Changeset 717 for trunk/grails-app


Ignore:
Timestamp:
Nov 24, 2010, 12:57:45 PM (14 years ago)
Author:
gav
Message:

Fix for ticket #91 - Purchasing - run order price update when invoice is updated.

Location:
trunk/grails-app
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/InventoryItemPurchaseDetailedController.groovy

    r633 r717  
    350350        }
    351351
     352        // Prevent lazy initialization error.
     353        result.inventoryItemPurchaseInstance.costCode.attach()
     354
    352355        render(view:'receive',
    353356                        model:['inventoryItemPurchaseInstance': result.inventoryItemPurchaseInstance,
     
    394397        }
    395398
     399        // Prevent lazy initialization error.
     400        result.inventoryItemPurchaseInstance.costCode.attach()
     401
    396402        render(view:'approveInvoicePayment',
    397403                    model:['inventoryItemPurchaseInstance': result.inventoryItemPurchaseInstance,
  • trunk/grails-app/services/InventoryPurchaseService.groovy

    r633 r717  
    99    /**
    1010    * Calulates the quantities for an inventoryItem and purchaseOrderNumber.
    11     * @param order An inventory puchase that was the source of the order.
     11    * @param order An inventory purchase that was the source of the order.
    1212    * @returns A result map containing the totalOrdered, totalReceived, totalRemaining, thisOrderRemaining,
    1313    *                 totalOrderedAmount, totalReceivedAmount, totalRemainingAmount, thisOrderRemainingAmount,
     
    265265            }
    266266
     267            def originalPaymentApprovedAmount = result.inventoryItemPurchaseInstance.orderValueAmount
     268
    267269            result.inventoryItemPurchaseInstance.properties = params
    268270            result.inventoryItemPurchaseInstance.purchaseOrderNumber = result.inventoryItemPurchaseInstance.purchaseOrderNumber.trim()
     271            result.inventoryItemPurchaseInstance.invoiceNumber = result.inventoryItemPurchaseInstance.invoiceNumber.trim()
    269272            result.inventoryItemPurchaseInstance.lastUpdatedBy = authService.currentUser
     273
     274            // Fetch to prevent lazy initialization error.
     275            result.inventoryItemPurchaseInstance.inventoryItem.unitOfMeasure
     276
     277            //  If processing an Invoice Approved.
     278            if(result.inventoryItemPurchaseInstance.inventoryItemPurchaseType.id == 4L) {
     279                if(!result.inventoryItemPurchaseInstance.invoiceNumber)
     280                    return fail(field:"invoiceNumber", code:"inventoryItemPurchase.invoiceNumber.required")
     281            }
    270282
    271283            if(result.inventoryItemPurchaseInstance.hasErrors() || !result.inventoryItemPurchaseInstance.save())
    272284                return fail(code:"default.update.failure")
     285
     286            //  If processing an Invoice Approved.
     287            if(result.inventoryItemPurchaseInstance.inventoryItemPurchaseType.id == 4L) {
     288
     289                def order = getOriginalOrder(result.inventoryItemPurchaseInstance)
     290                if(!order)
     291                    return fail(code:"default.not.found")
     292
     293                // Update orderValueAmount if receivedComplete.
     294                if(order.receivedComplete) {
     295
     296                    def calcQuantities = calcQuantities(order)
     297                    order.orderValueAmount = calcQuantities.totalPaymentApproved
     298
     299                    if(order.hasErrors() || !order.save())
     300                        return fail(code:"default.create.failure")
     301                }
     302
     303            }
    273304
    274305            // Success.
     
    281312        InventoryItemPurchase.withTransaction { status ->
    282313            def result = [:]
     314
    283315            def fail = { Map m ->
    284316                status.setRollbackOnly()
Note: See TracChangeset for help on using the changeset viewer.