From 5f9c1f7dc896566c3a32a014eae0a426e3dc04ca Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 17 Dec 2013 21:14:26 -0500 Subject: [PATCH] IDEMPIERE-1597 Price List and Date must be not-updateable --- .../oracle/201312131644_IDEMPIERE-1597.sql | 23 +++++++++++++++++++ .../201312131644_IDEMPIERE-1597.sql | 20 ++++++++++++++++ .../src/org/compiere/model/MInvoice.java | 22 +++++++++++++++++- .../src/org/compiere/model/MOrder.java | 22 +++++++++++++++++- .../src/org/compiere/model/MPriceList.java | 3 --- 5 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 migration/i2.0/oracle/201312131644_IDEMPIERE-1597.sql create mode 100644 migration/i2.0/postgresql/201312131644_IDEMPIERE-1597.sql diff --git a/migration/i2.0/oracle/201312131644_IDEMPIERE-1597.sql b/migration/i2.0/oracle/201312131644_IDEMPIERE-1597.sql new file mode 100644 index 0000000000..e3dc3004f4 --- /dev/null +++ b/migration/i2.0/oracle/201312131644_IDEMPIERE-1597.sql @@ -0,0 +1,23 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Dec 13, 2013 4:13:06 PM COT +-- IDEMPIERE-1597 Price List and Date must be not-updateable +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('E','Price list cannot be changed because the order contains product lines',200243,'D','41c5bae2-77e0-4beb-a562-3f3ae465cb90','CannotChangePl','Y',TO_DATE('2013-12-13 16:13:05','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_DATE('2013-12-13 16:13:05','YYYY-MM-DD HH24:MI:SS'),0) +; + +-- Dec 13, 2013 4:15:35 PM COT +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('E','Date Ordered cannot be changed because the order contains product lines and the change falls in a differente price list version',200244,'D','8264d9e8-2b91-4aa2-ba80-82171b747254','CannotChangeDateOrdered','Y',TO_DATE('2013-12-13 16:15:34','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_DATE('2013-12-13 16:15:34','YYYY-MM-DD HH24:MI:SS'),0) +; + +-- Dec 13, 2013 4:23:13 PM COT +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('E','Price list cannot be changed because the invoice contains product lines',200245,'D','4d860b4e-0cd0-491f-a68d-e8a4b0ffb8f8','CannotChangePlIn','Y',TO_DATE('2013-12-13 16:23:12','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_DATE('2013-12-13 16:23:12','YYYY-MM-DD HH24:MI:SS'),0) +; + +-- Dec 13, 2013 4:24:15 PM COT +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('E','Date Invoiced cannot be changed because the invoice contains product lines and the change falls in a differente price list version',200246,'D','411625c7-21ee-48e0-8350-5e59f7fb9ecd','CannotChangeDateInvoiced','Y',TO_DATE('2013-12-13 16:24:14','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_DATE('2013-12-13 16:24:14','YYYY-MM-DD HH24:MI:SS'),0) +; + +SELECT register_migration_script('201312131644_IDEMPIERE-1597.sql') FROM dual +; + diff --git a/migration/i2.0/postgresql/201312131644_IDEMPIERE-1597.sql b/migration/i2.0/postgresql/201312131644_IDEMPIERE-1597.sql new file mode 100644 index 0000000000..352b2367cc --- /dev/null +++ b/migration/i2.0/postgresql/201312131644_IDEMPIERE-1597.sql @@ -0,0 +1,20 @@ +-- Dec 13, 2013 4:13:06 PM COT +-- IDEMPIERE-1597 Price List and Date must be not-updateable +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('E','Price list cannot be changed because the order contains product lines',200243,'D','41c5bae2-77e0-4beb-a562-3f3ae465cb90','CannotChangePl','Y',TO_TIMESTAMP('2013-12-13 16:13:05','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_TIMESTAMP('2013-12-13 16:13:05','YYYY-MM-DD HH24:MI:SS'),0) +; + +-- Dec 13, 2013 4:15:35 PM COT +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('E','Date Ordered cannot be changed because the order contains product lines and the change falls in a differente price list version',200244,'D','8264d9e8-2b91-4aa2-ba80-82171b747254','CannotChangeDateOrdered','Y',TO_TIMESTAMP('2013-12-13 16:15:34','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_TIMESTAMP('2013-12-13 16:15:34','YYYY-MM-DD HH24:MI:SS'),0) +; + +-- Dec 13, 2013 4:23:13 PM COT +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('E','Price list cannot be changed because the invoice contains product lines',200245,'D','4d860b4e-0cd0-491f-a68d-e8a4b0ffb8f8','CannotChangePlIn','Y',TO_TIMESTAMP('2013-12-13 16:23:12','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_TIMESTAMP('2013-12-13 16:23:12','YYYY-MM-DD HH24:MI:SS'),0) +; + +-- Dec 13, 2013 4:24:15 PM COT +INSERT INTO AD_Message (MsgType,MsgText,AD_Message_ID,EntityType,AD_Message_UU,Value,IsActive,Updated,CreatedBy,UpdatedBy,AD_Org_ID,Created,AD_Client_ID) VALUES ('E','Date Invoiced cannot be changed because the invoice contains product lines and the change falls in a differente price list version',200246,'D','411625c7-21ee-48e0-8350-5e59f7fb9ecd','CannotChangeDateInvoiced','Y',TO_TIMESTAMP('2013-12-13 16:24:14','YYYY-MM-DD HH24:MI:SS'),100,100,0,TO_TIMESTAMP('2013-12-13 16:24:14','YYYY-MM-DD HH24:MI:SS'),0) +; + +SELECT register_migration_script('201312131644_IDEMPIERE-1597.sql') FROM dual +; + diff --git a/org.adempiere.base/src/org/compiere/model/MInvoice.java b/org.adempiere.base/src/org/compiere/model/MInvoice.java index e9c0f166c6..ef8720fbd9 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoice.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoice.java @@ -986,7 +986,27 @@ public class MInvoice extends X_C_Invoice implements DocAction if (order.getC_CashPlanLine_ID() > 0) setC_CashPlanLine_ID(order.getC_CashPlanLine_ID()); } - + + // IDEMPIERE-1597 Price List and Date must be not-updateable + if (!newRecord && (is_ValueChanged(COLUMNNAME_M_PriceList_ID) || is_ValueChanged(COLUMNNAME_DateInvoiced))) { + int cnt = DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM C_InvoiceLine WHERE C_Invoice_ID=? AND M_Product_ID>0", getC_Invoice_ID()); + if (cnt > 0) { + if (is_ValueChanged(COLUMNNAME_M_PriceList_ID)) { + log.saveError("Error", Msg.getMsg(getCtx(), "CannotChangePlIn")); + return false; + } + if (is_ValueChanged(COLUMNNAME_DateInvoiced)) { + MPriceList pList = MPriceList.get(getCtx(), getM_PriceList_ID(), null); + MPriceListVersion plOld = pList.getPriceListVersion((Timestamp)get_ValueOld(COLUMNNAME_DateInvoiced)); + MPriceListVersion plNew = pList.getPriceListVersion((Timestamp)get_Value(COLUMNNAME_DateInvoiced)); + if (plNew == null || !plNew.equals(plOld)) { + log.saveError("Error", Msg.getMsg(getCtx(), "CannotChangeDateInvoiced")); + return false; + } + } + } + } + return true; } // beforeSave diff --git a/org.adempiere.base/src/org/compiere/model/MOrder.java b/org.adempiere.base/src/org/compiere/model/MOrder.java index 3a3294c962..594d87cccb 100644 --- a/org.adempiere.base/src/org/compiere/model/MOrder.java +++ b/org.adempiere.base/src/org/compiere/model/MOrder.java @@ -1066,7 +1066,27 @@ public class MOrder extends X_C_Order implements DocAction } } } - + + // IDEMPIERE-1597 Price List and Date must be not-updateable + if (!newRecord && (is_ValueChanged(COLUMNNAME_M_PriceList_ID) || is_ValueChanged(COLUMNNAME_DateOrdered))) { + int cnt = DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM C_OrderLine WHERE C_Order_ID=? AND M_Product_ID>0", getC_Order_ID()); + if (cnt > 0) { + if (is_ValueChanged(COLUMNNAME_M_PriceList_ID)) { + log.saveError("Error", Msg.getMsg(getCtx(), "CannotChangePl")); + return false; + } + if (is_ValueChanged(COLUMNNAME_DateOrdered)) { + MPriceList pList = MPriceList.get(getCtx(), getM_PriceList_ID(), null); + MPriceListVersion plOld = pList.getPriceListVersion((Timestamp)get_ValueOld(COLUMNNAME_DateOrdered)); + MPriceListVersion plNew = pList.getPriceListVersion((Timestamp)get_Value(COLUMNNAME_DateOrdered)); + if (plNew == null || !plNew.equals(plOld)) { + log.saveError("Error", Msg.getMsg(getCtx(), "CannotChangeDateOrdered")); + return false; + } + } + } + } + return true; } // beforeSave diff --git a/org.adempiere.base/src/org/compiere/model/MPriceList.java b/org.adempiere.base/src/org/compiere/model/MPriceList.java index d72eb6732e..4d312dbc39 100644 --- a/org.adempiere.base/src/org/compiere/model/MPriceList.java +++ b/org.adempiere.base/src/org/compiere/model/MPriceList.java @@ -240,9 +240,6 @@ public class MPriceList extends X_M_PriceList { if (valid == null) valid = new Timestamp (System.currentTimeMillis()); - // Assume there is no later - if (m_plv != null && m_plv.getValidFrom().before(valid)) - return m_plv; final String whereClause = "M_PriceList_ID=? AND TRUNC(ValidFrom)<=?"; m_plv = new Query(getCtx(), I_M_PriceList_Version.Table_Name, whereClause, get_TrxName())