Changeset 964 for trunk


Ignore:
Timestamp:
Jul 19, 2012, 1:35:38 PM (7 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.

Location:
trunk/grails-app
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/i18n/messages.properties

    r874 r964  
    323323inventoryItemPurchase.delete.failure.received.exists=Could not delete, items have been received.
    324324inventoryItemPurchase.delete.failure.payment.approved=Could not delete, payment has been approved.
     325inventoryItemPurchase.delete.failure.reverse.move=Could not delete, associated movement could not be reversed, insufficient items in stock perhaps?
    325326inventoryItemPurchase.operation.not.permitted.on.inactive.or.obsolete.item=This operation is not permitted on an inactive or obsolete inventory item.
    326327inventoryItemPurchase.costCodes.not.found=No cost codes found, a person needs to be assigned to a purchasing group that has cost codes.
  • trunk/grails-app/services/InventoryMovementService.groovy

    r631 r964  
    99        InventoryMovement.withTransaction { status ->
    1010            def result = [:]
     11            params =  params ?: [:]
    1112
    1213            def fail = { Map m ->
     
    2021            result.inventoryMovementInstance = InventoryMovement.lock(params.id)
    2122
    22              if(!result.inventoryMovementInstance)
     23            if(!result.inventoryMovementInstance)
    2324                fail(code:"default.not.found")
    2425
  • 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.