details: https://code.openbravo.com/erp/devel/pi/rev/ef2a84e698c4 changeset: 32616:ef2a84e698c4 user: Mark <markmm82 <at> gmail.com> date: Mon Sep 04 12:44:00 2017 -0400 summary: Fixes issue 36776: Amounts in invoice lines and taxes rounded to price precision instead of standard precision in Create Lines From process.
In CreateFrom class, the price precision was used for rounding amounts instead of standard precision and it was causing differences with totals when invoices were created from orders or shipments. Now all prices are rounded with the price precision of it currency and amounts with standard precision. details: https://code.openbravo.com/erp/devel/pi/rev/f103322dedd4 changeset: 32617:f103322dedd4 user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Tue Sep 05 12:37:04 2017 +0200 summary: 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. details: https://code.openbravo.com/erp/devel/pi/rev/f9e08035b10d changeset: 32618:f9e08035b10d user: Mark <markmm82 <at> gmail.com> date: Mon Sep 04 15:09:05 2017 -0400 summary: Fixes issue 36705: More than one pending payment plan detail for same invoice payment plan When the payment schedule details were generated it was comparing the invoiced amount of related order with the sum of lineNetAmt + taxAmt of it lines, as tax calculation can be done at document level, and this sum is done at line level it is possible that exists differences between this sum and totals already rounded in the invoice. Also was considered an order completely invoiced if it dosn't has lines with ordered quatities different than invoiced. When exists orders with lines with lineNetAmt = 0 it was taking it as completed invoiced and then the whole amount of the psd was included in the invoice and it generates a difference between the total of document and the sum of the lines that was created as a new payment schedule detail. To avoid this situation, only are considered order lines with lineNetAmt different than zero to use the whole amount of the psd or to re-calculate the correct amounts from Payment Schedule and Payment Schedule Details related to the order and invoices. details: https://code.openbravo.com/erp/devel/pi/rev/40185fb2080e changeset: 32619:40185fb2080e user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Tue Sep 05 13:38:02 2017 +0200 summary: Related to issue 36705: Code review improvements Apply same fix in purchase flow. diffstat: modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml | 2 + src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java | 32 ++++----- src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql | 12 +- 3 files changed, 23 insertions(+), 23 deletions(-) diffs (141 lines): diff -r 2873be0d1b66 -r 40185fb2080e modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml --- a/modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml Mon Sep 04 14:03:39 2017 +0530 +++ b/modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml Tue Sep 05 13:38:02 2017 +0200 @@ -392,6 +392,7 @@ SELECT COALESCE(COUNT(*),0) INTO v_Count FROM c_orderline WHERE qtyordered <> (qtyinvoiced*v_MultiplierARC) + AND linenetamt <> 0 AND c_order_id = order_schdet.order_id; ELSE SELECT count(*) INTO v_count @@ -401,6 +402,7 @@ LEFT JOIN m_matchpo mpo ON ol.c_orderline_id = mpo.c_orderline_id AND mpo.c_invoiceline_id IS NOT NULL WHERE ol.c_order_id = order_schdet.order_id + AND ol.linenetamt <> 0 GROUP BY ol.c_orderline_id, ol.qtyordered) a WHERE a.qtyordered != (a.matchedqty*v_MultiplierARC); END IF; diff -r 2873be0d1b66 -r 40185fb2080e src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java --- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java Mon Sep 04 14:03:39 2017 +0530 +++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java Tue Sep 05 13:38:02 2017 +0200 @@ -1671,12 +1671,6 @@ } } - final int curPrecision; - if (strType.equals("SHIPMENT")) { - curPrecision = Integer.valueOf(dataAux[0].priceprecision).intValue(); - } else { - curPrecision = 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) { @@ -1714,20 +1708,24 @@ } price = null; } - BigDecimal lineNetAmt = (new BigDecimal(priceActual)).multiply(qty); - lineNetAmt = lineNetAmt.setScale(curPrecision, 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 ("Y".equals(strIsTaxIncluded)) { + if (StringUtils.equals(strIsTaxIncluded, "Y")) { grossAmt = new BigDecimal(priceGross).multiply(qty); - grossAmt = grossAmt.setScale(curPrecision, BigDecimal.ROUND_HALF_UP); + grossAmt = grossAmt.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP); } - if (!strPO.equals("")) { + if (StringUtils.isNotEmpty(strPO)) { String strInvoiceprepaymentamt = CreateFromInvoiceData.selectInvoicePrepaymentAmt( this, strKey); - BigDecimal invoiceprepaymentamt = (strInvoiceprepaymentamt.equals("") ? BigDecimal.ZERO + BigDecimal invoiceprepaymentamt = (StringUtils.isEmpty(strInvoiceprepaymentamt) ? BigDecimal.ZERO : new BigDecimal(strInvoiceprepaymentamt)); String strprepaymentamt = CreateFromInvoiceData.selectPrepaymentAmt(this, strPO); - BigDecimal prepaymentamt = (strprepaymentamt.equals("") ? BigDecimal.ZERO + BigDecimal prepaymentamt = (StringUtils.isEmpty(strprepaymentamt) ? BigDecimal.ZERO : new BigDecimal(strprepaymentamt)); BigDecimal totalprepayment = invoiceprepaymentamt.add(prepaymentamt); @@ -1735,10 +1733,10 @@ strKey); } String strTaxRate = CreateFromInvoiceData.selectTaxRate(this, C_Tax_ID); - BigDecimal taxRate = (strTaxRate.equals("") ? new BigDecimal(1) : new BigDecimal( - strTaxRate)); + BigDecimal taxRate = (StringUtils.isEmpty(strTaxRate) ? BigDecimal.ONE + : new BigDecimal(strTaxRate)); BigDecimal taxAmt = ((lineNetAmt.multiply(taxRate)).divide(new BigDecimal("100"), 12, - BigDecimal.ROUND_HALF_EVEN)).setScale(curPrecision, BigDecimal.ROUND_HALF_UP); + BigDecimal.ROUND_HALF_EVEN)).setScale(stdPrecision, BigDecimal.ROUND_HALF_UP); try { // Calculate Acc and Def Plan from Product String isDeferred = "N"; @@ -1765,7 +1763,7 @@ BigDecimal qtyOrdered = ol.getOrderedQuantity(); taxBaseAmt = ol.getTaxableAmount(); if (qtyOrdered.compareTo(ZERO) != 0) { - taxBaseAmt = (taxBaseAmt.multiply(qty)).divide(qtyOrdered, curPrecision, + taxBaseAmt = (taxBaseAmt.multiply(qty)).divide(qtyOrdered, stdPrecision, BigDecimal.ROUND_HALF_UP); } } diff -r 2873be0d1b66 -r 40185fb2080e src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql --- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql Mon Sep 04 14:03:39 2017 +0530 +++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql Tue Sep 05 13:38:02 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, + 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, + 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, 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, + 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 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits