details:   https://code.openbravo.com/erp/devel/pi/rev/a121302dfba6
changeset: 35559:a121302dfba6
user:      Mark Molina <mark.molina <at> doceleguas.com>
date:      Mon Mar 18 18:27:33 2019 -0300
summary:   Fixes issue 40392: Can't modify an invoice payment plan if it's 
already modified

This solution takes into account all the Payment Plan lines when calculating 
that
modified outstanding amounts are modified.
Also, all the payment plan expected amounts are updated if the sum of the 
updated
outstandings amounts are equals than original outstanding amount of the invoice 
instead
of just update the last record.

Also when a new record is added are taken into account all the lines and the new
outstanding amount is calculated by subtract to the total expected the total 
already paid
and the total outstanding in the existing lines.

diffstat:

 
modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-utilities.js
 |  21 ++++++---
 1 files changed, 14 insertions(+), 7 deletions(-)

diffs (51 lines):

diff -r a0588dfa7203 -r a121302dfba6 
modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-utilities.js
--- 
a/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-utilities.js
     Mon Mar 25 16:38:38 2019 +0100
+++ 
b/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-utilities.js
     Mon Mar 18 18:27:33 2019 -0300
@@ -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) 2011-2015 Openbravo SLU
+ * All portions are Copyright (C) 2011-2019 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -73,10 +73,13 @@
     totalOutstanding = totalOutstanding.add(new 
BigDecimal(String(row.outstanding)));
     totalReceived = totalReceived.add(new BigDecimal(String(row.received)));
   }
-  row.expected = Number(new BigDecimal(String(row.outstanding)).add(new 
BigDecimal(String(row.received))));
-  if (totalOutstanding.abs().compareTo(invoiceOutstanding.abs()) !== 0) {
+  if 
(totalOutstanding.abs().compareTo(totalExpected.subtract(totalReceived).abs()) 
!== 0) {
     return false;
   }
+  for (indRow = 0; indRow < allRows.length; indRow++) {
+    row = allRows[indRow];
+    row.expected = Number(new BigDecimal(String(row.outstanding)).add(new 
BigDecimal(String(row.received))));
+  }
   if (new 
BigDecimal(String(record.awaitingExecutionAmount)).abs().compareTo(new 
BigDecimal(String(record.outstanding)).abs()) > 0) {
     if (!OB.APRM.validateMPPUserWarnedAwaiting) {
       OB.APRM.validateMPPUserWarnedAwaiting = true;
@@ -153,14 +156,18 @@
 
 OB.APRM.addNew = function (grid) {
   var selectedRecord = grid.view.parentWindow.views[0].getParentRecord(),
-      allRows = grid.data.allRows || grid.data.localData;
+      allRows = grid.data.allRows || grid.data.localData,
+      totalExpected = new BigDecimal("0"),
+      totalReceived = new BigDecimal("0");
   var returnObject = isc.addProperties({}, allRows[0]);
-  var indRow, row, totalOutstanding = new BigDecimal("0");
+  var indRow, row, totalOutstandingInOthers = new BigDecimal("0");
   for (indRow = 0; indRow < allRows.length; indRow++) {
     row = allRows[indRow];
-    totalOutstanding = totalOutstanding.add(new 
BigDecimal(String(row.outstanding)));
+    totalOutstandingInOthers = totalOutstandingInOthers.add(new 
BigDecimal(String(row.outstanding)));
+    totalExpected = totalExpected.add(new BigDecimal(String(row.expected)));
+    totalReceived = totalReceived.add(new BigDecimal(String(row.received)));
   }
-  returnObject.outstanding = Number(new 
BigDecimal(String(grid.view.parentWindow.activeView.getContextInfo(false, true, 
true, false).inpoutstandingamt)).subtract(totalOutstanding));
+  returnObject.outstanding = 
Number(totalExpected.subtract(totalReceived).subtract(totalOutstandingInOthers));
   returnObject.received = 0;
   returnObject.expected = 0;
   returnObject.awaitingExecutionAmount = 0;


_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to