details:   https://code.openbravo.com/erp/devel/pi/rev/165f2247f1d0
changeset: 28264:165f2247f1d0
user:      Víctor Martínez Romanos <victor.martinez <at> openbravo.com>
date:      Thu Jan 14 18:16:17 2016 +0100
summary:   Fixed bug 31873:Multicurrency accounting posting partial invoice 
with prepayment

The selectPrepayments query, used only for foreign currency accounting schemas, 
was wrongly taken into account all the payment details linked to the order.
In case of an invoice linked to a prepaid order, when the invoice's amount is 
lower than the order's amount, the system automatically creates 2 payment 
details both linked to the order, and one of them linked to the invoice too.

After the fix, the query only takes into account the payment details linked to 
both the order and the invoice being posted.

diffstat:

 src/org/openbravo/erpCommon/ad_forms/DocInvoice.java      |  10 +++---
 src/org/openbravo/erpCommon/ad_forms/DocInvoice_data.xsql |  19 ++++++++------
 2 files changed, 16 insertions(+), 13 deletions(-)

diffs (87 lines):

diff -r eb8ad8b3ea7d -r 165f2247f1d0 
src/org/openbravo/erpCommon/ad_forms/DocInvoice.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocInvoice.java      Mon Jan 18 
15:27:35 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocInvoice.java      Thu Jan 14 
18:16:17 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-2015 Openbravo S.L.U.
+ * Contributions are Copyright (C) 2001-2016 Openbravo S.L.U.
  ******************************************************************************
  */
 package org.openbravo.erpCommon.ad_forms;
@@ -344,7 +344,7 @@
           } else if 
(!m_payments[i].C_Currency_ID_From.equals(as.m_C_Currency_ID)) {
             try {
               DocInvoiceData[] prepayments = 
DocInvoiceData.selectPrepayments(connectionProvider,
-                  m_payments[i].Line_ID);
+                  m_payments[i].Line_ID, Record_ID);
               for (int j = 0; j < prepayments.length; j++) {
                 BigDecimal prePaymentAmt = convertAmount(new 
BigDecimal(prepayments[j].prepaidamt),
                     true, DateAcct, TABLEID_Payment, 
prepayments[j].finPaymentId,
@@ -581,7 +581,7 @@
           } else if 
(!m_payments[i].C_Currency_ID_From.equals(as.m_C_Currency_ID)) {
             try {
               DocInvoiceData[] prepayments = 
DocInvoiceData.selectPrepayments(connectionProvider,
-                  m_payments[i].Line_ID);
+                  m_payments[i].Line_ID, Record_ID);
               for (int j = 0; j < prepayments.length; j++) {
                 BigDecimal prePaymentAmt = convertAmount(
                     new BigDecimal(prepayments[j].prepaidamt).negate(), true, 
DateAcct,
@@ -713,7 +713,7 @@
           } else if 
(!m_payments[i].C_Currency_ID_From.equals(as.m_C_Currency_ID)) {
             try {
               DocInvoiceData[] prepayments = 
DocInvoiceData.selectPrepayments(connectionProvider,
-                  m_payments[i].Line_ID);
+                  m_payments[i].Line_ID, Record_ID);
               for (int j = 0; j < prepayments.length; j++) {
                 BigDecimal prePaymentAmt = convertAmount(new 
BigDecimal(prepayments[j].prepaidamt),
                     false, DateAcct, TABLEID_Payment, 
prepayments[j].finPaymentId,
@@ -1019,7 +1019,7 @@
           } else if 
(!m_payments[i].C_Currency_ID_From.equals(as.m_C_Currency_ID)) {
             try {
               DocInvoiceData[] prepayments = 
DocInvoiceData.selectPrepayments(connectionProvider,
-                  m_payments[i].Line_ID);
+                  m_payments[i].Line_ID, Record_ID);
               for (int j = 0; j < prepayments.length; j++) {
                 BigDecimal prePaymentAmt = convertAmount(
                     new BigDecimal(prepayments[j].prepaidamt).negate(), false, 
DateAcct,
diff -r eb8ad8b3ea7d -r 165f2247f1d0 
src/org/openbravo/erpCommon/ad_forms/DocInvoice_data.xsql
--- a/src/org/openbravo/erpCommon/ad_forms/DocInvoice_data.xsql Mon Jan 18 
15:27:35 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocInvoice_data.xsql Thu Jan 14 
18:16:17 2016 +0100
@@ -12,7 +12,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-2015 Openbravo S.L.U.
+ * Contributions are Copyright (C) 2001-2016 Openbravo S.L.U.
  ******************************************************************************
 -->
 
@@ -98,16 +98,19 @@
     <SqlMethodComment></SqlMethodComment>
     <Sql>
       <![CDATA[
-    SELECT FIN_PAYMENT_SCHEDULEDETAIL.AMOUNT AS PREPAIDAMT, 
FIN_PAYMENT_DETAIL.FIN_PAYMENT_ID
-    FROM FIN_PAYMENT_SCHEDULE 
-    LEFT JOIN FIN_PAYMENT_SCHEDULEDETAIL ON 
FIN_PAYMENT_SCHEDULE.FIN_PAYMENT_SCHEDULE_ID = 
FIN_PAYMENT_SCHEDULEDETAIL.FIN_PAYMENT_SCHEDULE_ORDER
-    LEFT JOIN FIN_PAYMENT_DETAIL ON 
FIN_PAYMENT_SCHEDULEDETAIL.FIN_PAYMENT_DETAIL_ID = 
FIN_PAYMENT_DETAIL.FIN_PAYMENT_DETAIL_ID
-    WHERE COALESCE(FIN_PAYMENT_DETAIL.ISPREPAYMENT,'N') = 'Y'
-    AND FIN_PAYMENT_SCHEDULEDETAIL.ISCANCELED = 'N'
-    AND FIN_PAYMENT_SCHEDULE.FIN_PAYMENT_SCHEDULE_ID = ?
+    SELECT PSDO.AMOUNT AS PREPAIDAMT, PD.FIN_PAYMENT_ID
+    FROM FIN_PAYMENT_SCHEDULE FPSO
+    INNER JOIN FIN_PAYMENT_SCHEDULEDETAIL PSDO ON FPSO.FIN_PAYMENT_SCHEDULE_ID 
= PSDO.FIN_PAYMENT_SCHEDULE_ORDER
+    INNER JOIN FIN_PAYMENT_SCHEDULE FPSI ON PSDO.FIN_PAYMENT_SCHEDULE_INVOICE 
= FPSI.FIN_PAYMENT_SCHEDULE_ID
+    INNER JOIN FIN_PAYMENT_DETAIL PD ON PSDO.FIN_PAYMENT_DETAIL_ID = 
PD.FIN_PAYMENT_DETAIL_ID
+    WHERE COALESCE(PD.ISPREPAYMENT,'N') = 'Y'
+    AND PSDO.ISCANCELED = 'N'
+    AND FPSO.FIN_PAYMENT_SCHEDULE_ID = ?
+    AND FPSI.C_INVOICE_ID = ?
      ]]>
      </Sql>
      <Parameter name="paymentSchedule"/>
+     <Parameter name="invoiceId"/>
    </SqlMethod>    
    <SqlMethod name="selectProductAcct" type="preparedStatement" 
return="multiple">
     <SqlMethodComment></SqlMethodComment>

------------------------------------------------------------------------------
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=267308311&iu=/4140
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to