This is an automated email from the ASF dual-hosted git repository.
pawan pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/trunk by this push: new efc016e Fixed: BigDecimal casting in Groovy (OFBIZ-11862) efc016e is described below commit efc016e5c933469d863650c7af307ac4810b8142 Author: Pawan Verma <[hidden email]> AuthorDate: Fri Jul 3 14:08:14 2020 +0530 Fixed: BigDecimal casting in Groovy (OFBIZ-11862) Sometimes use wrong type castings for BigDecimal: Used BigDecimal.ZERO and BigDecimal.ONE instead. --- .../groovyScripts/order/OrderReturnServices.groovy | 20 ++++++++++---------- .../inventory/InventoryIssueServices.groovy | 10 +++++----- .../shipment/ShipmentReceiptServices.groovy | 8 ++++---- .../groovyScripts/shipment/ShipmentServices.groovy | 22 +++++++++++----------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/applications/order/groovyScripts/order/OrderReturnServices.groovy b/applications/order/groovyScripts/order/OrderReturnServices.groovy index 85fb741..8ff7a00 100644 --- a/applications/order/groovyScripts/order/OrderReturnServices.groovy +++ b/applications/order/groovyScripts/order/OrderReturnServices.groovy @@ -129,7 +129,7 @@ def updateReturnHeader() { List returnItems = from("ReturnItem").where(returnId: returnHeader.returnId).distinct().queryList() // this is used to make sure we don't return a negative amount - BigDecimal returnTotalAmount = 0 as BigDecimal + BigDecimal returnTotalAmount = BigDecimal.ZERO // check them all to make sure that the return total does not exceed order total. for (GenericValue returnItem : returnItems) { @@ -144,7 +144,7 @@ def updateReturnHeader() { // no adjustment needed: adjustment is passed in to calculate // the effect of an additional item on return total. Map serviceResult = run service:"getOrderAvailableReturnedTotal", with: [orderId: returnItem.orderId, - adjustment : 0 as BigDecimal] + adjustment : BigDecimal.ZERO] BigDecimal availableReturnTotal = serviceResult.availableReturnTotal BigDecimal returnTotal = serviceResult.returnTotal BigDecimal orderTotal = serviceResult.returnTotal @@ -205,13 +205,13 @@ def createReturnItem() { && ("RTN_CSREPLACE" == parameters.returnTypeId || "RTN_REPAIR_REPLACE" == parameters.returnTypeId)) { return informError("OrderReturnPaymentMethodNeededForThisTypeOfReturn") } - if (parameters.returnQuantity == (0 as BigDecimal)) { + if (parameters.returnQuantity == (BigDecimal.ZERO)) { return informError("OrderNoReturnQuantityAvailablePreviousReturnsMayExist") } // setup some default values for protection - BigDecimal returnableQuantity = 0 as BigDecimal - BigDecimal returnablePrice = 0 as BigDecimal + BigDecimal returnableQuantity = BigDecimal.ZERO + BigDecimal returnablePrice = BigDecimal.ZERO // if an orderItemSeqId is provided, then find the corresponding orderItem if (parameters.orderItemSeqId) { @@ -232,7 +232,7 @@ def createReturnItem() { returnableQuantity = serviceResult.returnableQuantity ?: returnableQuantity returnablePrice = serviceResult.returnablePrice ?: returnablePrice } - if (returnableQuantity > (0 as BigDecimal)) { + if (returnableQuantity > (BigDecimal.ZERO)) { // the user is only allowed to set a returnPrice if he has ORDERMGR_CREATE privilege, // otherwise only the returnablePrice calculated by service is used if (!security.hasEntityPermission("ORDERMGR", "_CREATE", parameters.userLogin)) { @@ -369,7 +369,7 @@ def updateReturnStatusFromReceipt() { Map totalsMap = [:] for (GenericValue receipt : shipmentReceipts) { if (!totalsMap[receipt?.returnItemSeqId]) { - totalsMap[receipt.returnItemSeqId] = 0 as BigDecimal + totalsMap[receipt.returnItemSeqId] = BigDecimal.ZERO } totalsMap[receipt.returnItemSeqId] += receipt.quantityAccepted + receipt.quantityRejected } @@ -520,7 +520,7 @@ def quickReturnFromOrder() { logInfo("Found unexpected orderAdjustment: ${newItemCtx.orderAdjustmentId}") newItemCtx.orderAdjustmentId = null } - if (newItemCtx.returnQuantity > (0 as BigDecimal)) { + if (newItemCtx.returnQuantity > (BigDecimal.ZERO)) { // otherwise, items which have been fully returned would still get passed in and then come back with an error run service:"createReturnItem", with: newItemCtx } else { @@ -551,7 +551,7 @@ def quickReturnFromOrder() { logInfo("OrderTotal [${orderTotal}] - ReturnTotal [${returnTotal}] = available Return Total [${}]") // create a manual balance adjustment based on the difference between order total and return total - if (availableReturnTotal != (0 as BigDecimal)) { + if (availableReturnTotal != (BigDecimal.ZERO)) { logWarning("Creating a balance adjustment of [" + availableReturnTotal + "] for return [" + returnId + "]") // create the balance adjustment return item @@ -958,7 +958,7 @@ def createReturnItemForRental() { createReturnCtx.returnTypeId = "RTN_RENTAL" createReturnCtx.returnItemTypeId = "RET_FDPROD_ITEM" createReturnCtx.expectedItemStatus = "INV_RETURNED" - createReturnCtx.returnPrice = 0 as BigDecimal + createReturnCtx.returnPrice = BigDecimal.ZERO List orderItems = from("OrderItemAndProduct") .where(orderId: orderHeader.orderId, diff --git a/applications/product/groovyScripts/product/inventory/InventoryIssueServices.groovy b/applications/product/groovyScripts/product/inventory/InventoryIssueServices.groovy index d443024..742f74a 100644 --- a/applications/product/groovyScripts/product/inventory/InventoryIssueServices.groovy +++ b/applications/product/groovyScripts/product/inventory/InventoryIssueServices.groovy @@ -116,7 +116,7 @@ def issueImmediatelyFulfilledOrderItem() { parameters.quantityNotIssued = orderItem.quantity // if quantityNotIssued is not 0, then pull it from the last non-serialized inventory item found, // in the quantityNotIssued field - if (parameters.quantityNotIssued != (0 as BigDecimal)) { + if (parameters.quantityNotIssued != (BigDecimal.ZERO)) { BigDecimal availableToPromiseDiff = - parameters.quantityNotIssued BigDecimal quantityOnHandDiff = - parameters.quantityNotIssued if (lastNonSerInventoryItem) { @@ -175,7 +175,7 @@ def issueImmediatelyFulfilledOrderItem() { def issueImmediateForInventoryItemInline(GenericValue inventoryItem) { GenericValue lastNonSerInventoryItem // only do something with this inventoryItem if there is more inventory to issue - if (parameters.quantityNotIssued > (0 as BigDecimal)) { + if (parameters.quantityNotIssued > (BigDecimal.ZERO)) { if ("SERIALIZED_INV_ITEM" == inventoryItem.inventoryItemTypeId) { if ("INV_AVAILABLE" == inventoryItem.statusId) { // change status on inventoryItem @@ -186,9 +186,9 @@ def issueImmediateForInventoryItemInline(GenericValue inventoryItem) { run service: "createItemIssuance", with: [orderId: parameters.orderId, orderItemSeqId: parameters.orderItemSeqId, inventoryItemId: inventoryItem.inventoryItemId, - quantity: 1 as BigDecimal] + quantity: BigDecimal.ONE] - parameters.quantityNotIssued -= 1 as BigDecimal + parameters.quantityNotIssued -= BigDecimal.ONE } } if (inventoryItem.inventoryItemTypeId == "NON_SERIAL_INV_ITEM") { @@ -196,7 +196,7 @@ def issueImmediateForInventoryItemInline(GenericValue inventoryItem) { // if not the code at the end of this method will handle it if ((!inventoryItem.statusId || inventoryItem.statusId == "INV_AVAILABLE") && inventoryItem.availableToPromiseTotal && - inventoryItem.availableToPromiseTotal > 0 as BigDecimal) { + inventoryItem.availableToPromiseTotal > BigDecimal.ZERO) { parameters.deductAmount = parameters.quantityNotIssued > inventoryItem.availableToPromiseTotal ? inventoryItem.availableToPromiseTotal : parameters.quantityNotIssued diff --git a/applications/product/groovyScripts/shipment/ShipmentReceiptServices.groovy b/applications/product/groovyScripts/shipment/ShipmentReceiptServices.groovy index 0f78946..b69e9cd 100644 --- a/applications/product/groovyScripts/shipment/ShipmentReceiptServices.groovy +++ b/applications/product/groovyScripts/shipment/ShipmentReceiptServices.groovy @@ -82,13 +82,13 @@ def receiveInventoryProduct () { Double loops = 1.0 if (parameters.inventoryItemTypeId == "SERIALIZED_INV_ITEM") { // if we are serialized and either a serialNumber or inventoyItemId is passed in and the quantityAccepted is greater than 1 then complain - if ((parameters.serialNumber || parameters.currentInventoryItemId) && (parameters.quantityAccepted > (1 as BigDecimal))) { + if ((parameters.serialNumber || parameters.currentInventoryItemId) && (parameters.quantityAccepted > (BigDecimal.ONE))) { Map errorLog = [parameters: parameters] return error(UtilProperties.getMessage("ProductUiLabels", "FacilityReceiveInventoryProduct", errorLog, parameters.locale)) // before getting going, see if there are any validation issues so far } loops = parameters.quantityAccepted - parameters.quantityAccepted = 1 as BigDecimal + parameters.quantityAccepted = BigDecimal.ONE } parameters.quantityOnHandDiff = parameters.quantityAccepted parameters.availableToPromiseDiff = parameters.quantityAccepted @@ -236,7 +236,7 @@ def quickReceiveReturn() { } if (!setNonSerial) { parameters.inventoryItemTypeId = "SERIALIZED_INV_ITEM" - returnItem.returnQuantity = 1 as BigDecimal + returnItem.returnQuantity = BigDecimal.ONE } receiveCtx = [inventoryItemTypeId: parameters.inventoryItemTypeId, statusId: returnItem.expectedItemStatus, @@ -248,7 +248,7 @@ def quickReceiveReturn() { shipmentId: shipmentId, // important: associate ShipmentReceipt with return shipment created comments: "Returned Item RA# ${returnItem.returnId}", datetimeReceived: nowTimestamp, - quantityRejected: 0 as BigDecimal + quantityRejected: BigDecimal.ZERO ] Map serviceResult = run service:"receiveInventoryProduct", with: receiveCtx result.successMessageList = serviceResult.successMessageList diff --git a/applications/product/groovyScripts/shipment/ShipmentServices.groovy b/applications/product/groovyScripts/shipment/ShipmentServices.groovy index 838ee19..5501374 100644 --- a/applications/product/groovyScripts/shipment/ShipmentServices.groovy +++ b/applications/product/groovyScripts/shipment/ShipmentServices.groovy @@ -506,7 +506,7 @@ def balanceItemIssuancesForShipment() { orderId: issuance.orderId, orderItemSeqId: issuance.orderItemSeqId) .queryList() - BigDecimal issuanceQuantity = 0 as BigDecimal + BigDecimal issuanceQuantity = BigDecimal.ZERO for (GenericValue receipt : receipts) { issuanceQuantity = issuanceQuantity + receipt.quantityAccepted + receipt.quantityRejected } @@ -545,7 +545,7 @@ def splitShipmentItemByQuantity() { .queryList() BigDecimal orderShipmentQuantityLeft = parameters.newItemQuantity for (GenericValue itemOrderShipment : itemOrderShipmentList) { - if (orderShipmentQuantityLeft > (0 as BigDecimal)) { + if (orderShipmentQuantityLeft > (BigDecimal.ZERO)) { if (itemOrderShipment.quantity > orderShipmentQuantityLeft) { // there is enough in this OrderShipment record, so just adjust it and move on Map updateOrderShipmentMap = itemOrderShipment.getAllFields() @@ -556,7 +556,7 @@ def splitShipmentItemByQuantity() { shipmentId: itemOrderShipment.shipmentId, shipmentItemSeqId: newShipmentItemSeqId, quantity: orderShipmentQuantityLeft] - orderShipmentQuantityLeft = 0 as BigDecimal + orderShipmentQuantityLeft = BigDecimal.ZERO } else { // not enough on this one, create a new one for the new item and delete this one run service: "deleteOrderShipment", with: itemOrderShipment.getAllFields() @@ -1336,7 +1336,7 @@ def removeOrderShipmentFromShipment() { GenericValue shipmentItem = from("ShipmentItem").where(parameters).queryOne() run service: "deleteOrderShipment", with: parameters shipmentItem.quantity = orderShipment.quantity - shipmentItem.quantity - if (shipmentItem.quantity > (0 as BigDecimal)) { + if (shipmentItem.quantity > (BigDecimal.ZERO)) { run service: "updateShipmentItem", with: shipmentItem.getAllFields() } else { run service: "deleteShipmentItem", with: parameters @@ -1353,7 +1353,7 @@ def removeOrderShipmentFromShipment() { def addOrderShipmentToShipment() { Map result = success() // if quantity is greater than 0 we add or update the ShipmentPlan - if (parameters.quantity > (0 as BigDecimal)) { + if (parameters.quantity > (BigDecimal.ZERO)) { // get orderHeader GenericValue orderHeader = from("OrderHeader").where(parameters).queryOne() // get orderItem @@ -1397,25 +1397,25 @@ def addOrderShipmentToShipment() { */ def getQuantityForShipment() { Map result = success() - BigDecimal plannedQuantity = 0 as BigDecimal - BigDecimal issuedQuantity = 0 as BigDecimal + BigDecimal plannedQuantity = BigDecimal.ZERO + BigDecimal issuedQuantity = BigDecimal.ZERO // get orderItem GenericValue orderItem = from("OrderItem").where(parameters).queryOne() Map orderShipmentLookup = [orderId: parameters.orderId, orderItemSeqId: parameters.orderItemSeqId] List existingOrderShipments = from("OrderShipment").where(orderShipmentLookup).queryList() for (GenericValue orderShipment : existingOrderShipments) { - plannedQuantity += orderShipment.quantity ?: 0 as BigDecimal + plannedQuantity += orderShipment.quantity ?: BigDecimal.ZERO } existingOrderShipments = from("ItemIssuance").where(orderShipmentLookup).queryList() for (GenericValue itemIssuance : existingOrderShipments) { - BigDecimal quantity = itemIssuance.quantity ?: 0 as BigDecimal - BigDecimal cancelQuantity = itemIssuance.cancelQuantity ?: 0 as BigDecimal + BigDecimal quantity = itemIssuance.quantity ?: BigDecimal.ZERO + BigDecimal cancelQuantity = itemIssuance.cancelQuantity ?: BigDecimal.ZERO issuedQuantity += quantity - cancelQuantity } BigDecimal totPlannedOrIssuedQuantity = issuedQuantity + plannedQuantity - BigDecimal orderCancelQuantity = orderItem.cancelQuantity ?: 0 as BigDecimal + BigDecimal orderCancelQuantity = orderItem.cancelQuantity ?: BigDecimal.ZERO result.remainingQuantity = orderCancelQuantity + totPlannedOrIssuedQuantity - orderItem.quantity return result |
Free forum by Nabble | Edit this page |