[116] | 1 | class InventoryItem { |
---|
| 2 | InventoryGroup inventoryGroup |
---|
| 3 | InventoryType inventoryType |
---|
| 4 | UnitOfMeasure unitOfMeasure |
---|
[175] | 5 | InventoryLocation inventoryLocation |
---|
| 6 | Period averageDeliveryPeriod |
---|
[182] | 7 | Picture picture |
---|
[116] | 8 | String name |
---|
| 9 | String description = "" |
---|
[422] | 10 | String comment = "" |
---|
[116] | 11 | String manufacturersPartNumber |
---|
[405] | 12 | BigDecimal estimatedUnitPriceAmount |
---|
| 13 | Currency estimatedUnitPriceCurrency |
---|
[116] | 14 | String suppliersPartNumber |
---|
[175] | 15 | Integer unitsInStock = 0 |
---|
[116] | 16 | Integer reorderPoint |
---|
| 17 | Integer recommendedReorderPoint |
---|
| 18 | Integer averageDeliveryTime |
---|
| 19 | boolean isActive = true |
---|
| 20 | boolean isObsolete = false |
---|
| 21 | boolean enableReorder = true |
---|
| 22 | |
---|
[182] | 23 | static mapping = { |
---|
| 24 | picture cascade: 'all-delete-orphan', lazy: true, inverse: true |
---|
| 25 | } |
---|
| 26 | |
---|
[116] | 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 = { |
---|
[182] | 36 | picture(nullable:true) |
---|
[175] | 37 | name(unique:true, blank:false, maxSize:50) |
---|
[422] | 38 | description(maxSize:255) |
---|
| 39 | comment(maxSize:500) |
---|
[175] | 40 | unitsInStock(min:0) |
---|
| 41 | unitOfMeasure() |
---|
[416] | 42 | estimatedUnitPriceAmount(nullable:true, max: new BigDecimal(1000000000000)) |
---|
[405] | 43 | estimatedUnitPriceCurrency(nullable:true) |
---|
[116] | 44 | reorderPoint() |
---|
| 45 | enableReorder() |
---|
[175] | 46 | recommendedReorderPoint(nullable:true) |
---|
[116] | 47 | isActive() |
---|
| 48 | isObsolete() |
---|
| 49 | inventoryGroup() |
---|
| 50 | inventoryType() |
---|
| 51 | manufacturersPartNumber(blank:true, nullable:true) |
---|
| 52 | suppliersPartNumber(blank:true, nullable:true) |
---|
[146] | 53 | averageDeliveryTime(nullable:true) |
---|
[175] | 54 | averageDeliveryPeriod(nullable:true) |
---|
[116] | 55 | } |
---|
| 56 | |
---|
| 57 | String toString() {"${this.name}"} |
---|
[425] | 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 | |
---|
[116] | 82 | } |
---|