Fixed bug 29145: Used credit is not correct under certain circumstances
authorSandra Huguet <sandra.huguet@openbravo.com>
Tue, 17 Mar 2015 17:53:05 +0100
changeset 26196 fb806ae22a47
parent 26195 0a80ccfcebd0
child 26197 2e3cf56c8f15
child 26198 7c384195efac
Fixed bug 29145: Used credit is not correct under certain circumstances
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MESSAGE.xml
modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MESSAGE.xml	Mon Mar 16 22:52:31 2015 +0000
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MESSAGE.xml	Tue Mar 17 17:53:05 2015 +0100
@@ -1489,6 +1489,18 @@
 <!--F4500597D99243129F93A0769047CFCB-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--F4500597D99243129F93A0769047CFCB--></AD_MESSAGE>
 
+<!--F482DF98F6FF45728419D116A7726765--><AD_MESSAGE>
+<!--F482DF98F6FF45728419D116A7726765-->  <AD_MESSAGE_ID><![CDATA[F482DF98F6FF45728419D116A7726765]]></AD_MESSAGE_ID>
+<!--F482DF98F6FF45728419D116A7726765-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--F482DF98F6FF45728419D116A7726765-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--F482DF98F6FF45728419D116A7726765-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--F482DF98F6FF45728419D116A7726765-->  <VALUE><![CDATA[APRM_MORECREDITAMOUNT]]></VALUE>
+<!--F482DF98F6FF45728419D116A7726765-->  <MSGTEXT><![CDATA[Credit amount should not be greater than total amount]]></MSGTEXT>
+<!--F482DF98F6FF45728419D116A7726765-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--F482DF98F6FF45728419D116A7726765-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--F482DF98F6FF45728419D116A7726765-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--F482DF98F6FF45728419D116A7726765--></AD_MESSAGE>
+
 <!--F579E42461DC472AA4F21B14DD3D680B--><AD_MESSAGE>
 <!--F579E42461DC472AA4F21B14DD3D680B-->  <AD_MESSAGE_ID><![CDATA[F579E42461DC472AA4F21B14DD3D680B]]></AD_MESSAGE_ID>
 <!--F579E42461DC472AA4F21B14DD3D680B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Mon Mar 16 22:52:31 2015 +0000
+++ b/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Tue Mar 17 17:53:05 2015 +0100
@@ -813,8 +813,21 @@
 };
 
 OB.APRM.AddPayment.doSelectionChangedCredit = function (record, state, view) {
+  var issotrx = view.theForm.getItem('issotrx'),
+      grid = view.theForm.getItem('credit_to_use').canvas.viewGrid,
+      amountField = grid.getFieldByColumnName('paymentAmount'),
+      outstanding = new BigDecimal(String(record.outstandingAmount));
+
+  if (state) {
+    grid.setEditValue(grid.getRecordIndex(record), amountField, Number(outstanding));
+  } else {
+    grid.setEditValue(grid.getRecordIndex(record), amountField, '0');
+  }
   OB.APRM.AddPayment.updateCreditTotal(view.theForm);
   OB.APRM.AddPayment.updateActualExpected(view.theForm);
+  if (issotrx) {
+    OB.APRM.AddPayment.distributeAmount(view, view.theForm, true);
+  }
 };
 
 OB.APRM.AddPayment.conversionRateOnChange = function (item, view, form, grid) {
@@ -1103,6 +1116,11 @@
     return false;
   }
 
+  if ((total.compareTo(creditTotalItem) < 0) && (overpaymentAction === 'CR')) {
+    view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, null, OB.I18N.getLabel('APRM_MORECREDITAMOUNT'));
+    return false;
+  }
+
   if (document !== null && document !== '' && actualPayment.compareTo(BigDecimal.prototype.ZERO) === 0 && view.parentWindow && view.parentWindow.windowId) {
     view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, null, OB.I18N.getLabel('APRM_ZEROAMOUNTPAYMENTTRANSACTION'));
     return false;