details: https://code.openbravo.com/erp/devel/pi/rev/ca914539af5d changeset: 28596:ca914539af5d user: Víctor Martínez Romanos <victor.martinez <at> openbravo.com> date: Tue Nov 17 17:32:11 2015 +0100 summary: Fixed bug 31354: Wrong amtsourcedr and amtsourcecr when posting Matched Invoice
The cost is always calculated and posted in the organization's currency. The expense is calculated and posted in the invoice's currency. The conversion date from the cost currency to the acct. schema currency uses the shipment accounting date. The conversion date from the invoice currency to the acct. schema currency uses the invoice accounting date. The difference for the price variant is calculated and posted in the cost currency. In case there is a difference in the conversion rate between the order and the invoice, the usual currency balance entry is automatically created details: https://code.openbravo.com/erp/devel/pi/rev/588f8a97fd4d changeset: 28597:588f8a97fd4d user: Víctor Martínez Romanos <victor.martinez <at> openbravo.com> date: Tue Feb 09 12:46:23 2016 +0100 summary: Related to issue 31354: Difference for price variant calculation The difference for price variants is now calculated and posted in the Acct. Schema currency as it was originally done details: https://code.openbravo.com/erp/devel/pi/rev/c4a8d69297b1 changeset: 28598:c4a8d69297b1 user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Thu Feb 11 09:50:00 2016 +0100 summary: Related to issue 31354: Adapt TestCosting Fix foreign currency debit, foreign currency credit and currency checks for ReceiptInvoiceMatch document in assertDocumentPost method in testCostingMC444 and testCostingMC445 tests. diffstat: src-test/src/org/openbravo/test/costing/TestCosting.java | 34 +++++++- src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java | 58 ++++++++------- 2 files changed, 59 insertions(+), 33 deletions(-) diffs (185 lines): diff -r 5f2dad834745 -r c4a8d69297b1 src-test/src/org/openbravo/test/costing/TestCosting.java --- a/src-test/src/org/openbravo/test/costing/TestCosting.java Fri Feb 12 09:01:15 2016 +0100 +++ b/src-test/src/org/openbravo/test/costing/TestCosting.java Thu Feb 11 09:50:00 2016 +0100 @@ -13094,11 +13094,17 @@ rate = BigDecimal.ONE; } - else if ((document.getEntityName().equals(ShipmentInOut.ENTITY_NAME) || document - .getEntityName().equals(CostAdjustment.ENTITY_NAME)) + else if ((document.getEntityName().equals(ShipmentInOut.ENTITY_NAME) + || document.getEntityName().equals(CostAdjustment.ENTITY_NAME) || (document + .getEntityName().equals(ReceiptInvoiceMatch.ENTITY_NAME) && (line.getEntityName() + .equals(ShipmentInOutLine.ENTITY_NAME) || (line.getEntityName().equals( + InvoiceLine.ENTITY_NAME) && ((InvoiceLine) line).getInvoice().getCurrency() + .equals(CURRENCY2_ID))))) && OBDal.getInstance().get(Organization.class, ORGANIZATION_ID).getCurrency() != null && OBDal.getInstance().get(Organization.class, ORGANIZATION_ID).getCurrency().getId() - .equals(CURRENCY2_ID)) { + .equals(CURRENCY2_ID) + && !accountingFact.getCurrency().getId() + .equals(accountingFact.getAccountingSchema().getCurrency().getId())) { Calendar calendar = Calendar.getInstance(); calendar.set(9999, 0, 1); OBCriteria<ConversionRate> criteria = OBDal.getInstance().createCriteria( @@ -13113,6 +13119,15 @@ rate = criteria.list().get(0).getMultipleRateBy(); } + else if (document.getEntityName().equals(ReceiptInvoiceMatch.ENTITY_NAME) + && line.getEntityName().equals(InvoiceLine.ENTITY_NAME) + && !((InvoiceLine) line).getInvoice().getCurrencyConversionRateDocList().isEmpty() + && BigDecimal.ZERO.compareTo(((InvoiceLine) line).getInvoice() + .getCurrencyConversionRateDocList().get(0).getRate()) != 0) { + rate = BigDecimal.ONE.divide(((InvoiceLine) line).getInvoice() + .getCurrencyConversionRateDocList().get(0).getRate()); + } + assertEquals( accountingFact.getForeignCurrencyDebit().setScale(2, BigDecimal.ROUND_HALF_UP), documentPostAssert @@ -13243,6 +13258,9 @@ if ((productId != null && productId.equals(LANDEDCOSTTYPE3_ID)) || (document.getEntityName().equals(Invoice.ENTITY_NAME) && ((Invoice) document) .getCurrency().getId().equals(CURRENCY2_ID)) + || (document.getEntityName().equals(ReceiptInvoiceMatch.ENTITY_NAME) + && line.getEntityName().equals(InvoiceLine.ENTITY_NAME) && ((InvoiceLine) line) + .getInvoice().getCurrency().getId().equals(CURRENCY2_ID)) || (document.getEntityName().equals(LandedCost.ENTITY_NAME) && ((LCReceiptLineAmt) line) .getLandedCostCost() .getLandedCostType() @@ -13253,10 +13271,12 @@ && ((LCMatched) line).getInvoiceLine().getProduct() != null && ((LCMatched) line) .getInvoiceLine().getProduct().getId().equals(LANDEDCOSTTYPE3_ID)) || (!document.getEntityName().equals(Invoice.ENTITY_NAME) - && !document.getEntityName().equals(ReceiptInvoiceMatch.ENTITY_NAME) - && OBDal.getInstance().get(Organization.class, ORGANIZATION_ID).getCurrency() != null && OBDal - .getInstance().get(Organization.class, ORGANIZATION_ID).getCurrency().getId() - .equals(CURRENCY2_ID))) { + && !(document.getEntityName().equals(ReceiptInvoiceMatch.ENTITY_NAME) && line + .getEntityName().equals(InvoiceLine.ENTITY_NAME)) + && OBDal.getInstance().get(Organization.class, ORGANIZATION_ID).getCurrency() != null + && OBDal.getInstance().get(Organization.class, ORGANIZATION_ID).getCurrency() + .getId().equals(CURRENCY2_ID) && !accountingFact.getCurrency().getId() + .equals(accountingFact.getAccountingSchema().getCurrency().getId()))) { assertEquals(accountingFact.getCurrency(), OBDal.getInstance().get(Currency.class, CURRENCY2_ID)); } else { diff -r 5f2dad834745 -r c4a8d69297b1 src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java --- a/src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java Fri Feb 12 09:01:15 2016 +0100 +++ b/src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java Thu Feb 11 09:50:00 2016 +0100 @@ -11,7 +11,7 @@ * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved. * Contributor(s): Openbravo SLU - * Contributions are Copyright (C) 2001-2014 Openbravo S.L.U. + * Contributions are Copyright (C) 2001-2015 Openbravo S.L.U. ****************************************************************************** */ package org.openbravo.erpCommon.ad_forms; @@ -313,7 +313,17 @@ String strInvoiceCurrency = invoiceData[0].cCurrencyId; String strIsSOTrx = invoiceData[0].issotrx; String strRecordId = invoiceData[0].cInvoiceId; - String strReceiptDate = data[0].getField("ORDERDATEACCT"); + String strReceiptDate = data[0].getField("orderAcctDate"); + int invoiceCurrencyPrecission = 2; + try { + OBContext.setAdminMode(); + invoiceCurrencyPrecission = OBDal.getInstance().get(Currency.class, strInvoiceCurrency) + .getStandardPrecision().intValue(); + } catch (Exception ignore) { + } finally { + OBContext.restorePreviousMode(); + } + BigDecimal bdExpenses = new BigDecimal(strExpenses).multiply( new BigDecimal(data[0].getField("QTY"))).divide( new BigDecimal(data[0].getField("QTYINVOICED"))); @@ -330,9 +340,6 @@ docLine.m_C_Campaign_ID = data[0].getField("INOUTCAMPAING"); docLine.m_C_Activity_ID = data[0].getField("INOUTACTIVITY"); docLine.m_C_Costcenter_ID = data[0].getField("INOUTCOSCENTER"); - // Calculate Difference amount in schema currency - bdCost = new BigDecimal(getConvertedAmt(bdCost.toString(), costCurrency.getId(), - as.m_C_Currency_ID, strReceiptDate, "", vars.getClient(), vars.getOrg(), conn)); if (ZERO.compareTo(bdCost) == 0) { strMessage = "@MatchedInvIsZero@"; @@ -343,32 +350,22 @@ DocLine_Material line = (DocLine_Material) p_inOutlines[i]; BigDecimal lineAmount = bdCost.multiply(new BigDecimal(line.m_qty)).divide( new BigDecimal(data[0].getField("MOVEMENTQTY")), - OBDal.getInstance().get(Currency.class, as.m_C_Currency_ID).getStandardPrecision() - .intValue(), BigDecimal.ROUND_HALF_UP); + costCurrency.getStandardPrecision().intValue(), BigDecimal.ROUND_HALF_UP); if (i == p_inOutlines.length - 1) { lineAmount = bdCost.subtract(totalInOutLines); } dr = fact.createLine(line, getAccount(AcctServer.ACCTTYPE_NotInvoicedReceipts, as, conn), - as.m_C_Currency_ID, lineAmount.toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo), - DocumentType, conn); + costCurrency.getId(), lineAmount.toString(), "0", Fact_Acct_Group_ID, nextSeqNo(SeqNo), + DocumentType, strReceiptDate, conn); totalInOutLines = totalInOutLines.add(lineAmount); } - 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 " + " cost of the product to not invoiced receipt account."); return null; } + ProductInfo p = new ProductInfo(data[0].getField("M_Product_Id"), conn); BigDecimal totalLines = BigDecimal.ZERO; for (int i = 0; i < p_lines.length; i++) { @@ -376,16 +373,14 @@ BigDecimal lineAmount = BigDecimal.ZERO; BigDecimal linenetamt = new BigDecimal(invoiceData[0].linenetamt); if (!(linenetamt.compareTo(BigDecimal.ZERO) == 0)) { - lineAmount = bdExpensesAcctCurrency.multiply(new BigDecimal(line.getAmount())).divide( - linenetamt, - OBDal.getInstance().get(Currency.class, strInvoiceCurrency).getStandardPrecision() - .intValue(), BigDecimal.ROUND_HALF_UP); + lineAmount = bdExpenses.multiply(new BigDecimal(line.getAmount())).divide(linenetamt, + invoiceCurrencyPrecission, BigDecimal.ROUND_HALF_UP); if (i == p_lines.length - 1) { - lineAmount = bdExpensesAcctCurrency.subtract(totalLines); + lineAmount = bdExpenses.subtract(totalLines); } cr = fact.createLine(line, p.getAccount(ProductInfo.ACCTTYPE_P_Expense, as, conn), - as.m_C_Currency_ID, "0", lineAmount.toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo), - DocumentType, conn); + strInvoiceCurrency, "0", lineAmount.toString(), Fact_Acct_Group_ID, nextSeqNo(SeqNo), + DocumentType, DateAcct, conn); totalLines = totalLines.add(lineAmount); } } @@ -404,6 +399,17 @@ } updateProductInfo(as.getC_AcctSchema_ID(), conn, con); // only API + 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)); + // Calculate Difference amount in schema currency + bdCost = new BigDecimal(getConvertedAmt(bdCost.toString(), costCurrency.getId(), + as.m_C_Currency_ID, strReceiptDate, "", vars.getClient(), vars.getOrg(), conn)); + BigDecimal bdDifference = bdExpensesAcctCurrency.subtract(bdCost); if (bdDifference.signum() != 0) { BigDecimal totalDiffLines = BigDecimal.ZERO; for (int i = 0; i < p_inOutlines.length; i++) { ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits