From 0a5309d390efdf3fb5add590fdf1595750dfd899 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 25 Jan 2014 14:46:01 -0500 Subject: [PATCH] IDEMPIERE-452 Control dates / based on patch from Nicolas Micoud (nmicoud) --- .../oracle/201401251441_IDEMPIERE-452.sql | 23 ++++++++ .../postgresql/201401251441_IDEMPIERE-452.sql | 20 +++++++ .../src/org/compiere/model/CalloutEngine.java | 53 ++++++++++++++++++- 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 migration/i2.0z/oracle/201401251441_IDEMPIERE-452.sql create mode 100644 migration/i2.0z/postgresql/201401251441_IDEMPIERE-452.sql diff --git a/migration/i2.0z/oracle/201401251441_IDEMPIERE-452.sql b/migration/i2.0z/oracle/201401251441_IDEMPIERE-452.sql new file mode 100644 index 0000000000..aae364ca78 --- /dev/null +++ b/migration/i2.0z/oracle/201401251441_IDEMPIERE-452.sql @@ -0,0 +1,23 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Jan 25, 2014 2:39:55 PM COT +-- IDEMPIERE-452 Control dates +UPDATE AD_Column SET Callout='org.compiere.model.CalloutEngine.checkPeriodOpen',Updated=TO_DATE('2014-01-25 14:39:55','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3552 +; + +-- Jan 25, 2014 2:40:28 PM COT +UPDATE AD_Column SET Callout='org.compiere.model.CalloutEngine.checkPeriodOpen',Updated=TO_DATE('2014-01-25 14:40:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3579 +; + +-- Jan 25, 2014 2:40:49 PM COT +UPDATE AD_Column SET Callout='org.compiere.model.CalloutEngine.checkPeriodOpen',Updated=TO_DATE('2014-01-25 14:40:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3608 +; + +-- Jan 25, 2014 2:41:13 PM COT +UPDATE AD_Column SET Callout='org.compiere.model.CalloutEngine.checkPeriodOpen',Updated=TO_DATE('2014-01-25 14:41:13','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=14527 +; + +SELECT register_migration_script('201401251441_IDEMPIERE-452.sql') FROM dual +; + diff --git a/migration/i2.0z/postgresql/201401251441_IDEMPIERE-452.sql b/migration/i2.0z/postgresql/201401251441_IDEMPIERE-452.sql new file mode 100644 index 0000000000..9c6b2b6067 --- /dev/null +++ b/migration/i2.0z/postgresql/201401251441_IDEMPIERE-452.sql @@ -0,0 +1,20 @@ +-- Jan 25, 2014 2:39:55 PM COT +-- IDEMPIERE-452 Control dates +UPDATE AD_Column SET Callout='org.compiere.model.CalloutEngine.checkPeriodOpen',Updated=TO_TIMESTAMP('2014-01-25 14:39:55','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3552 +; + +-- Jan 25, 2014 2:40:28 PM COT +UPDATE AD_Column SET Callout='org.compiere.model.CalloutEngine.checkPeriodOpen',Updated=TO_TIMESTAMP('2014-01-25 14:40:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3579 +; + +-- Jan 25, 2014 2:40:49 PM COT +UPDATE AD_Column SET Callout='org.compiere.model.CalloutEngine.checkPeriodOpen',Updated=TO_TIMESTAMP('2014-01-25 14:40:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=3608 +; + +-- Jan 25, 2014 2:41:13 PM COT +UPDATE AD_Column SET Callout='org.compiere.model.CalloutEngine.checkPeriodOpen',Updated=TO_TIMESTAMP('2014-01-25 14:41:13','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=14527 +; + +SELECT register_migration_script('201401251441_IDEMPIERE-452.sql') FROM dual +; + diff --git a/org.adempiere.base/src/org/compiere/model/CalloutEngine.java b/org.adempiere.base/src/org/compiere/model/CalloutEngine.java index 006a88eaaa..c734b8e437 100644 --- a/org.adempiere.base/src/org/compiere/model/CalloutEngine.java +++ b/org.adempiere.base/src/org/compiere/model/CalloutEngine.java @@ -22,6 +22,7 @@ import java.sql.Timestamp; import java.util.Properties; import java.util.logging.Level; +import org.compiere.acct.Doc; import org.compiere.util.CLogger; import org.compiere.util.Env; @@ -230,9 +231,59 @@ public class CalloutEngine implements Callout if (value == null || !(value instanceof Timestamp)) return NO_ERROR; mTab.setValue("DateAcct", value); - return NO_ERROR; + return checkPeriodOpen (ctx, WindowNo, mTab, mField, value); } // dateAcct + /** + * Check Account Date is on a opened period + * @param ctx context + * @param WindowNo window no + * @param mTab tab + * @param mField field + * @param value value + * @return null or error message + */ + public String checkPeriodOpen (Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) + { + if (isCalloutActive()) // assuming it is resetting value + return NO_ERROR; + if (value == null || !(value instanceof Timestamp)) + return NO_ERROR; + + int orgID = 0; + if (mTab.getValue("AD_Org_ID") != null) + orgID = (Integer) mTab.getValue("AD_Org_ID"); + + int doctypeID = -1; + if (mTab.getValue("C_DocTypeTarget_ID") != null) + doctypeID = (Integer) mTab.getValue("C_DocTypeTarget_ID"); + else if (mTab.getValue("C_DocType_ID") != null) + doctypeID = (Integer) mTab.getValue("C_DocType_ID"); + + String docBase = null; + if (doctypeID <= 0) { + if (MBankStatement.Table_Name.equals(mTab.getTableName())) + docBase = Doc.DOCTYPE_BankStatement; + else if (MBankStatementLine.Table_Name.equals(mTab.getTableName())) + docBase = Doc.DOCTYPE_BankStatement; + else if (MInventory.Table_Name.equals(mTab.getTableName())) + docBase = Doc.DOCTYPE_MatInventory; + else if (MMovement.Table_Name.equals(mTab.getTableName())) + docBase = Doc.DOCTYPE_MatMovement; + else if (MProduction.Table_Name.equals(mTab.getTableName())) + docBase = Doc.DOCTYPE_MatProduction; + else if (MRequisition.Table_Name.equals(mTab.getTableName())) + docBase = Doc.DOCTYPE_PurchaseRequisition; + } + + if (doctypeID > 0) { + MPeriod.testPeriodOpen(ctx, (Timestamp)value, doctypeID, orgID); + } else if (docBase != null) { + MPeriod.testPeriodOpen(ctx, (Timestamp)value, docBase, orgID); + } + return NO_ERROR; + } + /** * Rate - set Multiply Rate from Divide Rate and vice versa * org.compiere.model.CalloutEngine.rate