From 883edf8436d5e323167cb15c21af8f34a0b6ff08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Tak=C3=A1cs?= <93127072+PeterTakacs300@users.noreply.github.com> Date: Wed, 15 Feb 2023 15:37:28 +0100 Subject: [PATCH] IDEMPIERE-5575 - Period Controll, new option - Period Document Close (#1676) * IDEMPIERE-5575 - Period Controll, new option - Period Document Close * IDEMPIERE-5575 - patch pr1676 --- .../oracle/202302150816_IDEMPIERE-5575.sql | 14 +++++ .../202302150816_IDEMPIERE-5575.sql | 11 ++++ .../compiere/process/PeriodControlStatus.java | 3 + .../src/org/compiere/acct/Doc.java | 2 +- .../org/compiere/model/I_C_PeriodControl.java | 2 +- .../src/org/compiere/model/MPeriod.java | 57 ++++++++++++++++--- .../org/compiere/model/MPeriodControl.java | 20 +++++-- .../org/compiere/model/X_C_PeriodControl.java | 8 ++- .../org/adempiere/webui/acct/WAcctViewer.java | 2 +- 9 files changed, 103 insertions(+), 16 deletions(-) create mode 100644 migration/iD11/oracle/202302150816_IDEMPIERE-5575.sql create mode 100644 migration/iD11/postgresql/202302150816_IDEMPIERE-5575.sql diff --git a/migration/iD11/oracle/202302150816_IDEMPIERE-5575.sql b/migration/iD11/oracle/202302150816_IDEMPIERE-5575.sql new file mode 100644 index 0000000000..e8a05fc9a4 --- /dev/null +++ b/migration/iD11/oracle/202302150816_IDEMPIERE-5575.sql @@ -0,0 +1,14 @@ +-- IDEMPIERE-5575 +SELECT register_migration_script('202302150816_IDEMPIERE-5575.sql') FROM dual; + +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Feb 15, 2023, 8:16:38 AM CET +INSERT INTO AD_Ref_List (AD_Ref_List_ID,Name,AD_Reference_ID,Value,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,EntityType,AD_Ref_List_UU) VALUES (200628,'Document closed',177,'D',0,0,'Y',TO_TIMESTAMP('2023-02-15 08:16:38','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-02-15 08:16:38','YYYY-MM-DD HH24:MI:SS'),100,'D','948b0299-f812-4fc7-92b8-9063f7deae6d') +; + +-- Feb 15, 2023, 8:26:25 AM CET +INSERT INTO AD_Ref_List (AD_Ref_List_ID,Name,AD_Reference_ID,Value,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,EntityType,AD_Ref_List_UU) VALUES (200629,'Document Close Period',176,'D',0,0,'Y',TO_TIMESTAMP('2023-02-15 08:26:25','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-02-15 08:26:25','YYYY-MM-DD HH24:MI:SS'),100,'D','115de309-7e7b-42a0-873b-7acf400d3ac3') +; + diff --git a/migration/iD11/postgresql/202302150816_IDEMPIERE-5575.sql b/migration/iD11/postgresql/202302150816_IDEMPIERE-5575.sql new file mode 100644 index 0000000000..b60c001b7e --- /dev/null +++ b/migration/iD11/postgresql/202302150816_IDEMPIERE-5575.sql @@ -0,0 +1,11 @@ +-- IDEMPIERE-5575 +SELECT register_migration_script('202302150816_IDEMPIERE-5575.sql') FROM dual; + +-- Feb 15, 2023, 8:16:38 AM CET +INSERT INTO AD_Ref_List (AD_Ref_List_ID,Name,AD_Reference_ID,Value,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,EntityType,AD_Ref_List_UU) VALUES (200628,'Document closed',177,'D',0,0,'Y',TO_TIMESTAMP('2023-02-15 08:16:38','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-02-15 08:16:38','YYYY-MM-DD HH24:MI:SS'),100,'D','948b0299-f812-4fc7-92b8-9063f7deae6d') +; + +-- Feb 15, 2023, 8:26:25 AM CET +INSERT INTO AD_Ref_List (AD_Ref_List_ID,Name,AD_Reference_ID,Value,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,EntityType,AD_Ref_List_UU) VALUES (200629,'Document Close Period',176,'D',0,0,'Y',TO_TIMESTAMP('2023-02-15 08:26:25','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-02-15 08:26:25','YYYY-MM-DD HH24:MI:SS'),100,'D','115de309-7e7b-42a0-873b-7acf400d3ac3') +; + diff --git a/org.adempiere.base.process/src/org/compiere/process/PeriodControlStatus.java b/org.adempiere.base.process/src/org/compiere/process/PeriodControlStatus.java index cdd6d68ced..ee16c13082 100644 --- a/org.adempiere.base.process/src/org/compiere/process/PeriodControlStatus.java +++ b/org.adempiere.base.process/src/org/compiere/process/PeriodControlStatus.java @@ -83,6 +83,9 @@ public class PeriodControlStatus extends SvrProcess // Open if (MPeriodControl.PERIODACTION_OpenPeriod.equals(pc.getPeriodAction())) pc.setPeriodStatus(MPeriodControl.PERIODSTATUS_Open); + // Document Close + if (MPeriodControl.PERIODACTION_DocumentClosePeriod.equals(pc.getPeriodAction())) + pc.setPeriodStatus(MPeriodControl.PERIODSTATUS_DocumentClosed); // Close if (MPeriodControl.PERIODACTION_ClosePeriod.equals(pc.getPeriodAction())) pc.setPeriodStatus(MPeriodControl.PERIODSTATUS_Closed); diff --git a/org.adempiere.base/src/org/compiere/acct/Doc.java b/org.adempiere.base/src/org/compiere/acct/Doc.java index 945835419f..f34831423a 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc.java @@ -1105,7 +1105,7 @@ public abstract class Doc m_period = MPeriod.get(getCtx(), getDateAcct(), getAD_Org_ID(), (String)null); // Is Period Open? if (m_period != null - && m_period.isOpen(getDocumentType(), getDateAcct())) + && m_period.isOpen(getDocumentType(), getDateAcct(), true)) m_C_Period_ID = m_period.getC_Period_ID(); else m_C_Period_ID = -1; diff --git a/org.adempiere.base/src/org/compiere/model/I_C_PeriodControl.java b/org.adempiere.base/src/org/compiere/model/I_C_PeriodControl.java index 5a1f8dc425..e92ec05ac1 100644 --- a/org.adempiere.base/src/org/compiere/model/I_C_PeriodControl.java +++ b/org.adempiere.base/src/org/compiere/model/I_C_PeriodControl.java @@ -22,7 +22,7 @@ import org.compiere.util.KeyNamePair; /** Generated Interface for C_PeriodControl * @author iDempiere (generated) - * @version Release 10 + * @version Release 11 */ public interface I_C_PeriodControl { diff --git a/org.adempiere.base/src/org/compiere/model/MPeriod.java b/org.adempiere.base/src/org/compiere/model/MPeriod.java index 9fad4d6df0..1d701b9c8a 100644 --- a/org.adempiere.base/src/org/compiere/model/MPeriod.java +++ b/org.adempiere.base/src/org/compiere/model/MPeriod.java @@ -56,7 +56,7 @@ public class MPeriod extends X_C_Period implements ImmutablePOSupport /** * */ - private static final long serialVersionUID = -4813116760490243399L; + private static final long serialVersionUID = 3016788523921605808L; /** * Get Period from Cache (immutable) @@ -270,7 +270,21 @@ public class MPeriod extends X_C_Period implements ImmutablePOSupport * @param AD_Org_ID Organization * @return true if open */ - public static boolean isOpen (Properties ctx, Timestamp DateAcct, String DocBaseType, int AD_Org_ID) + public static boolean isOpen(Properties ctx, Timestamp DateAcct, String DocBaseType, int AD_Org_ID) + { + return isOpen(ctx, DateAcct, DocBaseType, AD_Org_ID, false); + } + + /** + * Is standard Period Open for Document Base Type + * @param ctx context + * @param DateAcct date + * @param DocBaseType base type + * @param AD_Org_ID Organization + * @param forPosting - check if the period is open for posting, false is for DocAction + * @return true if open + */ + public static boolean isOpen (Properties ctx, Timestamp DateAcct, String DocBaseType, int AD_Org_ID, boolean forPosting) { if (DateAcct == null) { @@ -288,7 +302,7 @@ public class MPeriod extends X_C_Period implements ImmutablePOSupport s_log.warning("No Period for " + DateAcct + " (" + DocBaseType + ")"); return false; } - boolean open = period.isOpen(DocBaseType, DateAcct); + boolean open = period.isOpen(DocBaseType, DateAcct, forPosting); if (!open) s_log.warning(period.getName() + ": Not open for " + DocBaseType + " (" + DateAcct + ")"); @@ -300,9 +314,23 @@ public class MPeriod extends X_C_Period implements ImmutablePOSupport * @param ctx context * @param tableID * @param recordID + * @param trxName * @return true if open */ - public static boolean isOpen (Properties ctx, int tableID, int recordID, String trxName) { + public static boolean isOpen(Properties ctx, int tableID, int recordID, String trxName) { + return isOpen (ctx, tableID, recordID, trxName, false); + } + + /** + * Is standard Period Open - based on tableID+recordID (for IDEMPIERE-2392) + * @param ctx context + * @param tableID + * @param recordID + * @param trxName + * @param forPosting - check if the period is open for posting, false is for DocAction + * @return true if open + */ + public static boolean isOpen (Properties ctx, int tableID, int recordID, String trxName, boolean forPosting) { MTable table = MTable.get(ctx, tableID); PO po = table.getPO(recordID, trxName); @@ -405,13 +433,13 @@ public class MPeriod extends X_C_Period implements ImmutablePOSupport // special case for journal that has direct period int periodID = po.get_ValueAsInt("C_Period_ID"); MPeriod period = MPeriod.get(ctx, periodID); - boolean open = period.isOpen(docBaseType, dateAcct); + boolean open = period.isOpen(docBaseType, dateAcct, forPosting); if (!open) s_log.warning(period.getName() + ": Not open for " + docBaseType + " (" + dateAcct + ")"); return open; } - return isOpen(ctx, dateAcct, docBaseType, orgID); + return isOpen(ctx, dateAcct, docBaseType, orgID, forPosting); } // isOpen /** @@ -665,6 +693,21 @@ public class MPeriod extends X_C_Period implements ImmutablePOSupport * @since 3.3.1b */ public boolean isOpen (String DocBaseType, Timestamp dateAcct) + { + return isOpen(DocBaseType, dateAcct, false); + } + + /** + * Is Period Open for Doc Base Type + * @param DocBaseType document base type + * @param dateAcct date; + * Applies only for "Auto Period Control": + *
  • if not null, date should be in auto period range (today - OpenHistory, today+OpenHistory) + *
  • if null, this period should be in auto period range + * @param forPosting - check if the period is open for posting, false is for DocAction + * @return true if open + */ + public boolean isOpen (String DocBaseType, Timestamp dateAcct, boolean forPosting) { if (!isActive()) { @@ -724,7 +767,7 @@ public class MPeriod extends X_C_Period implements ImmutablePOSupport return false; } if (log.isLoggable(Level.FINE)) log.fine(getName() + ": " + DocBaseType); - return pc.isOpen(); + return pc.isOpen(forPosting); } // isOpen /** diff --git a/org.adempiere.base/src/org/compiere/model/MPeriodControl.java b/org.adempiere.base/src/org/compiere/model/MPeriodControl.java index 92acce9d0d..97cdfa0b4c 100644 --- a/org.adempiere.base/src/org/compiere/model/MPeriodControl.java +++ b/org.adempiere.base/src/org/compiere/model/MPeriodControl.java @@ -33,8 +33,7 @@ public class MPeriodControl extends X_C_PeriodControl implements ImmutablePOSupp /** * */ - private static final long serialVersionUID = -3743823984541572396L; - + private static final long serialVersionUID = -7818843756246170549L; /** * Standard Constructor @@ -129,10 +128,23 @@ public class MPeriodControl extends X_C_PeriodControl implements ImmutablePOSupp */ public boolean isOpen() { - return PERIODSTATUS_Open.equals(getPeriodStatus()); + return isOpen(false); + } // isOpen + + /** + * Is Period Open + * @param forPosting - check if the period is open for posting, false is for DocAction + * @return true if open + */ + public boolean isOpen(boolean forPosting) + { + if (forPosting) + return PERIODSTATUS_Open.equals(getPeriodStatus()) + || PERIODSTATUS_DocumentClosed.equals(getPeriodStatus()); + else + return PERIODSTATUS_Open.equals(getPeriodStatus()); } // isOpen - /** * String Representation * @return info diff --git a/org.adempiere.base/src/org/compiere/model/X_C_PeriodControl.java b/org.adempiere.base/src/org/compiere/model/X_C_PeriodControl.java index 952b8a8dec..3a8820a01f 100644 --- a/org.adempiere.base/src/org/compiere/model/X_C_PeriodControl.java +++ b/org.adempiere.base/src/org/compiere/model/X_C_PeriodControl.java @@ -23,7 +23,7 @@ import org.compiere.util.KeyNamePair; /** Generated Model for C_PeriodControl * @author iDempiere (generated) - * @version Release 10 - $Id$ */ + * @version Release 11 - $Id$ */ @org.adempiere.base.Model(table="C_PeriodControl") public class X_C_PeriodControl extends PO implements I_C_PeriodControl, I_Persistent { @@ -31,7 +31,7 @@ public class X_C_PeriodControl extends PO implements I_C_PeriodControl, I_Persis /** * */ - private static final long serialVersionUID = 20221224L; + private static final long serialVersionUID = 20230215L; /** Standard Constructor */ public X_C_PeriodControl (Properties ctx, int C_PeriodControl_ID, String trxName) @@ -248,6 +248,8 @@ public class X_C_PeriodControl extends PO implements I_C_PeriodControl, I_Persis public static final int PERIODACTION_AD_Reference_ID=176; /** Close Period = C */ public static final String PERIODACTION_ClosePeriod = "C"; + /** Document Close Period = D */ + public static final String PERIODACTION_DocumentClosePeriod = "D"; /** <No Action> = N */ public static final String PERIODACTION_NoAction = "N"; /** Open Period = O */ @@ -275,6 +277,8 @@ public class X_C_PeriodControl extends PO implements I_C_PeriodControl, I_Persis public static final int PERIODSTATUS_AD_Reference_ID=177; /** Closed = C */ public static final String PERIODSTATUS_Closed = "C"; + /** Document closed = D */ + public static final String PERIODSTATUS_DocumentClosed = "D"; /** Never opened = N */ public static final String PERIODSTATUS_NeverOpened = "N"; /** Open = O */ diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewer.java index e7212091b7..7a3c2a0ecd 100755 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewer.java @@ -1322,7 +1322,7 @@ public class WAcctViewer extends Window implements EventListener && m_data.AD_Table_ID != 0 && m_data.Record_ID != 0) { // IDEMPIERE-2392 - if (! MPeriod.isOpen(Env.getCtx(), m_data.AD_Table_ID, m_data.Record_ID, null)) { + if (! MPeriod.isOpen(Env.getCtx(), m_data.AD_Table_ID, m_data.Record_ID, null, true)) { Dialog.error(0, "Error", Msg.getMsg(Env.getCtx(), "PeriodClosed")); return; }