source: trunk/grails-app/domain/InventoryItemPurchase.groovy @ 600

Last change on this file since 600 was 599, checked in by gav, 14 years ago

Implement InventoryItemPurchase custom constraint as per ticket #74, unique purchaseOrderNumber for an inventoryItem order.

File size: 1.5 KB
Line 
1class InventoryItemPurchase {
2
3    Person enteredBy
4    InventoryItem inventoryItem
5    CostCode costCode
6    InventoryItemPurchaseType inventoryItemPurchaseType
7
8    Date dateEntered = new Date()
9    Integer quantity
10    String purchaseOrderNumber = ''
11    BigDecimal orderValueAmount
12    Currency orderValueCurrency
13    String invoiceNumber = ''
14
15    Boolean receivedComplete = false
16    Boolean invoicePaymentApproved = false
17
18//     hasMany = []
19
20    static belongsTo = [InventoryItem]
21
22    static constraints = {
23        quantity(min:0)
24        purchaseOrderNumber(blank:false, maxSize:50, validator: {val, obj ->
25            // For orders the purchaseOrderNumber must be unique for an inventoryItem.
26            if(obj.inventoryItemPurchaseType.id == 1L) {
27                def list = InventoryItemPurchase.withCriteria {
28                    eq('inventoryItem', obj.inventoryItem)
29                    eq('purchaseOrderNumber', obj.purchaseOrderNumber)
30                    eq('inventoryItemPurchaseType', obj.inventoryItemPurchaseType)
31                    if(obj.id)
32                        notEqual('id', obj.id)
33                }
34                if(list.size() > 0)
35                    return 'not.unique.for.inventory.item.order'
36            }
37            // Success.
38            return true
39        })
40        invoiceNumber(maxSize:50)
41        orderValueAmount(max: new BigDecimal(1000000000000))
42        orderValueCurrency()
43    }
44
45    String toString() {
46        "${this.quantity} x ${inventoryItem} - ${this.inventoryItemPurchaseType} "
47    }
48
49}
Note: See TracBrowser for help on using the repository browser.