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