source: trunk/grails-app/domain/InventoryItem.groovy @ 718

Last change on this file since 718 was 718, checked in by gav, 13 years ago

Domain change: remove InventoryItem.averageDeliveryPeriod and averageDeliveryTime.

File size: 2.8 KB
Line 
1class  InventoryItem {
2    InventoryGroup inventoryGroup
3    InventoryType inventoryType
4    UnitOfMeasure unitOfMeasure
5    InventoryLocation inventoryLocation
6    Picture picture
7    Supplier preferredSupplier
8    Manufacturer preferredManufacturer
9    String name
10    String description = ""
11    String comment = ""
12    String manufacturersPartNumber
13    BigDecimal estimatedUnitPriceAmount
14    Currency estimatedUnitPriceCurrency
15    String suppliersPartNumber
16    Integer unitsInStock = 0
17    Integer reorderPoint
18    Integer reorderQuantity
19    boolean isActive = true
20    boolean isObsolete = false
21    boolean enableReorderListing = true
22
23    static mapping = {
24        picture cascade: 'all-delete-orphan', lazy: true, inverse: true
25    }
26
27    static hasMany = [alternateItems: InventoryItem,
28                                    spareFor: Asset,
29                                    inventoryMovements: InventoryMovement,
30                                    alternateManufacturers: Manufacturer,
31                                    alternateSuppliers: Supplier]
32
33//     static belongsTo = []
34
35    static constraints = {
36        picture(nullable:true)
37        name(unique:true, blank:false, maxSize:50)
38        description(maxSize:255)
39        comment(maxSize:500)
40        unitsInStock(min:0)
41        unitOfMeasure()
42        estimatedUnitPriceAmount(nullable:true, max: new BigDecimal(1000000000000))
43        estimatedUnitPriceCurrency(nullable:true)
44        reorderPoint()
45        enableReorderListing()
46        reorderQuantity(nullable:true)
47        isActive()
48        isObsolete()
49        inventoryGroup()
50        inventoryType()
51        manufacturersPartNumber(blank:true, nullable:true)
52        suppliersPartNumber(blank:true, nullable:true)
53        preferredSupplier(nullable:true)
54        preferredManufacturer(nullable:true)
55    }
56
57    String toString() {"${this.name}"}
58
59    static searchable = {
60        only = ['name', 'description', 'comment', 'isActive', 'isObsolete', 'inventoryLocation', 'inventoryGroup', 'spareFor']
61        //name boost: 1.5
62        inventoryLocation component: true
63        inventoryGroup component: true
64        spareFor component: true
65    }
66
67    def afterInsert = {
68        addReverseAlternateItems()
69    }
70
71    /**
72    * Add reverse alternateItem references.
73    */
74    def addReverseAlternateItems() {
75        this.alternateItems.each() {
76            if( !it.alternateItems?.contains(this) )
77                it.addToAlternateItems(this)
78        }
79    }
80
81    /**
82   * Remove all reverse alternateItem references.
83    * On update: reverse alternateItem handling must be done in the
84    * service class since the before assignment alternateItems are required.
85    */
86    def removeReverseAlternateItems(alternateItems = this.alternateItems) {
87        alternateItems.each() {
88            it.removeFromAlternateItems(this)
89        }
90    }
91
92}
Note: See TracBrowser for help on using the repository browser.