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