From 51a787b461033c08e77b17bb891ba2bd848dab14 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sun, 27 Jul 2008 01:13:05 +0000 Subject: [PATCH] Fix [ 2019115 ] Don't allow UoM change if product already used --- base/src/org/compiere/model/MProduct.java | 49 ++++++++++++++++--- migration/351a-trunk/241_BF2019115.sql | 10 ++++ .../351a-trunk/postgresql/241_BF2019115.sql | 15 ++++++ 3 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 migration/351a-trunk/241_BF2019115.sql create mode 100644 migration/351a-trunk/postgresql/241_BF2019115.sql diff --git a/base/src/org/compiere/model/MProduct.java b/base/src/org/compiere/model/MProduct.java index bd6e15e719..2136ef1cf5 100644 --- a/base/src/org/compiere/model/MProduct.java +++ b/base/src/org/compiere/model/MProduct.java @@ -1,5 +1,5 @@ /****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * + * Product: Adempiere ERP & CRM Smart Business Solution * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * * under the terms version 2 of the GNU General Public License as published * @@ -16,11 +16,18 @@ *****************************************************************************/ package org.compiere.model; -import java.math.*; -import java.sql.*; -import java.util.*; -import java.util.logging.*; -import org.compiere.util.*; +import java.math.BigDecimal; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.Properties; +import java.util.logging.Level; + +import org.compiere.util.CCache; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.util.Msg; /** * Product Model @@ -34,6 +41,12 @@ import org.compiere.util.*; */ public class MProduct extends X_M_Product { + /** + * + */ + private static final long serialVersionUID = 9065433844664694783L; + + /** * Get MProduct from Cache * @param ctx context @@ -570,6 +583,12 @@ public class MProduct extends X_M_Product return false; } } // storage + + // it checks if UOM has been changed , if so disallow the change if the condition is true. + if ((!newRecord) && is_ValueChanged("C_UOM_ID") && hasInventoryOrCost ()) { + log.saveError("Error", Msg.getMsg(getCtx(), "SaveUomError")); + return false; + } // Reset Stocked if not Item //AZ Goodwill: Bug Fix isStocked always return false @@ -584,6 +603,24 @@ public class MProduct extends X_M_Product return true; } // beforeSave + /** + * HasInventoryOrCost + * @return true if it has Inventory or Cost + */ + protected boolean hasInventoryOrCost () { + //check if it has transactions + int trans = DB.getSQLValue(null,"SELECT COUNT(*) FROM M_Transaction WHERE M_Product_ID=? AND IsActive='Y'", getM_Product_ID()); + if (trans > 0) + return true; + + //check if it has cost + int cost = DB.getSQLValue(null,"SELECT COUNT(*) FROM M_CostDetail WHERE M_Product_ID=? AND IsActive='Y'", getM_Product_ID()); + if (cost > 0) + return true; + + return false; + } + /** * After Save * @param newRecord new diff --git a/migration/351a-trunk/241_BF2019115.sql b/migration/351a-trunk/241_BF2019115.sql new file mode 100644 index 0000000000..e1f8b942ce --- /dev/null +++ b/migration/351a-trunk/241_BF2019115.sql @@ -0,0 +1,10 @@ +-- Jul 22, 2008 3:46:17 PM COT +-- [ 2019115 ] Don't allow UoM change if product already used +INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,53043,0,TO_DATE('2008-07-22 15:46:13','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','UOM can''t be changed if the product has movements or costs','E',TO_DATE('2008-07-22 15:46:13','YYYY-MM-DD HH24:MI:SS'),100,'SaveUomError') +; + +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) 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 FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=53043 AND EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Message_ID!=t.AD_Message_ID) +; + +UPDATE AD_Message_Trl SET IsTranslated='Y',MsgText='UOM no puede ser modificado si el producto tiene movimientos o costos',Updated=TO_DATE('2008-07-22 15:47:05','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Message_ID=53043 AND AD_Language like 'es_%' +; diff --git a/migration/351a-trunk/postgresql/241_BF2019115.sql b/migration/351a-trunk/postgresql/241_BF2019115.sql new file mode 100644 index 0000000000..6fe911923a --- /dev/null +++ b/migration/351a-trunk/postgresql/241_BF2019115.sql @@ -0,0 +1,15 @@ +-- Jul 22, 2008 3:46:17 PM COT +-- [ 2019115 ] Don't allow UoM change if product already used +INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,53043,0,TO_TIMESTAMP('2008-07-22 15:46:13','YYYY-MM-DD HH24:MI:SS'),100,'D','Y','UOM can''t be changed if the product has movements or costs','E',TO_TIMESTAMP('2008-07-22 15:46:13','YYYY-MM-DD HH24:MI:SS'),100,'SaveUomError') +; + +-- Jul 22, 2008 3:46:17 PM COT +-- [ 2019115 ] Don't allow UoM change if product already used +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) 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 FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=53043 AND EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Message_ID!=t.AD_Message_ID) +; + +-- Jul 22, 2008 3:47:05 PM COT +-- [ 2019115 ] Don't allow UoM change if product already used +UPDATE AD_Message_Trl SET IsTranslated='Y',MsgText='UOM no puede ser modificado si el producto tiene movimientos o costos',Updated=TO_TIMESTAMP('2008-07-22 15:47:05','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Message_ID=53043 AND AD_Language like 'es_%' +; +