Changeset 599 for trunk


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.

Location:
trunk/grails-app
Files:
2 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))
  • trunk/grails-app/i18n/messages.properties

    r592 r599  
    175175inventoryMovement.still.associated=Could not complete operation as inventory movements are still associated with this item.
    176176
     177inventoryItemPurchase.purchaseOrderNumber.not.unique.for.inventory.item.order=Purchase Order Number must be unique for this inventory item order.
    177178inventoryItemPurchase.invoiceNumber.required=An invoice number must be supplied to approve payment.
    178179inventoryItemPurchase.delete.failure.received.exists=Could not delete, items have been received.
Note: See TracChangeset for help on using the changeset viewer.