diff --git a/migration/360lts-release/oracle/897_IDEMPIERE-63.sql b/migration/360lts-release/oracle/897_IDEMPIERE-63.sql new file mode 100644 index 0000000000..9ce01aeaba --- /dev/null +++ b/migration/360lts-release/oracle/897_IDEMPIERE-63.sql @@ -0,0 +1,26 @@ +-- Aug 29, 2012 6:44:34 PM COT +-- IDEMPIERE-63 Document number is updated again when document completed after reactivation +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Document type cannot be changed when overwrite document number on complete is set and the document was already processed',200025,'D','1bc9f344-4855-473d-a058-424dfd6d9a1e','CannotChangeProcessedDocType','Y',TO_DATE('2012-08-29 18:44:33','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2012-08-29 18:44:33','YYYY-MM-DD HH24:MI:SS')) +; + +-- Aug 29, 2012 6:44:34 PM COT +-- IDEMPIERE-63 Document number is updated again when document completed after reactivation +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200025 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Aug 29, 2012 6:44:57 PM COT +-- IDEMPIERE-63 Document number is updated again when document completed after reactivation +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Date cannot be changed when overwrite date on complete is set and the document was already processed',200026,'D','81bf5a40-ae47-4dcf-9be3-9d04d0c9116f','CannotChangeProcessedDate','Y',TO_DATE('2012-08-29 18:44:56','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_DATE('2012-08-29 18:44:56','YYYY-MM-DD HH24:MI:SS')) +; + +-- Aug 29, 2012 6:44:57 PM COT +-- IDEMPIERE-63 Document number is updated again when document completed after reactivation +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200026 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +UPDATE AD_System + SET LastMigrationScriptApplied='897_IDEMPIERE-63.sql' +WHERE LastMigrationScriptApplied<'897_IDEMPIERE-63.sql' + OR LastMigrationScriptApplied IS NULL +; + diff --git a/migration/360lts-release/postgresql/897_IDEMPIERE-63.sql b/migration/360lts-release/postgresql/897_IDEMPIERE-63.sql new file mode 100644 index 0000000000..74a35bd628 --- /dev/null +++ b/migration/360lts-release/postgresql/897_IDEMPIERE-63.sql @@ -0,0 +1,26 @@ +-- Aug 29, 2012 6:44:34 PM COT +-- IDEMPIERE-63 Document number is updated again when document completed after reactivation +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Document type cannot be changed when overwrite document number on complete is set and the document was already processed',200025,'D','1bc9f344-4855-473d-a058-424dfd6d9a1e','CannotChangeProcessedDocType','Y',TO_TIMESTAMP('2012-08-29 18:44:33','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2012-08-29 18:44:33','YYYY-MM-DD HH24:MI:SS')) +; + +-- Aug 29, 2012 6:44:34 PM COT +-- IDEMPIERE-63 Document number is updated again when document completed after reactivation +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200025 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +-- Aug 29, 2012 6:44:57 PM COT +-- IDEMPIERE-63 Document number is updated again when document completed after reactivation +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Client_ID,AD_Org_ID,Created) VALUES ('E','Date cannot be changed when overwrite date on complete is set and the document was already processed',200026,'D','81bf5a40-ae47-4dcf-9be3-9d04d0c9116f','CannotChangeProcessedDate','Y',TO_TIMESTAMP('2012-08-29 18:44:56','YYYY-MM-DD HH24:MI:SS'),100,100,0,0,TO_TIMESTAMP('2012-08-29 18:44:56','YYYY-MM-DD HH24:MI:SS')) +; + +-- Aug 29, 2012 6:44:57 PM COT +-- IDEMPIERE-63 Document number is updated again when document completed after reactivation +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy,AD_Message_Trl_UU ) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy,Generate_UUID() FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=200026 AND NOT EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID) +; + +UPDATE AD_System + SET LastMigrationScriptApplied='897_IDEMPIERE-63.sql' +WHERE LastMigrationScriptApplied<'897_IDEMPIERE-63.sql' + OR LastMigrationScriptApplied IS NULL +; + diff --git a/org.adempiere.base/src/org/compiere/model/MJournal.java b/org.adempiere.base/src/org/compiere/model/MJournal.java index 85ec95e9c6..6dae4b1338 100644 --- a/org.adempiere.base/src/org/compiere/model/MJournal.java +++ b/org.adempiere.base/src/org/compiere/model/MJournal.java @@ -304,6 +304,28 @@ public class MJournal extends X_GL_Journal implements DocAction } if (getDateAcct() == null) setDateAcct(getDateDoc()); + + // IDEMPIERE-63 + // for documents that can be reactivated we cannot allow changing + // C_DocTypeTarget_ID or C_DocType_ID if they were already processed and isOverwriteSeqOnComplete + // neither change the Date if isOverwriteDateOnComplete + BigDecimal previousProcessedOn = (BigDecimal) get_ValueOld(COLUMNNAME_ProcessedOn); + if (! newRecord && previousProcessedOn != null && previousProcessedOn.signum() > 0) { + int previousDocTypeID = (Integer) get_ValueOld(COLUMNNAME_C_DocType_ID); + MDocType previousdt = MDocType.get(getCtx(), previousDocTypeID); + if (is_ValueChanged(COLUMNNAME_C_DocType_ID)) { + if (previousdt.isOverwriteSeqOnComplete()) { + log.saveError("Error", Msg.getMsg(getCtx(), "CannotChangeProcessedDocType")); + return false; + } + } + if (is_ValueChanged(COLUMNNAME_DateDoc)) { + if (previousdt.isOverwriteDateOnComplete()) { + log.saveError("Error", Msg.getMsg(getCtx(), "CannotChangeProcessedDate")); + return false; + } + } + } // Update DateAcct on lines - teo_sarca BF [ 1775358 ] if (is_ValueChanged(COLUMNNAME_DateAcct)) { @@ -601,12 +623,16 @@ public class MJournal extends X_GL_Journal implements DocAction private void setDefiniteDocumentNo() { MDocType dt = MDocType.get(getCtx(), getC_DocType_ID()); if (dt.isOverwriteDateOnComplete()) { - setDateDoc(new Timestamp (System.currentTimeMillis())); + if (this.getProcessedOn().signum() == 0) { + setDateDoc(new Timestamp (System.currentTimeMillis())); + } } if (dt.isOverwriteSeqOnComplete()) { - String value = DB.getDocumentNo(getC_DocType_ID(), get_TrxName(), true, this); - if (value != null) - setDocumentNo(value); + if (this.getProcessedOn().signum() == 0) { + String value = DB.getDocumentNo(getC_DocType_ID(), get_TrxName(), true, this); + if (value != null) + setDocumentNo(value); + } } } diff --git a/org.adempiere.base/src/org/compiere/model/MOrder.java b/org.adempiere.base/src/org/compiere/model/MOrder.java index b546366066..ef0a4e1368 100644 --- a/org.adempiere.base/src/org/compiere/model/MOrder.java +++ b/org.adempiere.base/src/org/compiere/model/MOrder.java @@ -1043,6 +1043,28 @@ public class MOrder extends X_C_Order implements DocAction setC_PaymentTerm_ID (ii); } } + + // IDEMPIERE-63 + // for documents that can be reactivated we cannot allow changing + // C_DocTypeTarget_ID or C_DocType_ID if they were already processed and isOverwriteSeqOnComplete + // neither change the Date if isOverwriteDateOnComplete + BigDecimal previousProcessedOn = (BigDecimal) get_ValueOld(COLUMNNAME_ProcessedOn); + if (! newRecord && previousProcessedOn != null && previousProcessedOn.signum() > 0) { + int previousDocTypeID = (Integer) get_ValueOld(COLUMNNAME_C_DocTypeTarget_ID); + MDocType previousdt = MDocType.get(getCtx(), previousDocTypeID); + if (is_ValueChanged(COLUMNNAME_C_DocType_ID) || is_ValueChanged(COLUMNNAME_C_DocTypeTarget_ID)) { + if (previousdt.isOverwriteSeqOnComplete()) { + log.saveError("Error", Msg.getMsg(getCtx(), "CannotChangeProcessedDocType")); + return false; + } + } + if (is_ValueChanged(COLUMNNAME_DateOrdered)) { + if (previousdt.isOverwriteDateOnComplete()) { + log.saveError("Error", Msg.getMsg(getCtx(), "CannotChangeProcessedDate")); + return false; + } + } + } return true; } // beforeSave @@ -1857,13 +1879,13 @@ public class MOrder extends X_C_Order implements DocAction MDocType dt = MDocType.get(getCtx(), getC_DocType_ID()); if (dt.isOverwriteDateOnComplete()) { /* a42niem - BF IDEMPIERE-63 - check if document has been completed before */ - if (this.getProcessedOn().compareTo(Env.ZERO) == 0) { + if (this.getProcessedOn().signum() == 0) { setDateOrdered(new Timestamp (System.currentTimeMillis())); } } if (dt.isOverwriteSeqOnComplete()) { /* a42niem - BF IDEMPIERE-63 - check if document has been completed before */ - if (this.getProcessedOn().compareTo(Env.ZERO) == 0) { + if (this.getProcessedOn().signum() == 0) { String value = DB.getDocumentNo(getC_DocType_ID(), get_TrxName(), true, this); if (value != null) setDocumentNo(value);