[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 |
---|
| 8 | Manufacturer preferredManufacturer |
---|
[116] | 9 | String name |
---|
| 10 | String description = "" |
---|
[422] | 11 | String comment = "" |
---|
[116] | 12 | String manufacturersPartNumber |
---|
[405] | 13 | BigDecimal estimatedUnitPriceAmount |
---|
| 14 | Currency estimatedUnitPriceCurrency |
---|
[116] | 15 | String suppliersPartNumber |
---|
[175] | 16 | Integer unitsInStock = 0 |
---|
[116] | 17 | Integer reorderPoint |
---|
[715] | 18 | Integer reorderQuantity |
---|
[116] | 19 | boolean isActive = true |
---|
| 20 | boolean isObsolete = false |
---|
[616] | 21 | boolean enableReorderListing = true |
---|
[116] | 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, |
---|
[435] | 30 | alternateManufacturers: Manufacturer, |
---|
| 31 | alternateSuppliers: Supplier] |
---|
[116] | 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() |
---|
[616] | 45 | enableReorderListing() |
---|
[715] | 46 | reorderQuantity(nullable:true) |
---|
[116] | 47 | isActive() |
---|
| 48 | isObsolete() |
---|
| 49 | inventoryGroup() |
---|
| 50 | inventoryType() |
---|
| 51 | manufacturersPartNumber(blank:true, nullable:true) |
---|
| 52 | suppliersPartNumber(blank:true, nullable:true) |
---|
[435] | 53 | preferredSupplier(nullable:true) |
---|
| 54 | preferredManufacturer(nullable:true) |
---|
[116] | 55 | } |
---|
| 56 | |
---|
| 57 | String toString() {"${this.name}"} |
---|
[425] | 58 | |
---|
[562] | 59 | static searchable = { |
---|
[566] | 60 | only = ['name', 'description', 'comment', 'isActive', 'isObsolete', 'inventoryLocation', 'inventoryGroup', 'spareFor'] |
---|
[562] | 61 | //name boost: 1.5 |
---|
| 62 | inventoryLocation component: true |
---|
[566] | 63 | inventoryGroup component: true |
---|
[562] | 64 | spareFor component: true |
---|
| 65 | } |
---|
| 66 | |
---|
[425] | 67 | def afterInsert = { |
---|
| 68 | addReverseAlternateItems() |
---|
| 69 | } |
---|
| 70 | |
---|
[484] | 71 | /** |
---|
| 72 | * Add reverse alternateItem references. |
---|
| 73 | */ |
---|
[425] | 74 | def addReverseAlternateItems() { |
---|
| 75 | this.alternateItems.each() { |
---|
| 76 | if( !it.alternateItems?.contains(this) ) |
---|
| 77 | it.addToAlternateItems(this) |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | /** |
---|
| 82 | * Remove all reverse alternateItem references. |
---|
[484] | 83 | * On update: reverse alternateItem handling must be done in the |
---|
[425] | 84 | * service class since the before assignment alternateItems are required. |
---|
| 85 | */ |
---|
| 86 | def removeReverseAlternateItems(alternateItems = this.alternateItems) { |
---|
| 87 | alternateItems.each() { |
---|
| 88 | it.removeFromAlternateItems(this) |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
[116] | 92 | } |
---|