details: https://code.openbravo.com/erp/devel/pi/rev/73d7dc299c01 changeset: 18581:73d7dc299c01 user: Ioritz Cia <ioritz.cia <at> openbravo.com> date: Tue Nov 20 12:57:42 2012 +0100 summary: Fixes issue 21889: Invoice's tax rate not taken into account in Matched Invoice.
details: https://code.openbravo.com/erp/devel/pi/rev/cdf443bcad4a changeset: 18582:cdf443bcad4a user: Ioritz Cia <ioritz.cia <at> openbravo.com> date: Tue Nov 20 12:59:03 2012 +0100 summary: Fixes issue 21890: The cost is not correctly calculated when posting matched invoices. diffstat: src/org/openbravo/erpCommon/ad_forms/AcctServer.java | 34 +++++++++---- src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java | 28 +++++++--- src/org/openbravo/erpCommon/ad_forms/DocMatchInv_data.xsql | 4 +- 3 files changed, 44 insertions(+), 22 deletions(-) diffs (144 lines): diff -r 7006f95b06fd -r cdf443bcad4a src/org/openbravo/erpCommon/ad_forms/AcctServer.java --- a/src/org/openbravo/erpCommon/ad_forms/AcctServer.java Wed Nov 21 08:35:17 2012 +0100 +++ b/src/org/openbravo/erpCommon/ad_forms/AcctServer.java Tue Nov 20 12:59:03 2012 +0100 @@ -2163,13 +2163,21 @@ // return amt; // } + public BigDecimal convertAmount(BigDecimal _amount, boolean isReceipt, String dateAcct, + String table_ID, String record_ID, String currencyIDFrom, String currencyIDTo, DocLine line, + AcctSchema as, Fact fact, String Fact_Acct_Group_ID, String seqNo, ConnectionProvider conn) + throws ServletException { + return convertAmount(_amount, isReceipt, dateAcct, table_ID, record_ID, currencyIDFrom, + currencyIDTo, line, as, fact, Fact_Acct_Group_ID, seqNo, conn, true); + } + /* * Returns an amount without applying currency precision for rounding purposes */ public BigDecimal convertAmount(BigDecimal _amount, boolean isReceipt, String dateAcct, String table_ID, String record_ID, String currencyIDFrom, String currencyIDTo, DocLine line, - AcctSchema as, Fact fact, String Fact_Acct_Group_ID, String seqNo, ConnectionProvider conn) - throws ServletException { + AcctSchema as, Fact fact, String Fact_Acct_Group_ID, String seqNo, ConnectionProvider conn, + boolean bookDifferences) throws ServletException { BigDecimal amtDiff = BigDecimal.ZERO; if (_amount == null || _amount.compareTo(BigDecimal.ZERO) == 0) { return _amount; @@ -2261,15 +2269,19 @@ Currency currencyTo = OBDal.getInstance().get(Currency.class, currencyIDTo); amtDiff = amtDiff.setScale(currencyTo.getStandardPrecision().intValue(), BigDecimal.ROUND_HALF_EVEN); - if ((!isReceipt && amtDiff.compareTo(BigDecimal.ZERO) == 1) - || (isReceipt && amtDiff.compareTo(BigDecimal.ZERO) == -1)) { - fact.createLine(line, getAccount(AcctServer.ACCTTYPE_ConvertGainDefaultAmt, as, conn), - currencyIDTo, "", amtDiff.abs().toString(), Fact_Acct_Group_ID, seqNo, DocumentType, conn); - } else if (amtDiff.compareTo(BigDecimal.ZERO) != 0) { - fact.createLine(line, getAccount(AcctServer.ACCTTYPE_ConvertChargeDefaultAmt, as, conn), - currencyIDTo, amtDiff.abs().toString(), "", Fact_Acct_Group_ID, seqNo, DocumentType, conn); - } else { - return amtFromSourcecurrency; + if (bookDifferences) { + if ((!isReceipt && amtDiff.compareTo(BigDecimal.ZERO) == 1) + || (isReceipt && amtDiff.compareTo(BigDecimal.ZERO) == -1)) { + fact.createLine(line, getAccount(AcctServer.ACCTTYPE_ConvertGainDefaultAmt, as, conn), + currencyIDTo, "", amtDiff.abs().toString(), Fact_Acct_Group_ID, seqNo, DocumentType, + conn); + } else if (amtDiff.compareTo(BigDecimal.ZERO) != 0) { + fact.createLine(line, getAccount(AcctServer.ACCTTYPE_ConvertChargeDefaultAmt, as, conn), + currencyIDTo, amtDiff.abs().toString(), "", Fact_Acct_Group_ID, seqNo, DocumentType, + conn); + } else { + return amtFromSourcecurrency; + } } if (log4j.isDebugEnabled()) log4j.debug("Amt from: " + amtFrom + "[" + currencyIDFrom + "]" + " Amt to: " + amtTo + "[" diff -r 7006f95b06fd -r cdf443bcad4a src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java --- a/src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java Wed Nov 21 08:35:17 2012 +0100 +++ b/src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java Tue Nov 20 12:59:03 2012 +0100 @@ -199,10 +199,12 @@ } BigDecimal trxCost = transaction.getTransactionCost(); // Cost is retrieved from the transaction and if it does not exist It calls the old way + // The precision of the divide is set to 10 because the rounding is needed to avoid exceptions. + // The rounding itself is not needed because it is done some lines later. BigDecimal bdCost = CostingStatus.getInstance().isMigrated() ? trxCost.divide( - transaction.getMovementQuantity(), costCurrency.getCostingPrecision().intValue(), - RoundingMode.HALF_UP) : new BigDecimal(DocMatchInvData.selectProductAverageCost(conn, - data[0].getField("M_Product_Id"), data[0].getField("orderAcctDate"))); + transaction.getMovementQuantity(), 10, RoundingMode.HALF_UP) : new BigDecimal( + DocMatchInvData.selectProductAverageCost(conn, data[0].getField("M_Product_Id"), + data[0].getField("orderAcctDate"))); Long scale = costCurrency.getStandardPrecision(); BigDecimal bdQty = new BigDecimal(data[0].getField("Qty")); bdCost = bdCost.multiply(bdQty).setScale(scale.intValue(), RoundingMode.HALF_UP); @@ -212,7 +214,8 @@ String strExpenses = invoiceData[0].linenetamt; String strInvoiceCurrency = invoiceData[0].cCurrencyId; - String strDate = invoiceData[0].dateacct; + String strIsSOTrx = invoiceData[0].issotrx; + String strRecordId = invoiceData[0].cInvoiceId; String strReceiptDate = data[0].getField("ORDERDATEACCT"); BigDecimal bdExpenses = new BigDecimal(strExpenses); if ((new BigDecimal(data[0].getField("QTYINVOICED")).signum() != (new BigDecimal( @@ -235,9 +238,16 @@ dr = fact.createLine(docLine, getAccount(AcctServer.ACCTTYPE_NotInvoicedReceipts, as, conn), as.m_C_Currency_ID, bdCost.toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn); - bdExpenses = new BigDecimal(getConvertedAmt(bdExpenses.toString(), strInvoiceCurrency, - as.m_C_Currency_ID, strDate, "", vars.getClient(), vars.getOrg(), conn)); - BigDecimal bdDifference = bdExpenses.subtract(bdCost); + + bdExpenses = convertAmount(bdExpenses, strIsSOTrx.equalsIgnoreCase("Y") ? true : false, + DateAcct, TABLEID_Invoice, strRecordId, strInvoiceCurrency, as.m_C_Currency_ID, docLine, + as, fact, Fact_Acct_Group_ID, SeqNo, conn, false); + + BigDecimal bdExpensesAcctCurrency = new BigDecimal( + getConvertedAmt(bdExpenses.toString(), strInvoiceCurrency, as.m_C_Currency_ID, DateAcct, + "", vars.getClient(), vars.getOrg(), conn)); + + BigDecimal bdDifference = bdExpensesAcctCurrency.subtract(bdCost); if (dr == null) { log4j.warn("createFact - unable to calculate line with " @@ -247,7 +257,7 @@ ProductInfo p = new ProductInfo(data[0].getField("M_Product_Id"), conn); cr = fact.createLine(p_lines[0], p.getAccount(ProductInfo.ACCTTYPE_P_Expense, as, conn), - as.m_C_Currency_ID, "0", bdExpenses.toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo), + strInvoiceCurrency, "0", bdExpenses.toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn); if (cr == null && ZERO.compareTo(bdExpenses) != 0) { log4j.warn("createFact - unable to calculate line with " @@ -264,7 +274,7 @@ } updateProductInfo(as.getC_AcctSchema_ID(), conn, con); // only API - if (bdCost.compareTo(bdExpenses) != 0) { + if (bdDifference.signum() != 0) { diff = fact.createLine(docLine, p.getAccount(ProductInfo.ACCTTYPE_P_IPV, as, conn), as.m_C_Currency_ID, (bdDifference.compareTo(BigDecimal.ZERO) == 1) ? bdDifference.abs() .toString() : "0", (bdDifference.compareTo(BigDecimal.ZERO) < 1) ? bdDifference.abs() diff -r 7006f95b06fd -r cdf443bcad4a src/org/openbravo/erpCommon/ad_forms/DocMatchInv_data.xsql --- a/src/org/openbravo/erpCommon/ad_forms/DocMatchInv_data.xsql Wed Nov 21 08:35:17 2012 +0100 +++ b/src/org/openbravo/erpCommon/ad_forms/DocMatchInv_data.xsql Tue Nov 20 12:59:03 2012 +0100 @@ -35,7 +35,7 @@ '' AS ISDESCRIPTION, '' AS QUANTITYORDER, '' AS M_PRODUCT_UOM_ID, '' AS C_CAMPAIGN_ID, '' AS C_PROJECT_ID, '' AS USER1_ID, '' AS USER2_ID, '' AS GLITEM_CREDIT_ACCT, - '' AS GLITEM_DEBIT_ACCT, '' AS INOUTPROJECT, '' AS C_INVOICE_ID + '' AS GLITEM_DEBIT_ACCT, '' AS INOUTPROJECT, '' AS C_INVOICE_ID, '' AS ISSOTRX FROM DUAL ]]> </Sql> @@ -72,7 +72,7 @@ <SqlMethod name="selectInvoiceData" type="preparedStatement" return="multiple"> <SqlMethodComment></SqlMethodComment> <Sql> - SELECT L.LINENETAMT, I.C_CURRENCY_ID, I.DATEACCT + SELECT L.LINENETAMT, I.C_CURRENCY_ID, I.DATEACCT, I.ISSOTRX, I.C_INVOICE_ID FROM C_INVOICELINE L, C_INVOICE I WHERE L.AD_CLIENT_ID = ? AND L.C_INVOICELINE_ID = ? ------------------------------------------------------------------------------ Monitor your physical, virtual and cloud infrastructure from a single web console. Get in-depth insight into apps, servers, databases, vmware, SAP, cloud infrastructure, etc. Download 30-day Free Trial. Pricing starts from $795 for 25 servers or applications! http://p.sf.net/sfu/zoho_dev2dev_nov _______________________________________________ Openbravo-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbravo-commits
