Fixes issue 41937: Take into account total paid when calculating the outstanding
authorMark Molina <mark.molina@doceleguas.com>
Mon, 07 Oct 2019 20:32:06 -0300
changeset 36569 96529e99687a
parent 36565 921035308d38
child 36570 23a72ef4e19b
Fixes issue 41937: Take into account total paid when calculating the outstanding
amount of lines when using the Modify Payment Plan feature.

In some cases, using the Modify Payment Plan feature was shoing that the Outstanding Amount
was invalid because the total invoice amount was considered when validating the Outstanding Amount
but wasn't taking into account the other payment plans already paid.
The issue on this situation was to to get the received amount from records shown in
the grid, as those lines already paid are not shown in the pop up grid, the amount
don'tr match and an error is shown to the user.

To fix this issue is validated that the total Outstanding amount is exactly the difference
between the invoice grand total and the total invoice amount already paid
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	Fri Sep 27 12:24:15 2019 +0000
+++ b/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-utilities.js	Mon Oct 07 20:32:06 2019 -0300
@@ -73,26 +73,15 @@
     totalReceived = new BigDecimal('0'),
     totalOutstanding = new BigDecimal('0'),
     isNumber = isc.isA.Number,
-    invoiceOutstanding = new BigDecimal(
-      String(
-        item.grid.view.parentWindow.activeView.getContextInfo(
-          false,
-          true,
-          true,
-          false
-        ).inpoutstandingamt
-      )
+    contextInfo = item.grid.view.parentWindow.activeView.getContextInfo(
+      false,
+      true,
+      true,
+      false
     ),
-    invoiceGrandTotal = new BigDecimal(
-      String(
-        item.grid.view.parentWindow.activeView.getContextInfo(
-          false,
-          true,
-          true,
-          false
-        ).inpgrandtotal
-      )
-    );
+    invoiceOutstanding = new BigDecimal(String(contextInfo.inpoutstandingamt)),
+    invoiceGrandTotal = new BigDecimal(String(contextInfo.inpgrandtotal)),
+    invoicePaidTotal = new BigDecimal(String(contextInfo.inptotalpaid));
 
   if (
     new BigDecimal(String(value)).compareTo(new BigDecimal('0')) !== 0 &&
@@ -125,9 +114,8 @@
   }
   if (
     totalOutstanding
-      .add(totalReceived)
       .abs()
-      .compareTo(invoiceGrandTotal.abs()) !== 0
+      .compareTo(invoiceGrandTotal.subtract(invoicePaidTotal).abs()) !== 0
   ) {
     return false;
   }