1 | class InventoryItem { |
---|
2 | InventoryGroup inventoryGroup |
---|
3 | InventoryType inventoryType |
---|
4 | UnitOfMeasure unitOfMeasure |
---|
5 | InventoryLocation inventoryLocation |
---|
6 | Picture picture |
---|
7 | Supplier preferredSupplier |
---|
8 | String name |
---|
9 | String description = "" |
---|
10 | String comment = "" |
---|
11 | BigDecimal estimatedUnitPriceAmount |
---|
12 | Currency estimatedUnitPriceCurrency |
---|
13 | String suppliersPartNumber |
---|
14 | Integer unitsInStock = 0 |
---|
15 | Integer reorderPoint |
---|
16 | Integer reorderQuantity |
---|
17 | boolean isActive = true |
---|
18 | boolean isObsolete = false |
---|
19 | boolean enableReorderListing = true |
---|
20 | |
---|
21 | static mapping = { |
---|
22 | picture cascade: 'all-delete-orphan', lazy: true, inverse: true |
---|
23 | } |
---|
24 | |
---|
25 | static hasMany = [alternateItems: InventoryItem, |
---|
26 | spareFor: Asset, |
---|
27 | inventoryMovements: InventoryMovement, |
---|
28 | alternateSuppliers: Supplier] |
---|
29 | |
---|
30 | // static belongsTo = [] |
---|
31 | |
---|
32 | static constraints = { |
---|
33 | picture(nullable:true) |
---|
34 | name(unique:true, blank:false, maxSize:50) |
---|
35 | description(maxSize:255) |
---|
36 | comment(maxSize:500) |
---|
37 | unitsInStock(min:0) |
---|
38 | unitOfMeasure() |
---|
39 | estimatedUnitPriceAmount(nullable:true, max: new BigDecimal(1000000000000)) |
---|
40 | estimatedUnitPriceCurrency(nullable:true) |
---|
41 | reorderPoint() |
---|
42 | enableReorderListing() |
---|
43 | reorderQuantity(nullable:true) |
---|
44 | isActive() |
---|
45 | isObsolete() |
---|
46 | inventoryGroup() |
---|
47 | inventoryType() |
---|
48 | suppliersPartNumber(blank:true, nullable:true) |
---|
49 | preferredSupplier(nullable:true) |
---|
50 | } |
---|
51 | |
---|
52 | String toString() {"${this.name}"} |
---|
53 | |
---|
54 | static searchable = { |
---|
55 | only = ['name', 'description', 'comment', 'isActive', 'isObsolete', 'inventoryLocation', 'inventoryGroup', 'spareFor'] |
---|
56 | //name boost: 1.5 |
---|
57 | inventoryLocation component: true |
---|
58 | inventoryGroup component: true |
---|
59 | spareFor component: true |
---|
60 | } |
---|
61 | |
---|
62 | def afterInsert = { |
---|
63 | addReverseAlternateItems() |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * Add reverse alternateItem references. |
---|
68 | */ |
---|
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. |
---|
78 | * On update: reverse alternateItem handling must be done in the |
---|
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 | |
---|
87 | } |
---|