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

Last change on this file since 426 was 425, checked in by gav, 15 years ago

Handle InventoryItem reverse alternateItems.

File size: 2.5 KB
Line 
1class  InventoryItem {
2    InventoryGroup inventoryGroup
3    InventoryType inventoryType
4    UnitOfMeasure unitOfMeasure
5    InventoryLocation inventoryLocation
6    Period averageDeliveryPeriod
7    Picture picture
8    String name
9    String description = ""
10    String comment = ""
11    String manufacturersPartNumber
12    BigDecimal estimatedUnitPriceAmount
13    Currency estimatedUnitPriceCurrency
14    String suppliersPartNumber
15    Integer unitsInStock = 0
16    Integer reorderPoint
17    Integer recommendedReorderPoint
18    Integer averageDeliveryTime
19    boolean isActive = true
20    boolean isObsolete = false
21    boolean enableReorder = 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                                    manufacturers: Manufacturer,
31                                    suppliers: 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        enableReorder()
46        recommendedReorderPoint(nullable:true)
47        isActive()
48        isObsolete()
49        inventoryGroup()
50        inventoryType()
51        manufacturersPartNumber(blank:true, nullable:true)
52        suppliersPartNumber(blank:true, nullable:true)
53        averageDeliveryTime(nullable:true)
54        averageDeliveryPeriod(nullable:true)
55    }
56
57    String toString() {"${this.name}"}
58
59    def afterInsert = {
60        addReverseAlternateItems()
61    }
62
63    // Add reverse alternateItem references.
64    def addReverseAlternateItems() {
65        this.alternateItems.each() {
66            if( !it.alternateItems?.contains(this) )
67                it.addToAlternateItems(this)
68        }
69    }
70
71    /**
72   * Remove all reverse alternateItem references.
73    * Update: reverse alternateItem handling must be done in the
74    * service class since the before assignment alternateItems are required.
75    */
76    def removeReverseAlternateItems(alternateItems = this.alternateItems) {
77        alternateItems.each() {
78            it.removeFromAlternateItems(this)
79        }
80    }
81
82}
Note: See TracBrowser for help on using the repository browser.