details:   https://code.openbravo.com/erp/devel/pi/rev/bbec1f5c7300
changeset: 33884:bbec1f5c7300
user:      Armaignac <collazoandy4 <at> gmail.com>
date:      Tue Apr 10 17:12:31 2018 -0400
summary:   Fixes issue 38288: Sales Invoice Payment Plan Due date can be 
modified when
related payment is in Remitted status

Remittances only accept documents with due date prior to their expected date,
the due date of a payment plan can be increased because the process doesn't
properly check the that condition

A new hook is created to check the edited payment schedule lines and avoid 
validation
issues

details:   https://code.openbravo.com/erp/devel/pi/rev/f3cb10dc3207
changeset: 33885:f3cb10dc3207
user:      David Miguelez <david.miguelez <at> openbravo.com>
date:      Mon Apr 23 09:17:37 2018 +0200
summary:   Related to Issue 38288. Code review changes

* Moved validation of Payment Plan before performing any logic
* Changed logic to retrieve messages, it now usses API from OBMessageUtils

diffstat:

 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ModifyPaymentPlanHook.java
                        |  44 ++++++++
 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ModifyPaymentPlanActionHandler.java
 |  49 ++++++---
 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ModifyPaymentPlanHookCaller.java
    |  45 +++++++++
 3 files changed, 119 insertions(+), 19 deletions(-)

diffs (244 lines):

diff -r bc87a9f043b8 -r f3cb10dc3207 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ModifyPaymentPlanHook.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ModifyPaymentPlanHook.java
  Mon Apr 23 09:17:37 2018 +0200
@@ -0,0 +1,44 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2018 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  
+ *************************************************************************
+ */
+package org.openbravo.advpaymentmngt;
+
+import java.util.List;
+
+import org.openbravo.base.exception.OBException;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
+
+/***
+ * Abstract class created to implement hooks inside Modify Payment Plan 
process. All hooks in that
+ * process must extend this class so they implement the methods
+ * 
+ * @author Andy Armaignac Collazo
+ *
+ */
+public abstract class ModifyPaymentPlanHook {
+
+  /***
+   * Method to validate the modified payment schedule
+   * 
+   * @param modifiedPaymentSchedule
+   * 
+   * @throws OBException
+   */
+  public abstract void validatePaymentSchedule(List<FIN_PaymentSchedule> 
modifiedPaymentSchedule)
+      throws OBException;
+}
diff -r bc87a9f043b8 -r f3cb10dc3207 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ModifyPaymentPlanActionHandler.java
--- 
a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ModifyPaymentPlanActionHandler.java
   Fri Apr 27 09:53:25 2018 +0200
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ModifyPaymentPlanActionHandler.java
   Mon Apr 23 09:17:37 2018 +0200
@@ -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) 2012-2017 Openbravo SLU
+ * All portions are Copyright (C) 2012-2018 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -36,14 +36,13 @@
 import org.hibernate.exception.ConstraintViolationException;
 import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
 import org.openbravo.advpaymentmngt.process.FIN_PaymentMonitorProcess;
-import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.base.weld.WeldUtils;
 import org.openbravo.client.application.ApplicationConstants;
 import org.openbravo.client.application.process.BaseProcessActionHandler;
 import org.openbravo.client.kernel.KernelUtils;
-import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
-import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.erpCommon.utility.OBMessageUtils;
 import org.openbravo.model.ad.ui.Field;
 import org.openbravo.model.common.invoice.Invoice;
 import org.openbravo.model.financialmgmt.payment.FIN_Payment;
@@ -51,7 +50,6 @@
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
-import org.openbravo.service.db.DalConnectionProvider;
 import org.openbravo.service.json.JsonToDataConverter;
 
 public class ModifyPaymentPlanActionHandler extends BaseProcessActionHandler {
@@ -81,7 +79,7 @@
 
       // TODO:Review if we should allow this option
       // if (paidAnyAmount(invoice)) {
-      // return addMessage(jsonRequest, "@APRM_AlreadyPaidInvoice@", "error");
+      // return addMessage(jsonRequest, "APRM_AlreadyPaidInvoice", "error");
       // }
 
       String errorMsg = validateGridAmounts(gridRows, invoice);
@@ -91,7 +89,7 @@
       }
       if (!validateInvoiceAmounts(invoice)) {
         OBDal.getInstance().rollbackAndClose();
-        return addMessage(jsonRequest, "@APRM_ExistingPlanIsNotCorrect@", 
"error");
+        return addMessage(jsonRequest, "APRM_ExistingPlanIsNotCorrect", 
"error");
       }
 
       List<JSONObject> lToCreate = getNewRows(gridRows);
@@ -101,6 +99,9 @@
       HashMap<FIN_PaymentSchedule, BigDecimal> orders = getOrders(lToRemove, 
lToModify);
       HashMap<FIN_PaymentDetail, BigDecimal> canceledPSDs = 
getCanceledPSDs(lToRemove, lToModify);
 
+      
WeldUtils.getInstanceFromStaticBeanManager(ModifyPaymentPlanHookCaller.class)
+          .validatePaymentSchedule(lToModify);
+
       removeRows(lToRemove, invoice);
       List<FIN_PaymentSchedule> createdPSs = createRows(lToCreate, invoice);
       createdPSs = modifyRows(lToModify, gridRows, invoice, createdPSs);
@@ -109,16 +110,17 @@
 
       if (!ordersSumsZero(orders, invoice.getFINPaymentScheduleList().get(0))) 
{
         OBDal.getInstance().rollbackAndClose();
-        return addMessage(jsonRequest, "@APRM_AmountNotFullyAllocated@", 
"error");
+        return addMessage(jsonRequest, "APRM_AmountNotFullyAllocated", 
"error");
       }
 
       if (!validateInvoiceAmounts(invoice)) {
         OBDal.getInstance().rollbackAndClose();
-        return addMessage(jsonRequest, "@APRM_AmountMismatch@", "error");
+        return addMessage(jsonRequest, "APRM_AmountMismatch", "error");
       }
+
       // As a final step, Payment Monitor information for this invoice is 
updated.
       FIN_PaymentMonitorProcess.updateInvoice(invoice);
-      return addMessage(jsonRequest, "@Success@", "success");
+      return addMessage(jsonRequest, "Success", "success");
     } catch (ConstraintViolationException e) {
       OBDal.getInstance().rollbackAndClose();
       log4j.error("Exception! " + e);
@@ -134,7 +136,7 @@
         }
       }
       try {
-        return addMessage(jsonRequest, "@" + constraint + "@", "error");
+        return addMessage(jsonRequest, constraint, "error");
       } catch (Exception ex) {
         log4j.error("Exception! " + ex);
         return jsonRequest;
@@ -143,7 +145,7 @@
       OBDal.getInstance().rollbackAndClose();
       log4j.error("Exception! " + e);
       try {
-        return addMessage(jsonRequest, "@ProcessRunError@", "error");
+        return addMessage(jsonRequest, "ProcessRunError", e.getMessage(), 
"error");
       } catch (Exception ex) {
         log4j.error("Exception! " + ex);
         return jsonRequest;
@@ -634,14 +636,23 @@
    */
   private JSONObject addMessage(JSONObject content, String strMessage, String 
strSeverity)
       throws JSONException {
+    return addMessage(content, "", strMessage, strSeverity);
+  }
+
+  /**
+   * Given a JSONObject to be returned, it adds a message to it
+   * 
+   * @throws JSONException
+   */
+  private JSONObject addMessage(JSONObject content, String strTitle, String 
strMessage,
+      String strSeverity) throws JSONException {
     JSONObject outPut = content;
     JSONObject message = new JSONObject();
     message.put("severity", strSeverity);
-    message.put("text", Utility.parseTranslation(new DalConnectionProvider(),
-        new VariablesSecureApp(OBContext.getOBContext().getUser().getId(), 
OBContext.getOBContext()
-            .getCurrentClient().getId(), 
OBContext.getOBContext().getCurrentOrganization().getId(),
-            OBContext.getOBContext().getRole().getId()), 
OBContext.getOBContext().getLanguage()
-            .getLanguage(), strMessage));
+    if (!StringUtils.isEmpty(strTitle)) {
+      message.put("title", OBMessageUtils.messageBD(strTitle));
+    }
+    message.put("text", OBMessageUtils.messageBD(strMessage));
     outPut.put("message", message);
     return outPut;
   }
@@ -688,11 +699,11 @@
       BigDecimal outstanding = new BigDecimal(jo.getString("outstanding"));
       BigDecimal awaitingExecution = new 
BigDecimal(jo.getString("awaitingExecutionAmount"));
       if (awaitingExecution.abs().compareTo(outstanding.abs()) > 0) {
-        return "@APRM_AwaitingExecutionAmountError@";
+        return "APRM_AwaitingExecutionAmountError";
       }
       if (outstanding.compareTo(BigDecimal.ZERO) != 0
           && (positive != (outstanding.compareTo(BigDecimal.ZERO) > 0))) {
-        return "@APRM_DifferentSignError@";
+        return "APRM_DifferentSignError";
       }
     }
     return null;
diff -r bc87a9f043b8 -r f3cb10dc3207 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ModifyPaymentPlanHookCaller.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/ModifyPaymentPlanHookCaller.java
      Mon Apr 23 09:17:37 2018 +0200
@@ -0,0 +1,45 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2018 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.advpaymentmngt.actionHandler;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import org.openbravo.advpaymentmngt.ModifyPaymentPlanHook;
+import org.openbravo.base.exception.OBException;
+import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
+
+public class ModifyPaymentPlanHookCaller {
+
+  @Inject
+  @Any
+  private Instance<ModifyPaymentPlanHook> hooks;
+
+  public void validatePaymentSchedule(List<FIN_PaymentSchedule> 
modifiedPaymentSchedule)
+      throws OBException {
+    for (Iterator<ModifyPaymentPlanHook> procIter = hooks.iterator(); 
procIter.hasNext();) {
+      ModifyPaymentPlanHook proc = procIter.next();
+      proc.validatePaymentSchedule(modifiedPaymentSchedule);
+    }
+  }
+}

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to