details: https://code.openbravo.com/erp/devel/pi/rev/a382e7ffe1c0 changeset: 26350:a382e7ffe1c0 user: Víctor Martínez Romanos <victor.martinez <at> openbravo.com> date: Wed Apr 22 17:03:17 2015 +0200 summary: Related to issue 29475: Applied code format before doing any change
details: https://code.openbravo.com/erp/devel/pi/rev/41ab0a941f50 changeset: 26351:41ab0a941f50 user: Víctor Martínez Romanos <victor.martinez <at> openbravo.com> date: Wed Apr 22 18:09:19 2015 +0200 summary: Fixed bug 29475: Cash VAT post incorrect when invoice's price is lower than linked order When the invoice's price is lower than the linked order's price, the system creates 2 payment details: the first one to pay the order, and another one with the difference. In this case the accounting process for Payment/Transaction/Reconciliation merges both payment details. However the Cash VAT logic for posting wasn't aware of the merge, creating a wrong posting. To fix it we first store the merged payment detail id done into the getPaymentDetailWriteOffAndAmount() method. In fact we have created a new getPaymentDetailWriteOffAndAmount() method that has a new parameter with the fieldProvider that represents the processed payment detail id. In this FieldProvider object we store the Merged Payment Detail Id. The DocLineCashVATReady_PaymentTransactionReconciliation class is now able to receive more than one payment detail, and keep track of all the InvoiceTaxCashVAT_V records associated to these payment details. So we can now link several payment details into the same DocLineCashVATReady_PaymentTransactionReconciliation object, which is exactly what we need to support the extra "merged" payment detail id. Finally, we ensure the DocLineCashVATReady_PaymentTransactionReconciliation.getInvoiceTaxCashVAT_V() now returns a list of unique InvoiceTaxCashVAT_V records, to avoid duplications in case the setInvoiceTaxCashVAT_V() method has been called several times for the same payment detail id. diffstat: src/org/openbravo/erpCommon/ad_forms/AcctServer.java | 44 +++++++++- src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java | 4 +- src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java | 3 +- src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java | 3 +- src/org/openbravo/erpCommon/ad_forms/DocLineCashVATReady_PaymentTransactionReconciliation.java | 28 ++++- 5 files changed, 68 insertions(+), 14 deletions(-) diffs (219 lines): diff -r 7eac27cd7440 -r 41ab0a941f50 src/org/openbravo/erpCommon/ad_forms/AcctServer.java --- a/src/org/openbravo/erpCommon/ad_forms/AcctServer.java Fri Apr 24 14:04:00 2015 +0200 +++ b/src/org/openbravo/erpCommon/ad_forms/AcctServer.java Wed Apr 22 18:09:19 2015 +0200 @@ -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; @@ -53,6 +53,7 @@ import org.openbravo.data.FieldProvider; import org.openbravo.database.ConnectionProvider; import org.openbravo.erpCommon.utility.DateTimeData; +import org.openbravo.erpCommon.utility.FieldProviderFactory; import org.openbravo.erpCommon.utility.OBDateUtils; import org.openbravo.erpCommon.utility.OBError; import org.openbravo.erpCommon.utility.OBMessageUtils; @@ -2496,9 +2497,10 @@ throw new OBException("@NotConvertible@"); } if (amtTo.compareTo(BigDecimal.ZERO) != 0) - amtFromSourcecurrency = amtFrom.multiply(_amount).divide(amtTo, conversionRatePrecision, - BigDecimal.ROUND_HALF_EVEN); - else amtFromSourcecurrency = amtFrom; + amtFromSourcecurrency = amtFrom.multiply(_amount).divide(amtTo, conversionRatePrecision, + BigDecimal.ROUND_HALF_EVEN); + else + amtFromSourcecurrency = amtFrom; } } amtDiff = (amtTo).subtract(amtFrom); @@ -2911,7 +2913,37 @@ public HashMap<String, BigDecimal> getPaymentDetailWriteOffAndAmount( List<FIN_PaymentDetail> paymentDetails, FIN_PaymentSchedule ps, FIN_PaymentSchedule psi, FIN_PaymentSchedule pso, int currentPaymentDetailIndex) { + return getPaymentDetailWriteOffAndAmount(paymentDetails, ps, psi, pso, + currentPaymentDetailIndex, null); + } + /** + * Returns the writeoff and the amount of a Payment Detail. In case the related Payment Schedule + * Detail was generated for compensate the difference between an Order and a related Invoice, it + * merges it's amount with the next Payment Schedule Detail. Issue 19567: + * https://issues.openbravo.com/view.php?id=19567 <br /> + * It does exactly the same as the + * {@link #getPaymentDetailWriteOffAndAmount(List, FIN_PaymentSchedule, FIN_PaymentSchedule, FIN_PaymentSchedule, int)} + * method, but it also stores a new field "MergedPaymentDetailId" inside the fieldProvider with + * the merged payment detail id (if any). + * + * @param paymentDetails + * List of payment Details + * @param ps + * Previous Payment Schedule + * @param psi + * Invoice Payment Schedule of actual Payment Detail + * @param pso + * Order Payment Schedule of actual Payment Detail + * @param currentPaymentDetailIndex + * Index + * @param fieldProvider + * contains the FieldProvider with the Payment Detail currently being processed. Used to + * store the "MergedPaymentDetailId" (if any) as a new field of the fieldProvider + */ + public HashMap<String, BigDecimal> getPaymentDetailWriteOffAndAmount( + List<FIN_PaymentDetail> paymentDetails, FIN_PaymentSchedule ps, FIN_PaymentSchedule psi, + FIN_PaymentSchedule pso, int currentPaymentDetailIndex, final FieldProvider fieldProvider) { HashMap<String, BigDecimal> amountAndWriteOff = new HashMap<String, BigDecimal>(); // Default return values @@ -2946,6 +2978,10 @@ "writeoff", paymentDetails.get(currentPaymentDetailIndex).getWriteoffAmount() .add(paymentDetails.get(currentPaymentDetailIndex - 1).getWriteoffAmount())); + if (fieldProvider != null) { + FieldProviderFactory.setField(fieldProvider, "MergedPaymentDetailId", paymentDetails + .get(currentPaymentDetailIndex - 1).getId()); + } } } } diff -r 7eac27cd7440 -r 41ab0a941f50 src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java --- a/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java Fri Apr 24 14:04:00 2015 +0200 +++ b/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java Wed Apr 22 18:09:19 2015 +0200 @@ -146,7 +146,7 @@ // into one. // https://issues.openbravo.com/view.php?id=19567 HashMap<String, BigDecimal> amountAndWriteOff = getPaymentDetailWriteOffAndAmount( - paymentDetails, ps, psi, pso, i); + paymentDetails, ps, psi, pso, i, data[i]); BigDecimal amount = amountAndWriteOff.get("amount"); BigDecimal writeOff = amountAndWriteOff.get("writeoff"); if (amount == null) { @@ -387,7 +387,9 @@ .getInvoice() : null); docLine.setDoubtFulDebtAmount(new BigDecimal(data[i].getField("DoubtFulDebtAmount"))); + docLine.setInvoiceTaxCashVAT_V(paymentDetail_ID); + docLine.setInvoiceTaxCashVAT_V(data[i].getField("MergedPaymentDetailId")); } docLine.setIsPrepayment(data[i].getField("isprepayment")); docLine.setCGlItemId(data[i].getField("cGlItemId")); diff -r 7eac27cd7440 -r 41ab0a941f50 src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java --- a/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java Fri Apr 24 14:04:00 2015 +0200 +++ b/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java Wed Apr 22 18:09:19 2015 +0200 @@ -118,7 +118,7 @@ // into one. // https://issues.openbravo.com/view.php?id=19567 HashMap<String, BigDecimal> amountAndWriteOff = getPaymentDetailWriteOffAndAmount( - paymentDetails, ps, psi, pso, i); + paymentDetails, ps, psi, pso, i, data[i]); BigDecimal amount = amountAndWriteOff.get("amount"); BigDecimal writeOff = amountAndWriteOff.get("writeoff"); if (amount == null) { @@ -302,6 +302,7 @@ : null); docLine.m_Record_Id2 = data[i].getField("recordId2"); docLine.setInvoiceTaxCashVAT_V(Line_ID); + docLine.setInvoiceTaxCashVAT_V(data[i].getField("MergedPaymentDetailId")); list.add(docLine); } finally { OBContext.restorePreviousMode(); diff -r 7eac27cd7440 -r 41ab0a941f50 src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java --- a/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java Fri Apr 24 14:04:00 2015 +0200 +++ b/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java Wed Apr 22 18:09:19 2015 +0200 @@ -192,7 +192,7 @@ // into one. // https://issues.openbravo.com/view.php?id=19567 HashMap<String, BigDecimal> amountAndWriteOff = getPaymentDetailWriteOffAndAmount( - paymentDetails, ps, psi, pso, i); + paymentDetails, ps, psi, pso, i, data[i]); BigDecimal amount = amountAndWriteOff.get("amount"); BigDecimal writeOff = amountAndWriteOff.get("writeoff"); if (amount == null) { @@ -700,6 +700,7 @@ FIN_PaymentDetail paymentDetail = OBDal.getInstance().get(FIN_PaymentDetail.class, finPaymentDetailID); detail.setInvoiceTaxCashVAT_V(finPaymentDetailID); + detail.setInvoiceTaxCashVAT_V(data[i].getField("MergedPaymentDetailId")); fact = createFactPaymentDetails(detail, paymentDetail, as, conn, fact, Fact_Acct_Group_ID, Fact_Acct_Group_ID2); } diff -r 7eac27cd7440 -r 41ab0a941f50 src/org/openbravo/erpCommon/ad_forms/DocLineCashVATReady_PaymentTransactionReconciliation.java --- a/src/org/openbravo/erpCommon/ad_forms/DocLineCashVATReady_PaymentTransactionReconciliation.java Fri Apr 24 14:04:00 2015 +0200 +++ b/src/org/openbravo/erpCommon/ad_forms/DocLineCashVATReady_PaymentTransactionReconciliation.java Wed Apr 22 18:09:19 2015 +0200 @@ -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-2014 Openbravo SLU + * All portions are Copyright (C) 2013-2015 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -20,7 +20,9 @@ package org.openbravo.erpCommon.ad_forms; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.apache.commons.lang.StringUtils; import org.openbravo.dal.core.OBContext; @@ -35,25 +37,37 @@ */ public class DocLineCashVATReady_PaymentTransactionReconciliation extends DocLine { - List<InvoiceTaxCashVAT_V> invoiceTaxCashVAT_V = null; + List<InvoiceTaxCashVAT_V> invoiceTaxCashVAT_V = new ArrayList<InvoiceTaxCashVAT_V>(); public DocLineCashVATReady_PaymentTransactionReconciliation(String DocumentType, String TrxHeader_ID, String TrxLine_ID) { super(DocumentType, TrxHeader_ID, TrxLine_ID); } + /** + * Returns a list of different InvoiceTaxCashVAT_V records. + * + * It internally creates a Set from the invoiceTaxCashVAT_V attribute and returns a List + */ public List<InvoiceTaxCashVAT_V> getInvoiceTaxCashVAT_V() { - return invoiceTaxCashVAT_V; + final Set<InvoiceTaxCashVAT_V> invoiceTaxCashVAT_V_Set = new HashSet<InvoiceTaxCashVAT_V>( + invoiceTaxCashVAT_V); + return new ArrayList<InvoiceTaxCashVAT_V>(invoiceTaxCashVAT_V_Set); } public void setInvoiceTaxCashVAT_V(List<InvoiceTaxCashVAT_V> invoiceTaxCashVAT_V) { this.invoiceTaxCashVAT_V = invoiceTaxCashVAT_V; } + /** + * Given the payment detail id (finPaymentDetailID), the method calculates the linked + * InvoiceTaxCashVAT_V records and adds them to the invoiceTaxCashVAT_V list associated to the + * object. If this method is called several times for different finPaymentDetailID, the system + * will add (not override) the associated invoiceTaxCashVAT_V records to the object + * + */ public void setInvoiceTaxCashVAT_V(String finPaymentDetailID) { - if (StringUtils.isBlank(finPaymentDetailID)) { - this.invoiceTaxCashVAT_V = new ArrayList<InvoiceTaxCashVAT_V>(); - } else { + if (StringUtils.isNotBlank(finPaymentDetailID)) { try { OBContext.setAdminMode(true); final StringBuffer hql = new StringBuffer(); @@ -67,7 +81,7 @@ obq.setFilterOnReadableClients(false); obq.setFilterOnReadableOrganization(false); - this.invoiceTaxCashVAT_V = obq.list(); + this.invoiceTaxCashVAT_V.addAll(obq.list()); } finally { OBContext.restorePreviousMode(); } ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Openbravo-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbravo-commits
