Ignore:
Timestamp:
Jun 18, 2010, 3:58:43 PM (15 years ago)
Author:
gav
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/InventoryItemPurchase.groovy

    r441 r599  
    2222    static constraints = {
    2323        quantity(min:0)
    24         purchaseOrderNumber(blank:false, maxSize:50)
     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        })
    2540        invoiceNumber(maxSize:50)
    2641        orderValueAmount(max: new BigDecimal(1000000000000))
Note: See TracChangeset for help on using the changeset viewer.