You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2015/01/11 19:11:46 UTC

svn commit: r1650940 - in /ofbiz/branches/release13.07: ./ applications/order/src/org/ofbiz/order/order/ applications/product/script/org/ofbiz/product/inventory/ applications/product/script/org/ofbiz/shipment/issuance/

Author: jleroux
Date: Sun Jan 11 18:11:46 2015
New Revision: 1650940

URL: http://svn.apache.org/r1650940
Log:
"Applied fix from trunk for revision: 1650938  " 
------------------------------------------------------------------------
r1650938 | jleroux | 2015-01-11 19:10:03 +0100 (dim. 11 janv. 2015) | 9 lignes

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/branches/release13.07/   (props changed)
    ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
    ofbiz/branches/release13.07/applications/product/script/org/ofbiz/product/inventory/InventoryIssueServices.xml
    ofbiz/branches/release13.07/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml
    ofbiz/branches/release13.07/applications/product/script/org/ofbiz/shipment/issuance/IssuanceServices.xml

Propchange: ofbiz/branches/release13.07/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Jan 11 18:11:46 2015
@@ -5,4 +5,4 @@
 /ofbiz/branches/jquery:952958-1044489
 /ofbiz/branches/multitenant20100310:921280-927264
 /ofbiz/branches/release12.04:1557118
-/ofbiz/trunk:1506269,1506499,1506504,1506828,1509164,1510042,1511279,1512376,1512573,1516094,1517629,1517702,1517780,1517947,1518336,1518950,1519245,1519999,1520319,1520321,1520326,1524361,1524676,1524704,1524769,1524835,1524950,1525523,1526276,1526387,1526463,1527212,1527254,1527609,1527626,1527810,1528144,1528146,1528149,1528298,1529412,1529418,1529588,1530273,1530634,1530876,1530972,1530976,1531848,1532342,1532366,1533542,1533839,1535961,1536170,1536656,1537023,1537086,1537179,1537996,1538096,1539147,1539156,1539781,1542264,1542388,1542442,1543744,1543766,1543781,1543994,1544444,1547548,1548143,1549015,1550255,1550258,1550515,1551585,1551744,1552149,1552290,1552500,1552901,1552908,1554064,1554242,1554265,1554290,1554373,1554536,1554681,1554685,1554706,1554764,1554787,1555142,1557409-1557410,1557427,1557440,1557443,1557447,1557456-1557457,1557462,1557593,1558145,1558241,1558373,1558774,1559814,1560048,1560056,1560176,1560203,1560205,1560699,1561286,1561290,1561305,1561311,1561327,
 1561467,1562767,1563238,1563683,1563958,1564111,1564113,1564463,1564473,1564493,1566096,1566273,1569078,1569743,1570611,1570622,1570639-1570640,1571207,1571219,1571247,1573161,1573498,1573639,1574019,1574201,1574404,1575508,1576259,1576331,1576378,1576506,1576511,1576757,1576839,1577268,1577744,1579155,1579161,1579277,1579309,1580455,1580850,1581386,1581972,1581997,1582762,1583040,1583427-1583428,1583551,1583674,1583681,1583689,1583696,1584873,1585033,1585574,1585958-1585959,1586987,1587841,1587843,1588733,1589589,1589602,1589606,1589612,1589625,1589669,1592530,1592588,1592745,1592977,1593902,1593908,1593952,1597239,1597464,1598113,1598327,1598475,1598544,1598913,1603439,1603732,1603739,1604357,1604363,1604522,1604554,1605029,1605269,1605348,1605354,1605707,1607457,1608355,1608495,1608526,1608698,1609047,1609065,1609076,1609087,1609149,1609155,1609167,1609184,1609389,1609394,1609398,1609406,1609418,1609885,1609889,1610355,1610420,1610425,1610685,1610918,1610925,1611321,1612190,16122
 02,1613121,1614019,1614025,1614280,1614355,1614366,1614556,1615296-1615297,1616272,1616684,1616940,1617229,1617473,1617480,1617936,1617938,1618395,1618397,1618570,1618831,1619087,1619098,1619300,1621335,1621363,1621413,1621436,1621438-1621439,1621442,1621599,1621683,1622050,1622170,1622672,1623370,1624538,1624767,1624809,1624817,1626797,1627230,1627763,1628096,1628130,1628937,1628940,1629382,1629391,1629426,1631203,1631299-1631300,1632764,1632793,1633100,1633188,1633550,1636864,1637883,1639606,1639835,1639840-1639841,1639846,1639863,1639887,1640288,1640299,1640515,1640717,1641066,1641131,1641165,1641548,1641804,1642423,1643341,1644904,1645950,1646204,1646935,1646977,1646984,1647266,1647338,1647559,1647606,1648668,1650240,1650583,1650642,1650678,1650882
+/ofbiz/trunk:1506269,1506499,1506504,1506828,1509164,1510042,1511279,1512376,1512573,1516094,1517629,1517702,1517780,1517947,1518336,1518950,1519245,1519999,1520319,1520321,1520326,1524361,1524676,1524704,1524769,1524835,1524950,1525523,1526276,1526387,1526463,1527212,1527254,1527609,1527626,1527810,1528144,1528146,1528149,1528298,1529412,1529418,1529588,1530273,1530634,1530876,1530972,1530976,1531848,1532342,1532366,1533542,1533839,1535961,1536170,1536656,1537023,1537086,1537179,1537996,1538096,1539147,1539156,1539781,1542264,1542388,1542442,1543744,1543766,1543781,1543994,1544444,1547548,1548143,1549015,1550255,1550258,1550515,1551585,1551744,1552149,1552290,1552500,1552901,1552908,1554064,1554242,1554265,1554290,1554373,1554536,1554681,1554685,1554706,1554764,1554787,1555142,1557409-1557410,1557427,1557440,1557443,1557447,1557456-1557457,1557462,1557593,1558145,1558241,1558373,1558774,1559814,1560048,1560056,1560176,1560203,1560205,1560699,1561286,1561290,1561305,1561311,1561327,
 1561467,1562767,1563238,1563683,1563958,1564111,1564113,1564463,1564473,1564493,1566096,1566273,1569078,1569743,1570611,1570622,1570639-1570640,1571207,1571219,1571247,1573161,1573498,1573639,1574019,1574201,1574404,1575508,1576259,1576331,1576378,1576506,1576511,1576757,1576839,1577268,1577744,1579155,1579161,1579277,1579309,1580455,1580850,1581386,1581972,1581997,1582762,1583040,1583427-1583428,1583551,1583674,1583681,1583689,1583696,1584873,1585033,1585574,1585958-1585959,1586987,1587841,1587843,1588733,1589589,1589602,1589606,1589612,1589625,1589669,1592530,1592588,1592745,1592977,1593902,1593908,1593952,1597239,1597464,1598113,1598327,1598475,1598544,1598913,1603439,1603732,1603739,1604357,1604363,1604522,1604554,1605029,1605269,1605348,1605354,1605707,1607457,1608355,1608495,1608526,1608698,1609047,1609065,1609076,1609087,1609149,1609155,1609167,1609184,1609389,1609394,1609398,1609406,1609418,1609885,1609889,1610355,1610420,1610425,1610685,1610918,1610925,1611321,1612190,16122
 02,1613121,1614019,1614025,1614280,1614355,1614366,1614556,1615296-1615297,1616272,1616684,1616940,1617229,1617473,1617480,1617936,1617938,1618395,1618397,1618570,1618831,1619087,1619098,1619300,1621335,1621363,1621413,1621436,1621438-1621439,1621442,1621599,1621683,1622050,1622170,1622672,1623370,1624538,1624767,1624809,1624817,1626797,1627230,1627763,1628096,1628130,1628937,1628940,1629382,1629391,1629426,1631203,1631299-1631300,1632764,1632793,1633100,1633188,1633550,1636864,1637883,1639606,1639835,1639840-1639841,1639846,1639863,1639887,1640288,1640299,1640515,1640717,1641066,1641131,1641165,1641548,1641804,1642423,1643341,1644904,1645950,1646204,1646935,1646977,1646984,1647266,1647338,1647559,1647606,1648668,1650240,1650583,1650642,1650678,1650882,1650938

Modified: ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java?rev=1650940&r1=1650939&r2=1650940&view=diff
==============================================================================
--- ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java (original)
+++ ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java Sun Jan 11 18:11:46 2015
@@ -2197,7 +2197,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/branches/release13.07/applications/product/script/org/ofbiz/product/inventory/InventoryIssueServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/product/script/org/ofbiz/product/inventory/InventoryIssueServices.xml?rev=1650940&r1=1650939&r2=1650940&view=diff
==============================================================================
--- ofbiz/branches/release13.07/applications/product/script/org/ofbiz/product/inventory/InventoryIssueServices.xml (original)
+++ ofbiz/branches/release13.07/applications/product/script/org/ofbiz/product/inventory/InventoryIssueServices.xml Sun Jan 11 18:11:46 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/branches/release13.07/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml?rev=1650940&r1=1650939&r2=1650940&view=diff
==============================================================================
--- ofbiz/branches/release13.07/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml (original)
+++ ofbiz/branches/release13.07/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml Sun Jan 11 18:11:46 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/branches/release13.07/applications/product/script/org/ofbiz/shipment/issuance/IssuanceServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/product/script/org/ofbiz/shipment/issuance/IssuanceServices.xml?rev=1650940&r1=1650939&r2=1650940&view=diff
==============================================================================
--- ofbiz/branches/release13.07/applications/product/script/org/ofbiz/shipment/issuance/IssuanceServices.xml (original)
+++ ofbiz/branches/release13.07/applications/product/script/org/ofbiz/shipment/issuance/IssuanceServices.xml Sun Jan 11 18:11:46 2015
@@ -265,7 +265,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"/>
@@ -496,10 +496,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"/>
@@ -518,10 +518,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"/>
@@ -672,10 +672,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"/>