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

Last change on this file since 562 was 562, checked in by gav, 14 years ago

Install searchable plugin, configure and start inventory search.

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