IDEMPIERE-5575 - Period Controll, new option - Period Document Close (#1676)

* IDEMPIERE-5575 - Period Controll, new option - Period Document Close

* IDEMPIERE-5575 - patch pr1676
This commit is contained in:
Peter Takács 2023-02-15 15:37:28 +01:00 committed by GitHub
parent dff85c45de
commit 883edf8436
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 103 additions and 16 deletions

View File

@ -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')
;

View File

@ -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')
;

View File

@ -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);

View File

@ -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;

View File

@ -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
{

View File

@ -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)
@ -271,6 +271,20 @@ public class MPeriod extends X_C_Period implements ImmutablePOSupport
* @return true if open
*/
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) {
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":
* <li>if not null, date should be in auto period range (today - OpenHistory, today+OpenHistory)
* <li>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
/**

View File

@ -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,9 +128,22 @@ 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

View File

@ -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";
/** &lt;No Action&gt; = 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 */

View File

@ -1322,7 +1322,7 @@ public class WAcctViewer extends Window implements EventListener<Event>
&& 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;
}