Related to issue 36776: Code review improvements
authorAlvaro Ferraz <alvaro.ferraz@openbravo.com>
Tue, 05 Sep 2017 12:37:04 +0200
changeset 32617 f103322dedd4
parent 32616 ef2a84e698c4
child 32618 f9e08035b10d
Related to issue 36776: Code review improvements

Retrieve currency standard precision instead of price precision in selectFromPO, selectFromPOUpdate, selectFromPOUpdateSOTrx and selectPriceList methods.
Do not round price actual with price precision when calculating line net amount.
Remove unused priceprecision variable.
Use data variable to retrieve currency standard precision when creating invoice from order and dataAux variable when creating invoice from receipt/shipment.
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java	Mon Sep 04 12:44:00 2017 -0400
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java	Tue Sep 05 12:37:04 2017 +0200
@@ -1671,13 +1671,6 @@
               }
             }
 
-            final int pricePrecision;
-            if (StringUtils.equals(strType, "SHIPMENT")) {
-              pricePrecision = Integer.valueOf(dataAux[0].priceprecision).intValue();
-            } else {
-              pricePrecision = Integer.valueOf(data[i].priceprecision).intValue();
-            }
-
             if (!data[i].cOrderlineId.equals("")) {
               price = CreateFromInvoiceData.selectPrices(conn, this, data[i].cOrderlineId);
               if (price != null && price.length > 0) {
@@ -1715,11 +1708,12 @@
               }
               price = null;
             }
-            final int stdPrecision = StringUtils.isNotEmpty(data[i].currencystdprecision) ? Integer
-                .valueOf(data[i].currencystdprecision).intValue() : 2;
-            BigDecimal lineNetAmt = (new BigDecimal(priceActual).setScale(pricePrecision,
-                BigDecimal.ROUND_HALF_UP)).multiply(qty);
-            lineNetAmt = lineNetAmt.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
+
+            final int stdPrecision = Integer.valueOf(
+                StringUtils.equals(strType, "SHIPMENT") ? dataAux[0].curstdprecision
+                    : data[i].curstdprecision).intValue();
+            BigDecimal lineNetAmt = new BigDecimal(priceActual).multiply(qty).setScale(
+                stdPrecision, BigDecimal.ROUND_HALF_UP);
             BigDecimal grossAmt = BigDecimal.ZERO;
             if (StringUtils.equals(strIsTaxIncluded, "Y")) {
               grossAmt = new BigDecimal(priceGross).multiply(qty);
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql	Mon Sep 04 12:44:00 2017 -0400
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql	Tue Sep 05 12:37:04 2017 +0200
@@ -34,9 +34,9 @@
        WHERE  CI.C_INVOICE_ID=? AND CO.C_ORDERLINE_ID = l.c_orderline_id
        GROUP BY CI.C_orderline_id , CO.QtyORDERED),0) AS QTY, 
        l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?)) AS RELATION_NAME, 
-        l.C_OrderLine_ID,l.Line, l.ad_org_id, '' as STDPRECISION, '' AS currencyStdPrecision,
+        l.C_OrderLine_ID,l.Line, l.ad_org_id, '' as STDPRECISION,
         '' as M_InOutLine_ID, '' AS PriceActual, '' AS PriceList, '' AS PriceLimit, '' AS Description, '' as PriceStd,
-        '' AS QUANTITYORDER, l.M_Product_UOM_ID, '' AS M_ATTRIBUTESETINSTANCE_ID, '' AS M_Offer_ID, '' AS PricePrecision,
+        '' AS QUANTITYORDER, l.M_Product_UOM_ID, '' AS M_ATTRIBUTESETINSTANCE_ID, '' AS M_Offer_ID, '' AS curStdPrecision,
         l.taxbaseamt, l.CancelPriceAD, '' AS Rate, '' AS gross_unit_price, '' AS grosspricelist, '' AS grosspricestd,
         COALESCE(l.A_Asset_ID, o.A_Asset_ID) AS A_Asset_ID, COALESCE(l.C_Project_ID, o.C_Project_ID) AS C_Project_ID,
         COALESCE(l.C_Costcenter_ID, o.C_Costcenter_ID) AS C_Costcenter_ID,
@@ -276,7 +276,7 @@
       <![CDATA[
       SELECT (CASE WHEN B.M_InOutLine_ID IS NULL THEN A.QTY ELSE B.QTY END) AS ID, 
       A.C_UOM_ID,uom.UOMSymbol, A.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(A.m_product_id), to_char(?)) AS NAME, 
-      A.C_OrderLine_ID,A.Line, uom.stdprecision AS stdprecision, cur.priceprecision, cur.stdprecision as currencyStdPrecision,
+      A.C_OrderLine_ID, A.Line, uom.stdprecision AS stdprecision, cur.stdprecision AS curStdPrecision,
       B.M_InOutLine_ID, A.Description, (CASE WHEN B.M_InOutLine_ID IS NULL THEN A.quantityOrder ELSE B.quantityOrder END) AS quantityOrder, 
       (CASE WHEN B.M_InOutLine_ID IS NULL THEN A.M_Product_UOM_ID ELSE B.M_Product_UOM_ID END) AS M_Product_UOM_ID, A.M_ATTRIBUTESETINSTANCE_ID, A.ad_org_id,
       A.taxbaseamt, A.a_asset_id, A.c_project_id, A.c_costcenter_id, A.user1_id, A.user2_id, A.explode, 'Y' as isOrder,
@@ -327,7 +327,7 @@
       <![CDATA[
         SELECT (CASE WHEN il.M_INOUTLINE_ID IS NULL THEN (l.QtyOrdered-COALESCE(l.QTYINVOICED ,0)) ELSE il.MOVEMENTQTY END) AS ID, 
         l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?)) AS NAME, 
-        l.C_OrderLine_ID,l.Line, max(uom.stdprecision) AS stdprecision, cur.priceprecision, cur.stdprecision as currencyStdPrecision, il.M_InOutLine_ID as M_InOutLine_ID, l.Description,
+        l.C_OrderLine_ID, l.Line, max(uom.stdprecision) AS stdprecision, cur.stdprecision AS curStdPrecision, il.M_InOutLine_ID as M_InOutLine_ID, l.Description,
         (CASE WHEN il.M_INOUTLINE_ID IS NULL THEN l.quantityOrder*C_DIVIDE((l.QtyOrdered-COALESCE(l.QTYINVOICED ,0)),(l.QtyOrdered)) ELSE il.quantityOrder END) AS quantityOrder, 
         (CASE WHEN il.M_INOUTLINE_ID IS NULL THEN l.M_Product_UOM_ID ELSE il.M_Product_UOM_ID END) AS M_Product_UOM_ID, il.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id,
         l.taxbaseamt, COALESCE(l.A_Asset_ID, o.A_Asset_ID) as A_Asset_ID, COALESCE(l.C_Project_ID, o.C_Project_ID) as C_Project_ID,
@@ -343,7 +343,7 @@
         AND l.M_Product_ID=p.M_Product_ID 
         GROUP BY l.QtyOrdered,l.qtydelivered,l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, 
         l.QTYINVOICED, il.M_InOutLine_ID, il.MovementQty, l.Description, l.quantityOrder, il.quantityOrder, 
-        l.M_Product_UOM_ID, il.M_Product_UOM_ID, il.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id, cur.priceprecision, cur.stdprecision,
+        l.M_Product_UOM_ID, il.M_Product_UOM_ID, il.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id, cur.stdprecision,
         l.taxbaseamt, COALESCE(l.A_Asset_ID, o.A_Asset_ID), COALESCE(l.C_Project_ID, o.C_Project_ID), COALESCE(l.C_Costcenter_ID, o.C_Costcenter_ID),
         COALESCE(l.User1_ID, o.User1_ID), COALESCE(l.User2_ID, o.User2_ID), l.explode, o.C_DOCTYPE_ID, l.C_AUM, l.AUMQTY
         HAVING ( (l.explode='Y') OR ((l.QtyOrdered-COALESCE(l.QTYINVOICED ,0)) <> 0)) 
@@ -697,7 +697,7 @@
     <SqlMethodComment></SqlMethodComment>
     <Sql>
       <![CDATA[
-      SELECT plv.M_PriceList_Version_ID AS ID, cur.Priceprecision
+      SELECT plv.M_PriceList_Version_ID AS ID, cur.StdPrecision AS curStdPrecision
       FROM M_PRICELIST pl, M_PRICELIST_VERSION plv, C_CURRENCY cur
       WHERE pl.M_PriceList_ID = plv.M_PriceList_ID 
       AND pl.C_Currency_ID = cur.C_Currency_ID