Ignore:
Timestamp:
Jul 19, 2012, 1:35:38 PM (12 years ago)
Author:
gav
Message:

Fix for ticket #105 - InventoryItemPurchase?'s can't be deleted when order quantity = 0 and allows the order to be deleted.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/InventoryPurchaseService.groovy

    r717 r964  
    194194                }
    195195
    196                 def movementResult = inventoryMovementService.reverseMove(inventoryMovements[0])
    197                 if(movementResult.error)
    198                     return fail(code:"inventoryMovement.quantity.insufficientItemsInStock")
     196                if(inventoryMovements[0]) {
     197                    def movementResult = inventoryMovementService.reverseMove(inventoryMovements[0])
     198                    if(movementResult.error)
     199                        return fail(code:"inventoryItemPurchase.delete.failure.reverse.move")
     200                }
    199201
    200202                InventoryItemPurchase.withCriteria {
     
    213215            // Deletion of received already requires payment approved to be deleted.
    214216            if(purchaseTypeId == 1) {
     217
    215218                def calcQuantities = calcQuantities(result.inventoryItemPurchaseInstance)
    216219                if(calcQuantities.totalReceived > 0)
     220                    return fail(code:"inventoryItemPurchase.delete.failure.received.exists")
     221
     222                // Cover the case of 0 ordered and received.
     223                // Only possible to have Received Complete (3L) in this case and not B/order (2L).
     224                def receivedExists = InventoryItemPurchase.withCriteria {
     225                    eq("inventoryItem", result.inventoryItemPurchaseInstance.inventoryItem)
     226                    eq("purchaseOrderNumber", result.inventoryItemPurchaseInstance.purchaseOrderNumber)
     227                    inventoryItemPurchaseType {
     228                            eq("id", 3L) // Received Complete.
     229                    }
     230                }
     231
     232                if(receivedExists)
    217233                    return fail(code:"inventoryItemPurchase.delete.failure.received.exists")
    218234            }
Note: See TracChangeset for help on using the changeset viewer.