From 993901c7d7c49d73268a6b1e06b48133b3abbf2c Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 16 Oct 2015 10:19:26 -0500 Subject: [PATCH] IDEMPIERE-2811 Each Record should have a primary key / Implement for M_ProductPrice / Peer review --- .../oracle/201510160847_IDEMPIERE-2811.sql | 6 ++++- .../201510160847_IDEMPIERE-2811.sql | 2 +- .../compiere/process/M_PriceList_Create.java | 25 ++++++++++--------- .../src/org/compiere/model/MProductPrice.java | 1 - 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/migration/i2.1z/oracle/201510160847_IDEMPIERE-2811.sql b/migration/i2.1z/oracle/201510160847_IDEMPIERE-2811.sql index 2f5285e465..88b2801abc 100644 --- a/migration/i2.1z/oracle/201510160847_IDEMPIERE-2811.sql +++ b/migration/i2.1z/oracle/201510160847_IDEMPIERE-2811.sql @@ -20,7 +20,7 @@ ALTER TABLE M_ProductPrice ADD M_ProductPrice_ID NUMBER(10) DEFAULT NULL --CHUCK added here --oracle -ALTER TABLE m_productprice DROP CONSTRAINT m_productprice_pkey; +ALTER TABLE m_productprice DROP CONSTRAINT m_productpice_key CASCADE; --CHUCK added here --set the values for the keys @@ -48,6 +48,10 @@ INSERT INTO AD_IndexColumn (AD_Client_ID,AD_Org_ID,AD_IndexColumn_ID,AD_IndexCol ALTER TABLE M_ProductPrice ADD CONSTRAINT m_productprice_unique_idx UNIQUE (M_PriceList_Version_ID,M_Product_ID) ; +-- Carlos - rename old unique key index +ALTER INDEX M_PRODUCTPICE_KEY RENAME TO M_PRODUCTPRICE_UNIQUE_IDX +; + -- Oct 8, 2015 2:23:10 PM CDT INSERT INTO AD_Field (AD_Field_ID,Name,Description,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,ColumnSpan) VALUES (203893,'Product Price','Intersection between a Product and a Price List Version',183,212276,'N',22,'N','N','N','N',0,0,'Y',TO_DATE('2015-10-08 14:23:05','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2015-10-08 14:23:05','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','eb261ad2-c016-4281-adc9-c16742b0c125','N',2) ; diff --git a/migration/i2.1z/postgresql/201510160847_IDEMPIERE-2811.sql b/migration/i2.1z/postgresql/201510160847_IDEMPIERE-2811.sql index 71b3949297..7c29a8892a 100644 --- a/migration/i2.1z/postgresql/201510160847_IDEMPIERE-2811.sql +++ b/migration/i2.1z/postgresql/201510160847_IDEMPIERE-2811.sql @@ -17,7 +17,7 @@ ALTER TABLE M_ProductPrice ADD COLUMN M_ProductPrice_ID NUMERIC(10) DEFAULT NULL --Chuck added here --drop current primary key -alter table m_productprice drop constraint if exists m_productprice_pkey; +alter table m_productprice drop constraint m_productprice_pkey; --Chuck added here --set the values for the keys diff --git a/org.adempiere.base.process/src/org/compiere/process/M_PriceList_Create.java b/org.adempiere.base.process/src/org/compiere/process/M_PriceList_Create.java index a93f2db7e8..0365b78175 100644 --- a/org.adempiere.base.process/src/org/compiere/process/M_PriceList_Create.java +++ b/org.adempiere.base.process/src/org/compiere/process/M_PriceList_Create.java @@ -414,6 +414,8 @@ public class M_PriceList_Create extends SvrProcess { // Copy (Insert) Prices // v_temp = rsCurgen.getInt("M_PriceList_Version_Base_ID"); + int seqproductpriceid = MSequence.get(getCtx(), "M_ProductPrice").get_ID(); + int currentUserID = Env.getAD_User_ID(getCtx()); if (v_temp == p_PriceList_Version_ID) // // We have Prices already @@ -426,6 +428,7 @@ public class M_PriceList_Create extends SvrProcess { { sqlins = new StringBuilder("INSERT INTO M_ProductPrice "); sqlins.append("(M_ProductPrice_ID"); + sqlins.append(" ,M_ProductPrice_UU"); sqlins.append(" ,M_PriceList_Version_ID"); sqlins.append(" ,M_Product_ID "); sqlins.append(" ,AD_Client_ID"); @@ -439,9 +442,8 @@ public class M_PriceList_Create extends SvrProcess { sqlins.append(" , PriceStd"); sqlins.append(" , PriceLimit) "); sqlins.append("SELECT "); - sqlins.append("nextIdFunc("); - sqlins.append( MSequence.get(getCtx(), "M_ProductPrice").get_ID()); - sqlins.append(",'N') ,"); + sqlins.append(" nextIdFunc(").append(seqproductpriceid).append(",'N')"); + sqlins.append(" , generate_uuid(),"); sqlins.append(p_PriceList_Version_ID); sqlins.append(" ,po.M_Product_ID "); sqlins.append(" ,"); @@ -450,9 +452,9 @@ public class M_PriceList_Create extends SvrProcess { sqlins.append(rsCurgen.getInt("AD_Org_ID")); sqlins.append(" ,'Y'"); sqlins.append(" ,SysDate,"); - sqlins.append(rsCurgen.getInt("UpdatedBy")); + sqlins.append(currentUserID); sqlins.append(" ,SysDate,"); - sqlins.append(rsCurgen.getInt("UpdatedBy")); + sqlins.append(currentUserID); // //Price List // @@ -563,22 +565,21 @@ public class M_PriceList_Create extends SvrProcess { //Copy and Convert from other PriceList_Version // sqlins = new StringBuilder("INSERT INTO M_ProductPrice "); - sqlins.append(" (M_ProductPrice_ID, M_PriceList_Version_ID, M_Product_ID,"); + sqlins.append(" (M_ProductPrice_ID, M_ProductPrice_UU, M_PriceList_Version_ID, M_Product_ID,"); sqlins.append(" AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,"); sqlins.append(" PriceList, PriceStd, PriceLimit)"); sqlins.append(" SELECT "); - sqlins.append("nextIdFunc("); - sqlins.append( MSequence.get(getCtx(), "M_ProductPrice").get_ID()); - sqlins.append(",'N') ,"); + sqlins.append("nextIdFunc(").append(seqproductpriceid).append(",'N')"); + sqlins.append(", generate_uuid(),"); sqlins.append(p_PriceList_Version_ID); sqlins.append(", pp.M_Product_ID,"); sqlins.append(rsCurgen.getInt("AD_Client_ID")); sqlins.append(", "); sqlins.append(rsCurgen.getInt("AD_Org_ID")); sqlins.append(", 'Y', SysDate, "); - sqlins.append(rsCurgen.getInt("UpdatedBy")); + sqlins.append(currentUserID); sqlins.append(", SysDate, "); - sqlins.append(rsCurgen.getInt("UpdatedBy")); + sqlins.append(currentUserID); sqlins.append(" ,"); // Price List sqlins.append("COALESCE(currencyConvert(pp.PriceList, pl.C_Currency_ID, "); @@ -617,7 +618,7 @@ public class M_PriceList_Create extends SvrProcess { sqlins.append(rsCurgen.getInt("M_PriceList_Version_Base_ID")); sqlins.append(" AND EXISTS (SELECT * FROM T_Selection s WHERE pp.M_Product_ID=s.T_Selection_ID"); sqlins.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")"); - sqlins.append("AND pp.IsActive='Y'"); + sqlins.append(" AND pp.IsActive='Y'"); pstmt = DB.prepareStatement(sqlins.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, diff --git a/org.adempiere.base/src/org/compiere/model/MProductPrice.java b/org.adempiere.base/src/org/compiere/model/MProductPrice.java index 111b23e5da..b42302207f 100644 --- a/org.adempiere.base/src/org/compiere/model/MProductPrice.java +++ b/org.adempiere.base/src/org/compiere/model/MProductPrice.java @@ -21,7 +21,6 @@ import java.sql.ResultSet; import java.util.Properties; import org.compiere.util.CLogger; -import org.compiere.util.Env; /** * Product Price