Author: jleroux
Date: Sun Jan 11 18:10:03 2015
New Revision: 1650938
URL: http://svn.apache.org/r1650938
Log:
AA patch from Bob Morley for "Errors attempting to use quantities with more
than 2 decimals of precision" https://issues.apache.org/jira/browse/OFBIZ-3666
We have a need to handle inventory items with quantities up to four decimal
places. The data model currently supports 6 decimals so I thought I would try
to complete a purchase order, sales order, and a return for an item that has
this many digits of precision. What I found was ...
- The order item was calculated properly (including the total for the line) but
the totals for the entire sales order were incorrect. This was because when
OrderReadHelper was getting the OrderItemQuantity as part of calculating the
subtotal it would round it to the order's configured scale (2). Since this is
being used as a calculation it should not be rounded -- the total itself should
be rounded.
- In a number of spots in issuance and reservation services values were
(sometimes) being rounded. For example, when an order item was created it
would create an InventoryItemDetail record that would reduce the ATP by the
precise quantity, however when the order was placed the QOH was reduced by the
rounded value. All of these issues were the result of the mini-lang calculate
element being used which by default uses a scale of 2 decimals (from the dtd).
The solution was when working with quantities pass in the precision scale (6)
to ensure we do not lose precision. Again, when order totals, taxes, things
like that are being done the configured scale should take over, but the
intermediate calculations should not be losing precision.
jleroux: Adrian suggested to rather introduce types for quantity and money.
This was almost 5 years ago. Because these types has not been introduced since
I decided to pragmatically fix this 5 years old bug!
Modified:
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryIssueServices.xml
ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml
ofbiz/trunk/applications/product/script/org/ofbiz/shipment/issuance/IssuanceServices.xml
Modified:
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java?rev=1650938&r1=1650937&r2=1650938&view=diff
==============================================================================
---
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
(original)
+++
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
Sun Jan 11 18:10:03 2015
@@ -2237,7 +2237,7 @@ public class OrderReadHelper {
if (cancelQty == null) cancelQty = ZERO;
if (orderQty == null) orderQty = ZERO;
- return orderQty.subtract(cancelQty).setScale(scale, rounding);
+ return orderQty.subtract(cancelQty);
}
public static BigDecimal getOrderItemShipGroupQuantity(GenericValue
shipGroupAssoc) {
Modified:
ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryIssueServices.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryIssueServices.xml?rev=1650938&r1=1650937&r2=1650938&view=diff
==============================================================================
---
ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryIssueServices.xml
(original)
+++
ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryIssueServices.xml
Sun Jan 11 18:10:03 2015
@@ -138,10 +138,10 @@ under the License.
<set field="createDetailMap.orderId"
from-field="parameters.orderId"/>
<set field="createDetailMap.orderItemSeqId"
from-field="parameters.orderItemSeqId"/>
<set field="createDetailMap.itemIssuanceId"
from-field="itemIssuanceId"/>
- <calculate field="createDetailMap.availableToPromiseDiff">
+ <calculate field="createDetailMap.availableToPromiseDiff"
decimal-scale="6">
<calcop field="parameters.quantityNotIssued"
operator="negative"/>
</calculate>
- <calculate field="createDetailMap.quantityOnHandDiff">
+ <calculate field="createDetailMap.quantityOnHandDiff"
decimal-scale="6">
<calcop field="parameters.quantityNotIssued"
operator="negative"/>
</calculate>
<call-service service-name="createInventoryItemDetail"
in-map-name="createDetailMap"/>
@@ -173,10 +173,10 @@ under the License.
<set field="createDetailMap.orderId"
from-field="parameters.orderId"/>
<set field="createDetailMap.orderItemSeqId"
from-field="parameters.orderItemSeqId"/>
<set field="createDetailMap.itemIssuanceId"
from-field="itemIssuanceId"/>
- <calculate field="createDetailMap.availableToPromiseDiff">
+ <calculate field="createDetailMap.availableToPromiseDiff"
decimal-scale="6">
<calcop field="parameters.quantityNotIssued"
operator="negative"/>
</calculate>
- <calculate field="createDetailMap.quantityOnHandDiff">
+ <calculate field="createDetailMap.quantityOnHandDiff"
decimal-scale="6">
<calcop field="parameters.quantityNotIssued"
operator="negative"/>
</calculate>
<call-service service-name="createInventoryItemDetail"
in-map-name="createDetailMap"/>
@@ -249,10 +249,10 @@ under the License.
<set field="createDetailMap.orderItemSeqId"
from-field="parameters.orderItemSeqId"/>
<set field="createDetailMap.itemIssuanceId"
from-field="itemIssuanceId"/>
<!-- update availableToPromiseDiff AND
quantityOnHandDiff since this is an issuance -->
- <calculate
field="createDetailMap.availableToPromiseDiff">
+ <calculate
field="createDetailMap.availableToPromiseDiff" decimal-scale="6">
<calcop field="parameters.deductAmount"
operator="negative"/>
</calculate>
- <calculate field="createDetailMap.quantityOnHandDiff">
+ <calculate field="createDetailMap.quantityOnHandDiff"
decimal-scale="6">
<calcop field="parameters.deductAmount"
operator="negative"/>
</calculate>
<call-service service-name="createInventoryItemDetail"
in-map-name="createDetailMap"/>
Modified:
ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml?rev=1650938&r1=1650937&r2=1650938&view=diff
==============================================================================
---
ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml
(original)
+++
ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml
Sun Jan 11 18:10:03 2015
@@ -172,7 +172,7 @@ under the License.
<set from-field="parameters.orderId"
field="createDetailMap.orderId"/>
<set from-field="parameters.orderItemSeqId"
field="createDetailMap.orderItemSeqId"/>
<set from-field="parameters.shipGroupSeqId"
field="createDetailMap.shipGroupSeqId"/>
- <calculate
field="createDetailMap.availableToPromiseDiff">
+ <calculate
field="createDetailMap.availableToPromiseDiff" decimal-scale="6">
<calcop field="parameters.quantityNotReserved"
operator="negative"/>
</calculate>
@@ -241,7 +241,7 @@ under the License.
<set from-field="parameters.orderId"
field="createDetailMap.orderId"/>
<set from-field="parameters.orderItemSeqId"
field="createDetailMap.orderItemSeqId"/>
<set from-field="parameters.shipGroupSeqId"
field="createDetailMap.shipGroupSeqId"/>
- <calculate
field="createDetailMap.availableToPromiseDiff">
+ <calculate
field="createDetailMap.availableToPromiseDiff" decimal-scale="6">
<calcop field="parameters.quantityNotReserved"
operator="negative"/>
</calculate>
<if-not-empty
field="parameters.reserveReasonEnumId"><set
from-field="parameters.reserveReasonEnumId"
field="createDetailMap.reasonEnumId"/></if-not-empty>
@@ -453,7 +453,7 @@ under the License.
<set from-field="inventoryItem.inventoryItemId"
field="createDetailMap.inventoryItemId"/>
<set from-field="parameters.orderId"
field="createDetailMap.orderId"/>
<set from-field="parameters.orderItemSeqId"
field="createDetailMap.orderItemSeqId"/>
- <calculate
field="createDetailMap.availableToPromiseDiff">
+ <calculate
field="createDetailMap.availableToPromiseDiff" decimal-scale="6">
<calcop field="parameters.deductAmount"
operator="negative"/>
</calculate>
<if-not-empty field="ebayReserveReasonEnumId"><set
from-field="parameters.reserveReasonEnumId"
field="createDetailMap.reasonEnumId"/></if-not-empty>
@@ -478,7 +478,7 @@ under the License.
<call-service
service-name="reserveOrderItemInventory" in-map-name="reserveOisgirMap"/>
<clear-field field="reserveOisgirMap"/>
</if-empty>
- <calculate field="parameters.quantityNotReserved">
+ <calculate field="parameters.quantityNotReserved"
decimal-scale="6">
<calcop operator="subtract"
field="parameters.quantityNotReserved">
<calcop operator="get"
field="parameters.deductAmount"/>
</calcop>
@@ -533,11 +533,11 @@ under the License.
</if-empty>
<create-value value-field="newOisgirEntity"/>
<else>
- <calculate field="checkOisgirEntity.quantity">
+ <calculate field="checkOisgirEntity.quantity" decimal-scale="6">
<calcop operator="add" field="checkOisgirEntity.quantity"/>
<calcop operator="add" field="parameters.quantity"/>
</calculate>
- <calculate field="checkOisgirEntity.quantityNotAvailable">
+ <calculate field="checkOisgirEntity.quantityNotAvailable"
decimal-scale="6">
<calcop operator="add"
field="checkOisgirEntity.quantityNotAvailable"/>
<calcop operator="add"
field="parameters.quantityNotAvailable"/>
</calculate>
@@ -611,7 +611,7 @@ under the License.
<set from-field="oisgir.inventoryItemId"
field="checkDiiMap.inventoryItemId"/>
<call-service service-name="checkDecomposeInventoryItem"
in-map-name="checkDiiMap"/>
<!-- update the toCancelAmount -->
- <calculate field="toCancelAmount">
+ <calculate field="toCancelAmount" decimal-scale="6">
<calcop operator="subtract" field="toCancelAmount">
<calcop operator="get"
field="cancelOisgirMap.cancelQuantity"/>
</calcop>
@@ -646,7 +646,7 @@ under the License.
<clear-field field="createDetailMap"/>
<if-compare-field field="cancelQuantity"
to-field="orderItemShipGrpInvRes.quantity" operator="less" type="BigDecimal">
- <calculate field="orderItemShipGrpInvRes.quantity">
+ <calculate field="orderItemShipGrpInvRes.quantity"
decimal-scale="6">
<calcop operator="subtract"
field="orderItemShipGrpInvRes.quantity">
<calcop operator="get" field="cancelQuantity"/>
</calcop>
Modified:
ofbiz/trunk/applications/product/script/org/ofbiz/shipment/issuance/IssuanceServices.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/script/org/ofbiz/shipment/issuance/IssuanceServices.xml?rev=1650938&r1=1650937&r2=1650938&view=diff
==============================================================================
---
ofbiz/trunk/applications/product/script/org/ofbiz/shipment/issuance/IssuanceServices.xml
(original)
+++
ofbiz/trunk/applications/product/script/org/ofbiz/shipment/issuance/IssuanceServices.xml
Sun Jan 11 18:10:03 2015
@@ -267,7 +267,7 @@ under the License.
<set from-field="shipmentItem.shipmentId"
field="createDetailMap.shipmentId"/>
<set from-field="shipmentItem.shipmentItemSeqId"
field="createDetailMap.shipmentItemSeqId"/>
<set from-field="itemIssuanceId"
field="createDetailMap.itemIssuanceId"/>
- <calculate field="createDetailMap.quantityOnHandDiff">
+ <calculate field="createDetailMap.quantityOnHandDiff"
decimal-scale="6">
<calcop field="parameters.quantity" operator="negative"/>
</calculate>
<call-service service-name="createInventoryItemDetail"
in-map-name="createDetailMap"/>
@@ -522,10 +522,10 @@ under the License.
<set from-field="fixedAssetMaint.fixedAssetId"
field="createDetailMap.fixedAssetId"/>
<set from-field="fixedAssetMaint.maintHistSeqId"
field="createDetailMap.maintHistSeqId"/>
<set from-field="itemIssuanceId"
field="createDetailMap.itemIssuanceId"/>
- <calculate field="createDetailMap.quantityOnHandDiff">
+ <calculate field="createDetailMap.quantityOnHandDiff"
decimal-scale="6">
<calcop field="parameters.quantity" operator="negative"/>
</calculate>
- <calculate field="createDetailMap.availableToPromiseDiff">
+ <calculate field="createDetailMap.availableToPromiseDiff"
decimal-scale="6">
<calcop field="parameters.quantity" operator="negative"/>
</calculate>
<call-service service-name="createInventoryItemDetail"
in-map-name="createDetailMap"/>
@@ -544,10 +544,10 @@ under the License.
<set from-field="itemIssuance.fixedAssetId"
field="createDetailMap.fixedAssetId"/>
<set from-field="itemIssuance.maintHistSeqId"
field="createDetailMap.maintHistSeqId"/>
<set from-field="itemIssuance.itemIssuanceId"
field="createDetailMap.itemIssuanceId"/>
- <calculate field="createDetailMap.quantityOnHandDiff">
+ <calculate field="createDetailMap.quantityOnHandDiff"
decimal-scale="6">
<calcop field="oldQuantity" operator="add"/>
</calculate>
- <calculate field="createDetailMap.availableToPromiseDiff">
+ <calculate field="createDetailMap.availableToPromiseDiff"
decimal-scale="6">
<calcop field="oldQuantity" operator="add"/>
</calculate>
<call-service service-name="createInventoryItemDetail"
in-map-name="createDetailMap"/>
@@ -698,10 +698,10 @@ under the License.
<set field="createDetailMap.itemIssuanceId"
from-field="itemIssuanceId"/>
<set field="createDetailMap.shipmentId" from-field="shipmentId"/>
<set field="createDetailMap.shipmentItemSeqId"
from-field="shipmentItemSeqId"/>
- <calculate field="createDetailMap.quantityOnHandDiff">
+ <calculate field="createDetailMap.quantityOnHandDiff"
decimal-scale="6">
<calcop field="parameters.quantity" operator="negative"/>
</calculate>
- <calculate field="createDetailMap.availableToPromiseDiff">
+ <calculate field="createDetailMap.availableToPromiseDiff"
decimal-scale="6">
<calcop field="parameters.quantity" operator="negative"/>
</calculate>
<call-service service-name="createInventoryItemDetail"
in-map-name="createDetailMap"/>