details:   https://code.openbravo.com/erp/devel/pi/rev/3aae880a7aa2
changeset: 27283:3aae880a7aa2
user:      Atul Gaware <atul.gaware <at> openbravo.com>
date:      Thu Aug 06 16:14:03 2015 +0530
summary:   Fixes Issue 30449:Automatic distribution of the amount in Add 
Details window
cannot be disabled

A preference APRM_AutoDistributeAmt - Add Payment: Automatically distribute
amounts. In disribute amount method before doing auto distribution this
preference is checked. If it is not set or is set as 'Y' then only distribution
of amount will take place else not.

To disable distribute functionality user need to set this preference to 'N'.It
is made available in the property list.

details:   https://code.openbravo.com/erp/devel/pi/rev/134c828d9f0a
changeset: 27284:134c828d9f0a
user:      Víctor Martínez Romanos <victor.martinez <at> openbravo.com>
date:      Fri Aug 07 12:23:06 2015 +0200
summary:   Related to issue 30449: code review improvements
If clause checks autoDistributeAmt is not 'N' to follow same logic as for 
APRM_ShowNoDistributeMsg.
autoDistributeAmt is directly assigned in the variable definition.

diffstat:

 
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_REF_LIST.xml 
               |   12 +
 
modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js
 |  153 +++++----
 2 files changed, 90 insertions(+), 75 deletions(-)

diffs (203 lines):

diff -r f0a956388321 -r 134c828d9f0a 
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_REF_LIST.xml
--- 
a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_REF_LIST.xml
   Wed Aug 05 10:21:32 2015 +0200
+++ 
b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_REF_LIST.xml
   Fri Aug 07 12:23:06 2015 +0200
@@ -343,6 +343,18 @@
 <!--7AC4F4FF644247B7BD320BBF67C4F066-->  <SEQNO><![CDATA[10]]></SEQNO>
 <!--7AC4F4FF644247B7BD320BBF67C4F066--></AD_REF_LIST>
 
+<!--9AE9EBD541F34CC7AC8830B9601C52CB--><AD_REF_LIST>
+<!--9AE9EBD541F34CC7AC8830B9601C52CB-->  
<AD_REF_LIST_ID><![CDATA[9AE9EBD541F34CC7AC8830B9601C52CB]]></AD_REF_LIST_ID>
+<!--9AE9EBD541F34CC7AC8830B9601C52CB-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--9AE9EBD541F34CC7AC8830B9601C52CB-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--9AE9EBD541F34CC7AC8830B9601C52CB-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--9AE9EBD541F34CC7AC8830B9601C52CB-->  
<VALUE><![CDATA[APRM_AutoDistributeAmt]]></VALUE>
+<!--9AE9EBD541F34CC7AC8830B9601C52CB-->  <NAME><![CDATA[Add Payment: 
Automatically distribute amounts]]></NAME>
+<!--9AE9EBD541F34CC7AC8830B9601C52CB-->  <DESCRIPTION><![CDATA[If set as 'N' 
then auto distribution is not done]]></DESCRIPTION>
+<!--9AE9EBD541F34CC7AC8830B9601C52CB-->  
<AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--9AE9EBD541F34CC7AC8830B9601C52CB-->  
<AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--9AE9EBD541F34CC7AC8830B9601C52CB--></AD_REF_LIST>
+
 <!--A29540336120479B825D190E5B51C79E--><AD_REF_LIST>
 <!--A29540336120479B825D190E5B51C79E-->  
<AD_REF_LIST_ID><![CDATA[A29540336120479B825D190E5B51C79E]]></AD_REF_LIST_ID>
 <!--A29540336120479B825D190E5B51C79E-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff -r f0a956388321 -r 134c828d9f0a 
modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js
--- 
a/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js
    Wed Aug 05 10:21:32 2015 +0200
+++ 
b/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js
    Fri Aug 07 12:23:06 2015 +0200
@@ -375,99 +375,102 @@
       glitemamt = new 
BigDecimal(String(form.getItem('amount_gl_items').getValue() || 0)),
       orderInvoiceData = orderInvoice.data.localData,
       total = orderInvoice.data.totalRows,
+      autoDistributeAmt = OB.PropertyStore.get("APRM_AutoDistributeAmt"),
       writeoff, amt, outstandingAmount, i, showMessageProperty, showMessage, 
message;
 
-  if (orderInvoice.data.cachedRows < (orderInvoice.data.totalRows)) {
-    showMessageProperty = OB.PropertyStore.get('APRM_ShowNoDistributeMsg');
-    showMessage = (showMessageProperty !== 'N' && showMessageProperty !== 
'"N"');
-    if (showMessage) {
-      
orderInvoice.contentView.messageBar.setMessage(isc.OBMessageBar.TYPE_INFO, 
'<div><div class="' + OB.Styles.MessageBar.leftMsgContainerStyle + '">' + 
OB.I18N.getLabel('APRM_NoDistributeMsg') + '</div><div class="' + 
OB.Styles.MessageBar.rightMsgContainerStyle + '"><a href="#" class="' + 
OB.Styles.MessageBar.rightMsgTextStyle + '" onclick="' + 'window[\'' + 
orderInvoice.contentView.messageBar.ID + '\'].hide(); 
OB.PropertyStore.set(\'APRM_ShowNoDistributeMsg\', \'N\');">' + 
OB.I18N.getLabel('OBUIAPP_NeverShowMessageAgain') + '</a></div></div>', ' ');
-    }
-    return;
-  } else {
-    // hide the message bar if it is still showing the APRM_NoDistributeMsg 
message and the distribution is about to be done
-    message = orderInvoice.contentView.messageBar.text.contents;
-    if (message.contains(OB.I18N.getLabel('APRM_NoDistributeMsg'))) {
-      orderInvoice.contentView.messageBar.hide();
-    }
-  }
-  // subtract glitem amount
-  amount = amount.subtract(glitemamt);
-  // add credit amount
-  amount = amount.add(creditamt);
-
-  for (i = 0; i < total; i++) {
-    if (isc.isA.Object(orderInvoiceData[i]) && 
!isc.isA.emptyObject(orderInvoiceData[i])) {
-      outstandingAmount = new 
BigDecimal(String(orderInvoiceData[i].outstandingAmount));
-      if (outstandingAmount.signum() < 0) {
-        negativeamt = negativeamt.add(new 
BigDecimal(Math.abs(outstandingAmount).toString()));
+  if (autoDistributeAmt !== 'N' && autoDistributeAmt !== '"N"') {
+    if (orderInvoice.data.cachedRows < (orderInvoice.data.totalRows)) {
+      showMessageProperty = OB.PropertyStore.get('APRM_ShowNoDistributeMsg');
+      showMessage = (showMessageProperty !== 'N' && showMessageProperty !== 
'"N"');
+      if (showMessage) {
+        
orderInvoice.contentView.messageBar.setMessage(isc.OBMessageBar.TYPE_INFO, 
'<div><div class="' + OB.Styles.MessageBar.leftMsgContainerStyle + '">' + 
OB.I18N.getLabel('APRM_NoDistributeMsg') + '</div><div class="' + 
OB.Styles.MessageBar.rightMsgContainerStyle + '"><a href="#" class="' + 
OB.Styles.MessageBar.rightMsgTextStyle + '" onclick="' + 'window[\'' + 
orderInvoice.contentView.messageBar.ID + '\'].hide(); 
OB.PropertyStore.set(\'APRM_ShowNoDistributeMsg\', \'N\');">' + 
OB.I18N.getLabel('OBUIAPP_NeverShowMessageAgain') + '</a></div></div>', ' ');
+      }
+      return;
+    } else {
+      // hide the message bar if it is still showing the APRM_NoDistributeMsg 
message and the distribution is about to be done
+      message = orderInvoice.contentView.messageBar.text.contents;
+      if (message.contains(OB.I18N.getLabel('APRM_NoDistributeMsg'))) {
+        orderInvoice.contentView.messageBar.hide();
       }
     }
-  }
+    // subtract glitem amount
+    amount = amount.subtract(glitemamt);
+    // add credit amount
+    amount = amount.add(creditamt);
 
-  if (amount.compareTo(negativeamt.negate()) > 0 && (onActualPaymentChange || 
payment)) {
-    amount = amount.add(negativeamt);
-  }
+    for (i = 0; i < total; i++) {
+      if (isc.isA.Object(orderInvoiceData[i]) && 
!isc.isA.emptyObject(orderInvoiceData[i])) {
+        outstandingAmount = new 
BigDecimal(String(orderInvoiceData[i].outstandingAmount));
+        if (outstandingAmount.signum() < 0) {
+          negativeamt = negativeamt.add(new 
BigDecimal(Math.abs(outstandingAmount).toString()));
+        }
+      }
+    }
 
-  for (i = 0; i < total; i++) {
-    if (!isc.isA.Object(orderInvoiceData[i]) || 
isc.isA.emptyObject(orderInvoiceData[i])) {
-      continue;
+    if (amount.compareTo(negativeamt.negate()) > 0 && (onActualPaymentChange 
|| payment)) {
+      amount = amount.add(negativeamt);
     }
-    writeoff = orderInvoice.getEditValues(i).writeoff;
-    amt = new BigDecimal(String(orderInvoice.getEditValues(i).amount || 0));
-    if (writeoff === null || writeoff === undefined) {
-      writeoff = orderInvoice.getRecord(i).writeoff;
-      amt = new BigDecimal(String(orderInvoice.getRecord(i).amount || 0));
-    }
-    if (writeoff && issotrx) {
-      amount = amount.subtract(amt);
-      continue;
-    } else {
-      outstandingAmount = new 
BigDecimal(String(orderInvoice.getRecord(i).outstandingAmount));
-      if (payment && !onActualPaymentChange && 
orderInvoice.getRecord(i).obSelected) {
-        outstandingAmount = new 
BigDecimal(String(orderInvoice.getRecord(i).amount));
-      } else if ((outstandingAmount.signum() < 0) && (amount.signum() < 0)) {
-        if (Math.abs(outstandingAmount) > Math.abs(amount)) {
-          differenceamt = outstandingAmount.subtract(amount);
+
+    for (i = 0; i < total; i++) {
+      if (!isc.isA.Object(orderInvoiceData[i]) || 
isc.isA.emptyObject(orderInvoiceData[i])) {
+        continue;
+      }
+      writeoff = orderInvoice.getEditValues(i).writeoff;
+      amt = new BigDecimal(String(orderInvoice.getEditValues(i).amount || 0));
+      if (writeoff === null || writeoff === undefined) {
+        writeoff = orderInvoice.getRecord(i).writeoff;
+        amt = new BigDecimal(String(orderInvoice.getRecord(i).amount || 0));
+      }
+      if (writeoff && issotrx) {
+        amount = amount.subtract(amt);
+        continue;
+      } else {
+        outstandingAmount = new 
BigDecimal(String(orderInvoice.getRecord(i).outstandingAmount));
+        if (payment && !onActualPaymentChange && 
orderInvoice.getRecord(i).obSelected) {
+          outstandingAmount = new 
BigDecimal(String(orderInvoice.getRecord(i).amount));
+        } else if ((outstandingAmount.signum() < 0) && (amount.signum() < 0)) {
+          if (Math.abs(outstandingAmount) > Math.abs(amount)) {
+            differenceamt = outstandingAmount.subtract(amount);
+            outstandingAmount = amount;
+            amount = amount.subtract(differenceamt);
+          }
+        } else if (outstandingAmount.signum() > -1 && amount.signum() > -1 && 
outstandingAmount.compareTo(amount) > 0) {
           outstandingAmount = amount;
-          amount = amount.subtract(differenceamt);
         }
-      } else if (outstandingAmount.signum() > -1 && amount.signum() > -1 && 
outstandingAmount.compareTo(amount) > 0) {
-        outstandingAmount = amount;
-      }
-      // do not distribute again when the selectionChanged method is invoked
-      orderInvoice.preventDistributingOnSelectionChanged = true;
-      if (amount.signum() === 0) {
-        if (outstandingAmount.signum() < 0 && (onActualPaymentChange || 
payment)) {
+        // do not distribute again when the selectionChanged method is invoked
+        orderInvoice.preventDistributingOnSelectionChanged = true;
+        if (amount.signum() === 0) {
+          if (outstandingAmount.signum() < 0 && (onActualPaymentChange || 
payment)) {
+            orderInvoice.setEditValue((i), 'amount', 
Number(outstandingAmount.toString()));
+            orderInvoice.selectRecord(i);
+          } else {
+            orderInvoice.setEditValue((i), 'amount', Number('0'));
+            orderInvoice.deselectRecord(i);
+          }
+        } else if (amount.signum() === 1) {
           orderInvoice.setEditValue((i), 'amount', 
Number(outstandingAmount.toString()));
           orderInvoice.selectRecord(i);
-        } else {
-          orderInvoice.setEditValue((i), 'amount', Number('0'));
-          orderInvoice.deselectRecord(i);
-        }
-      } else if (amount.signum() === 1) {
-        orderInvoice.setEditValue((i), 'amount', 
Number(outstandingAmount.toString()));
-        orderInvoice.selectRecord(i);
-        if (outstandingAmount.signum() >= 0 || amount.signum() <= 0) {
-          amount = amount.subtract(outstandingAmount);
-        }
-      } else {
-        if (outstandingAmount.signum() < 0) {
-          orderInvoice.setEditValue((i), 'amount', 
Number(outstandingAmount.toString()));
-          orderInvoice.selectRecord(i);
-          if (outstandingAmount.signum() <= 0 || amount.signum() <= 0) {
+          if (outstandingAmount.signum() >= 0 || amount.signum() <= 0) {
             amount = amount.subtract(outstandingAmount);
           }
         } else {
-          orderInvoice.setEditValue((i), 'amount', Number('0'));
-          orderInvoice.deselectRecord(i);
+          if (outstandingAmount.signum() < 0) {
+            orderInvoice.setEditValue((i), 'amount', 
Number(outstandingAmount.toString()));
+            orderInvoice.selectRecord(i);
+            if (outstandingAmount.signum() <= 0 || amount.signum() <= 0) {
+              amount = amount.subtract(outstandingAmount);
+            }
+          } else {
+            orderInvoice.setEditValue((i), 'amount', Number('0'));
+            orderInvoice.deselectRecord(i);
+          }
         }
+        delete orderInvoice.preventDistributingOnSelectionChanged;
       }
-      delete orderInvoice.preventDistributingOnSelectionChanged;
     }
+    OB.APRM.AddPayment.updateActualExpected(form);
+    OB.APRM.AddPayment.updateInvOrderTotal(form, orderInvoice);
   }
-  OB.APRM.AddPayment.updateActualExpected(form);
-  OB.APRM.AddPayment.updateInvOrderTotal(form, orderInvoice);
 };
 
 OB.APRM.AddPayment.updateTotal = function (form) {

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

Reply via email to