Fixes issue 41935: Take into account total paid when calculating the outstanding
authorMark Molina <mark.molina@doceleguas.com>
Mon, 07 Oct 2019 19:48:59 -0300
changeset 36620 4c494b46c371
parent 36619 9765dea5db5c
child 36621 fc810b87d8a0
Fixes issue 41935: 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	Wed Oct 09 11:02:13 2019 +0200
+++ b/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-utilities.js	Mon Oct 07 19:48:59 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;
   }