details:   https://code.openbravo.com/erp/devel/pi/rev/c11d43f00ade
changeset: 35672:c11d43f00ade
user:      Nono Carballo <nonofce <at> gmail.com>
date:      Mon Apr 15 12:37:16 2019 +0200
summary:   Fixes issue 40519: Prevents post CostAdjustment with closed periods

For CostAdjustments, the accounting date is a property of CostAdjustmentLines,
the date considered to get the period is the reference date of the document,
causing a CostAdjustment with reference date in an open period can be posted
even when there are lines with accounting date in a closed period.

This fix prevents a CostAdjustment to be posted if there is at least one line
with accounting date in a closed period.

details:   https://code.openbravo.com/erp/devel/pi/rev/68baacc03b4a
changeset: 35673:68baacc03b4a
user:      Sandra Huguet <sandra.huguet <at> openbravo.com>
date:      Mon Apr 15 17:58:20 2019 +0200
summary:   related to issue 40519 code review changes

diffstat:

 src/org/openbravo/erpCommon/ad_forms/DocCostAdjustment.java |  38 ++++++++++++-
 1 files changed, 37 insertions(+), 1 deletions(-)

diffs (67 lines):

diff -r d91acd577d96 -r 68baacc03b4a 
src/org/openbravo/erpCommon/ad_forms/DocCostAdjustment.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocCostAdjustment.java       Wed Apr 
17 09:51:44 2019 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocCostAdjustment.java       Mon Apr 
15 17:58:20 2019 +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) 2014-2018 Openbravo SLU
+ * All portions are Copyright (C) 2014-2019 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -27,11 +27,16 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+import org.openbravo.advpaymentmngt.utility.FIN_Utility;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBQuery;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.database.ConnectionProvider;
+import org.openbravo.erpCommon.utility.OBDateUtils;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
 import org.openbravo.erpCommon.utility.SequenceIdData;
+import org.openbravo.model.materialmgmt.cost.CostAdjustmentLine;
 
 public class DocCostAdjustment extends AcctServer {
 
@@ -511,6 +516,37 @@
 
   }
 
+  /**
+   * Set the period for the Cost Adjustment considering if all the periods 
matching accounting dates
+   * in Cost Adjustment Lines are opened
+   */
+  @Override
+  public void setC_Period_ID() {
+    if (C_Period_ID != null) {
+      return;
+    }
+    if (areAllPeriodsOpened(Record_ID, DocumentType)) {
+      super.setC_Period_ID();
+    } else {
+      C_Period_ID = "";
+    }
+  }
+
+  private boolean areAllPeriodsOpened(final String record_ID, final String 
documentType) {
+    String whereClause = "costAdjustment.id = :record_ID";
+    OBQuery<CostAdjustmentLine> costAdjLineQry = OBDal.getInstance()
+        .createQuery(CostAdjustmentLine.class, whereClause);
+    costAdjLineQry.setNamedParameter("record_ID", record_ID);
+    for (CostAdjustmentLine costAdjustmentLine : costAdjLineQry.list()) {
+      if (!FIN_Utility.isPeriodOpen(costAdjustmentLine.getClient().getId(), 
documentType,
+          costAdjustmentLine.getOrganization().getId(),
+          OBDateUtils.formatDate(costAdjustmentLine.getAccountingDate()))) {
+        return false;
+      }
+    }
+    return true;
+  }
+
   @Override
   public String getServletInfo() {
     return "Servlet for the accounting";


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

Reply via email to