details: https://code.openbravo.com/erp/devel/pi/rev/e36d52a51aee changeset: 35427:e36d52a51aee user: Sandra Huguet <sandra.huguet <at> openbravo.com> date: Thu Jan 31 16:18:04 2019 +0100 summary: Fixed issue 39969 Avoid NPE when posting a payment/transaction/reconciliation of a Cash VAT invoice with different currency.
After convert the tax amount with from the used currency to the financial account currency it is possible that this conversion is ZERO. If Amount converted is zero should have the same behaviour as when amount is zero. details: https://code.openbravo.com/erp/devel/pi/rev/e4b514229785 changeset: 35428:e4b514229785 user: David Miguelez <david.miguelez <at> openbravo.com> date: Mon Feb 04 11:53:15 2019 +0100 summary: Related to Issue 39969. Code Review changes. Moved logic to retrieve some variables after if clause. If the condition is not fulfilled, it is not necessary to initialize this variables. details: https://code.openbravo.com/erp/devel/pi/rev/5b3625a0edb3 changeset: 35429:5b3625a0edb3 user: Sandra Huguet <sandra.huguet <at> openbravo.com> date: Mon Feb 04 13:38:49 2019 +0100 summary: related to issue 39969 update Copyright year details: https://code.openbravo.com/erp/devel/pi/rev/94c8cd7d1c55 changeset: 35430:94c8cd7d1c55 user: Atul Gaware <atul.gaware <at> openbravo.com> date: Tue Jan 29 23:13:57 2019 +0530 summary: Fixes Issue 0039993: / by zero error in Costing Background Process with backdated and negative stock correction and voided goods receipt In case of negative stock correction, handle divide by zero when currentStock value is zero diffstat: src/org/openbravo/costing/AverageCostAdjustment.java | 12 +- src/org/openbravo/erpCommon/utility/CashVATUtil.java | 117 +++++++++--------- 2 files changed, 67 insertions(+), 62 deletions(-) diffs (187 lines): diff -r 9141b6a4a4e8 -r 94c8cd7d1c55 src/org/openbravo/costing/AverageCostAdjustment.java --- a/src/org/openbravo/costing/AverageCostAdjustment.java Tue Feb 05 08:11:05 2019 +0100 +++ b/src/org/openbravo/costing/AverageCostAdjustment.java Tue Jan 29 23:13:57 2019 +0530 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2014-2018 Openbravo SLU + * All portions are Copyright (C) 2014-2019 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************* @@ -376,10 +376,12 @@ lineParameters.setNegativeCorrection(true); lineParameters.setRelatedTransactionAdjusted(true); insertCostAdjustmentLine(lineParameters); - cost = currentValueAmt.add(adjustmentBalance) - .divide(currentStock, costCurPrecission, RoundingMode.HALF_UP); - log.debug("Revert Negative stock correction. Amount: {}, new cost {}", - revertedNegativeAdjustment.toPlainString(), cost.toPlainString()); + if (currentStock.signum() != 0) { + cost = currentValueAmt.add(adjustmentBalance) + .divide(currentStock, costCurPrecission, RoundingMode.HALF_UP); + log.debug("Revert Negative stock correction. Amount: {}, new cost {}", + revertedNegativeAdjustment.toPlainString(), cost.toPlainString()); + } } } diff -r 9141b6a4a4e8 -r 94c8cd7d1c55 src/org/openbravo/erpCommon/utility/CashVATUtil.java --- a/src/org/openbravo/erpCommon/utility/CashVATUtil.java Tue Feb 05 08:11:05 2019 +0100 +++ b/src/org/openbravo/erpCommon/utility/CashVATUtil.java Tue Jan 29 23:13:57 2019 +0530 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2013-2018 Openbravo SLU + * All portions are Copyright (C) 2013-2019 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -516,26 +516,48 @@ if (tax.isCashVAT() && StringUtils.equals(inv.getId(), invoice.getId())) { final BigDecimal taxAmt = itcv.getTaxAmount(); if (taxAmt.compareTo(BigDecimal.ZERO) != 0) { - final DocTax m_tax = new DocTax(tax.getId(), tax.getName(), tax.getRate().toString(), - itcv.getInvoiceTax().getTaxableAmount().toString(), - itcv.getTaxAmount().toString(), tax.isNotTaxdeductable(), tax.isTaxdeductable()); - final String invoicedocumentType = invoice.getDocumentType().getDocumentCategory(); - final boolean isReversal = invoice.getDocumentType().isReversal(); String dateFormatString = OBPropertiesProvider.getInstance() .getOpenbravoProperties() .getProperty("dateFormat.java"); SimpleDateFormat dateFormat = new SimpleDateFormat(dateFormatString); - String taxAmountConverted = fact.getM_doc() + BigDecimal taxAmtConverted = fact.getM_doc() .convertAmount(taxAmt, invoice.isSalesTransaction(), dateFormat.format(invoice.getAccountingDate()), AcctServer.TABLEID_Invoice, invoice.getId(), invoice.getCurrency().getId(), as.m_C_Currency_ID, line, as, - fact, Fact_Acct_Group_ID, nextSeqNo(SeqNo), conn) - .toString(); - // ARI, ARF, ARI_RM - if (invoicedocumentType.equals(AcctServer.DOCTYPE_ARInvoice) - || invoicedocumentType.equals(AcctServer.DOCTYPE_ARProForma) - || invoicedocumentType.equals(AcctServer.DOCTYPE_RMSalesInvoice)) { - if (isReversal) { + fact, Fact_Acct_Group_ID, nextSeqNo(SeqNo), conn); + if (taxAmtConverted.compareTo(BigDecimal.ZERO) != 0) { + String taxAmountConverted = taxAmtConverted.toString(); + final DocTax m_tax = new DocTax(tax.getId(), tax.getName(), + tax.getRate().toString(), itcv.getInvoiceTax().getTaxableAmount().toString(), + itcv.getTaxAmount().toString(), tax.isNotTaxdeductable(), + tax.isTaxdeductable()); + final String invoicedocumentType = invoice.getDocumentType().getDocumentCategory(); + final boolean isReversal = invoice.getDocumentType().isReversal(); + // ARI, ARF, ARI_RM + if (invoicedocumentType.equals(AcctServer.DOCTYPE_ARInvoice) + || invoicedocumentType.equals(AcctServer.DOCTYPE_ARProForma) + || invoicedocumentType.equals(AcctServer.DOCTYPE_RMSalesInvoice)) { + if (isReversal) { + final FactLine factLine1 = fact.createLine(line, + m_tax.getAccount(DocTax.ACCTTYPE_TaxDue_Trans, as, conn), + invoice.getCurrency().getId(), "", taxAmountConverted, Fact_Acct_Group_ID, + nextSeqNo(SeqNo), documentType, conn); + factLine2 = fact.createLine(line, + m_tax.getAccount(DocTax.ACCTTYPE_TaxDue, as, conn), + invoice.getCurrency().getId(), taxAmt.toString(), "", Fact_Acct_Group_ID, + nextSeqNo(factLine1.m_SeqNo), documentType, conn); + } else { + final FactLine factLine1 = fact.createLine(line, + m_tax.getAccount(DocTax.ACCTTYPE_TaxDue_Trans, as, conn), + invoice.getCurrency().getId(), taxAmountConverted, "", Fact_Acct_Group_ID, + nextSeqNo(SeqNo), documentType, conn); + factLine2 = fact.createLine(line, + m_tax.getAccount(DocTax.ACCTTYPE_TaxDue, as, conn), + invoice.getCurrency().getId(), "", taxAmt.toString(), Fact_Acct_Group_ID, + nextSeqNo(factLine1.m_SeqNo), documentType, conn); + } + } // ARC + else if (invoicedocumentType.equals(AcctServer.DOCTYPE_ARCredit)) { final FactLine factLine1 = fact.createLine(line, m_tax.getAccount(DocTax.ACCTTYPE_TaxDue_Trans, as, conn), invoice.getCurrency().getId(), "", taxAmountConverted, Fact_Acct_Group_ID, @@ -544,30 +566,31 @@ m_tax.getAccount(DocTax.ACCTTYPE_TaxDue, as, conn), invoice.getCurrency().getId(), taxAmt.toString(), "", Fact_Acct_Group_ID, nextSeqNo(factLine1.m_SeqNo), documentType, conn); - } else { - final FactLine factLine1 = fact.createLine(line, - m_tax.getAccount(DocTax.ACCTTYPE_TaxDue_Trans, as, conn), - invoice.getCurrency().getId(), taxAmountConverted, "", Fact_Acct_Group_ID, - nextSeqNo(SeqNo), documentType, conn); - factLine2 = fact.createLine(line, - m_tax.getAccount(DocTax.ACCTTYPE_TaxDue, as, conn), - invoice.getCurrency().getId(), "", taxAmt.toString(), Fact_Acct_Group_ID, - nextSeqNo(factLine1.m_SeqNo), documentType, conn); } - } // ARC - else if (invoicedocumentType.equals(AcctServer.DOCTYPE_ARCredit)) { - final FactLine factLine1 = fact.createLine(line, - m_tax.getAccount(DocTax.ACCTTYPE_TaxDue_Trans, as, conn), - invoice.getCurrency().getId(), "", taxAmountConverted, Fact_Acct_Group_ID, - nextSeqNo(SeqNo), documentType, conn); - factLine2 = fact.createLine(line, - m_tax.getAccount(DocTax.ACCTTYPE_TaxDue, as, conn), - invoice.getCurrency().getId(), taxAmt.toString(), "", Fact_Acct_Group_ID, - nextSeqNo(factLine1.m_SeqNo), documentType, conn); - } - // API - else if (invoicedocumentType.equals(AcctServer.DOCTYPE_APInvoice)) { - if (isReversal) { + // API + else if (invoicedocumentType.equals(AcctServer.DOCTYPE_APInvoice)) { + if (isReversal) { + final FactLine factLine1 = fact.createLine(line, + m_tax.getAccount(DocTax.ACCTTYPE_TaxCredit_Trans, as, conn), + invoice.getCurrency().getId(), taxAmountConverted, "", Fact_Acct_Group_ID, + nextSeqNo(SeqNo), documentType, conn); + factLine2 = fact.createLine(line, + m_tax.getAccount(DocTax.ACCTTYPE_TaxCredit, as, conn), + invoice.getCurrency().getId(), "", taxAmt.toString(), Fact_Acct_Group_ID, + nextSeqNo(factLine1.m_SeqNo), documentType, conn); + } else { + final FactLine factLine1 = fact.createLine(line, + m_tax.getAccount(DocTax.ACCTTYPE_TaxCredit_Trans, as, conn), + invoice.getCurrency().getId(), "", taxAmountConverted, Fact_Acct_Group_ID, + nextSeqNo(SeqNo), documentType, conn); + factLine2 = fact.createLine(line, + m_tax.getAccount(DocTax.ACCTTYPE_TaxCredit, as, conn), + invoice.getCurrency().getId(), taxAmt.toString(), "", Fact_Acct_Group_ID, + nextSeqNo(factLine1.m_SeqNo), documentType, conn); + } + } + // APC + else if (invoicedocumentType.equals(AcctServer.DOCTYPE_APCredit)) { final FactLine factLine1 = fact.createLine(line, m_tax.getAccount(DocTax.ACCTTYPE_TaxCredit_Trans, as, conn), invoice.getCurrency().getId(), taxAmountConverted, "", Fact_Acct_Group_ID, @@ -576,28 +599,8 @@ m_tax.getAccount(DocTax.ACCTTYPE_TaxCredit, as, conn), invoice.getCurrency().getId(), "", taxAmt.toString(), Fact_Acct_Group_ID, nextSeqNo(factLine1.m_SeqNo), documentType, conn); - } else { - final FactLine factLine1 = fact.createLine(line, - m_tax.getAccount(DocTax.ACCTTYPE_TaxCredit_Trans, as, conn), - invoice.getCurrency().getId(), "", taxAmountConverted, Fact_Acct_Group_ID, - nextSeqNo(SeqNo), documentType, conn); - factLine2 = fact.createLine(line, - m_tax.getAccount(DocTax.ACCTTYPE_TaxCredit, as, conn), - invoice.getCurrency().getId(), taxAmt.toString(), "", Fact_Acct_Group_ID, - nextSeqNo(factLine1.m_SeqNo), documentType, conn); } } - // APC - else if (invoicedocumentType.equals(AcctServer.DOCTYPE_APCredit)) { - final FactLine factLine1 = fact.createLine(line, - m_tax.getAccount(DocTax.ACCTTYPE_TaxCredit_Trans, as, conn), - invoice.getCurrency().getId(), taxAmountConverted, "", Fact_Acct_Group_ID, - nextSeqNo(SeqNo), documentType, conn); - factLine2 = fact.createLine(line, - m_tax.getAccount(DocTax.ACCTTYPE_TaxCredit, as, conn), - invoice.getCurrency().getId(), "", taxAmt.toString(), Fact_Acct_Group_ID, - nextSeqNo(factLine1.m_SeqNo), documentType, conn); - } } } } _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits