From 838af05634d2479714c8134b76ededbddf27a9f3 Mon Sep 17 00:00:00 2001 From: Elaine Tan Date: Thu, 5 Dec 2013 15:38:53 +0800 Subject: [PATCH] IDEMPIERE-337 zkwebui - Improve Info Product window - enforce only one current vendor per product rule --- .../oracle/201312051535_IDEMPIERE-337.sql | 18 ++++++++++ .../postgresql/201312051535_IDEMPIERE-337.sql | 15 +++++++++ .../src/org/compiere/model/MProductPO.java | 33 +++++++++++++++++-- 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 migration/i2.0/oracle/201312051535_IDEMPIERE-337.sql create mode 100644 migration/i2.0/postgresql/201312051535_IDEMPIERE-337.sql diff --git a/migration/i2.0/oracle/201312051535_IDEMPIERE-337.sql b/migration/i2.0/oracle/201312051535_IDEMPIERE-337.sql new file mode 100644 index 0000000000..dd8d9a52f7 --- /dev/null +++ b/migration/i2.0/oracle/201312051535_IDEMPIERE-337.sql @@ -0,0 +1,18 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- IDEMPIERE-337 zkwebui - Improve Info Product window +UPDATE M_Product_PO po +SET IsCurrentVendor='N' +WHERE po.IsActive='Y' +AND po.IsCurrentVendor='Y' +AND po.C_BPartner_ID NOT IN ( + SELECT MAX(ppo.C_BPartner_ID) + FROM M_Product_PO ppo + WHERE ppo.IsActive='Y' + AND ppo.IsCurrentVendor='Y' + AND ppo.M_Product_ID = po.M_Product_ID +); + +SELECT register_migration_script('201312051535_IDEMPIERE-337') FROM dual +; \ No newline at end of file diff --git a/migration/i2.0/postgresql/201312051535_IDEMPIERE-337.sql b/migration/i2.0/postgresql/201312051535_IDEMPIERE-337.sql new file mode 100644 index 0000000000..fd2829156a --- /dev/null +++ b/migration/i2.0/postgresql/201312051535_IDEMPIERE-337.sql @@ -0,0 +1,15 @@ +-- IDEMPIERE-337 zkwebui - Improve Info Product window +UPDATE M_Product_PO po +SET IsCurrentVendor='N' +WHERE po.IsActive='Y' +AND po.IsCurrentVendor='Y' +AND po.C_BPartner_ID NOT IN ( + SELECT MAX(ppo.C_BPartner_ID) + FROM M_Product_PO ppo + WHERE ppo.IsActive='Y' + AND ppo.IsCurrentVendor='Y' + AND ppo.M_Product_ID = po.M_Product_ID +); + +SELECT register_migration_script('201312051535_IDEMPIERE-337') FROM dual +; \ No newline at end of file diff --git a/org.adempiere.base/src/org/compiere/model/MProductPO.java b/org.adempiere.base/src/org/compiere/model/MProductPO.java index dde9a5356b..1c7746732b 100644 --- a/org.adempiere.base/src/org/compiere/model/MProductPO.java +++ b/org.adempiere.base/src/org/compiere/model/MProductPO.java @@ -19,6 +19,9 @@ package org.compiere.model; import java.sql.ResultSet; import java.util.List; import java.util.Properties; +import java.util.logging.Level; + +import org.compiere.util.DB; /** * Product PO Model @@ -31,8 +34,7 @@ public class MProductPO extends X_M_Product_PO /** * */ - private static final long serialVersionUID = -747761340543484440L; - + private static final long serialVersionUID = -1883198806060209516L; /** * Get current PO of Product @@ -84,4 +86,31 @@ public class MProductPO extends X_M_Product_PO super(ctx, rs, trxName); } // MProductPO + /** + * Before Save + * @param newRecord new + * @return true + */ + @Override + protected boolean beforeSave(boolean newRecord) + { + if ((newRecord && isActive() && isCurrentVendor()) || + (!newRecord && + ( + (is_ValueChanged("IsActive") && isActive()) // now active + || (is_ValueChanged("IsCurrentVendor") && isCurrentVendor()) // now current vendor + || is_ValueChanged("C_BPartner_ID") + || is_ValueChanged("M_Product_ID") + ) + ) + ) + { + String sql = "UPDATE M_Product_PO SET IsCurrentVendor='N' WHERE IsActive='Y' AND IsCurrentVendor='Y' AND C_BPartner_ID!=? AND M_Product_ID=?"; + int no = DB.executeUpdate(sql, new Object[] {getC_BPartner_ID(), getM_Product_ID()}, false, get_TrxName()); + if (log.isLoggable(Level.FINEST)) log.finest("Updated M_Product_PO.IsCurrentVendor #" + no); + } + + return true; + } + } // MProductPO