Fixes Issue 37156, 37219:Cannot unpost a financial account transaction
authorAtul Gaware <atul.gaware@openbravo.com>
Mon, 06 Nov 2017 11:45:05 +0530
changeset 32916 28d8fe1517d7
parent 32915 d0a5ddee9b68
child 32925 bb674eaf41ef
Fixes Issue 37156, 37219:Cannot unpost a financial account transaction
reconciled with a previous period's date: c_period_id is null in
fact_acct

** Use AccDefUtility.getCurrentPeriod to get the perid for
financial account transaction date.
** Removed public getPeriod method.
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/TransactionsDao.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/TransactionsDao.java	Fri Nov 03 11:59:33 2017 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/TransactionsDao.java	Mon Nov 06 11:45:05 2017 +0530
@@ -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) 2010-2016 Openbravo SLU
+ * All portions are Copyright (C) 2010-2017 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -40,12 +40,12 @@
 import org.openbravo.data.FieldProvider;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.ad_forms.AcctServer;
+import org.openbravo.erpCommon.utility.AccDefUtility;
 import org.openbravo.erpCommon.utility.FieldProviderFactory;
 import org.openbravo.erpCommon.utility.OBObjectFieldProvider;
 import org.openbravo.model.ad.datamodel.Table;
 import org.openbravo.model.ad.ui.Tab;
 import org.openbravo.model.financialmgmt.accounting.AccountingFact;
-import org.openbravo.model.financialmgmt.calendar.Period;
 import org.openbravo.model.financialmgmt.payment.FIN_FinaccTransaction;
 import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
 import org.openbravo.model.financialmgmt.payment.FIN_Payment;
@@ -256,22 +256,12 @@
     for (AccountingFact aFact : obcAF.list()) {
       aFact.setAccountingDate(transaction.getTransactionDate());
       aFact.setTransactionDate(transaction.getTransactionDate());
-      aFact.setPeriod(getPeriod(transaction.getTransactionDate()));
+      aFact.setPeriod((AccDefUtility.getCurrentPeriod(transaction.getTransactionDate(),
+          AccDefUtility.getCalendar(transaction.getOrganization()))));
     }
     return;
   }
 
-  public static Period getPeriod(Date date) {
-    Period period = null;
-    OBCriteria<Period> obcPe = OBDal.getInstance().createCriteria(Period.class);
-    obcPe.add(Restrictions.le(Period.PROPERTY_ENDINGDATE, date));
-    obcPe.add(Restrictions.ge(Period.PROPERTY_STARTINGDATE, date));
-    if (obcPe.list() != null && obcPe.list().size() > 0) {
-      period = obcPe.list().get(0);
-    }
-    return period;
-  }
-
   public static List<FIN_FinaccTransaction> getTransactionsToReconciled(
       FIN_FinancialAccount account, Date statementDate, boolean hideAfterDate) {