Fix [ 2019115 ] Don't allow UoM change if product already used
This commit is contained in:
parent
4932e4b1a5
commit
51a787b461
|
@ -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. *
|
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||||
* This program is free software; you can redistribute it and/or modify it *
|
* 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 *
|
* under the terms version 2 of the GNU General Public License as published *
|
||||||
|
@ -16,11 +16,18 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.math.*;
|
import java.math.BigDecimal;
|
||||||
import java.sql.*;
|
import java.sql.PreparedStatement;
|
||||||
import java.util.*;
|
import java.sql.ResultSet;
|
||||||
import java.util.logging.*;
|
import java.util.ArrayList;
|
||||||
import org.compiere.util.*;
|
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
|
* Product Model
|
||||||
|
@ -34,6 +41,12 @@ import org.compiere.util.*;
|
||||||
*/
|
*/
|
||||||
public class MProduct extends X_M_Product
|
public class MProduct extends X_M_Product
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 9065433844664694783L;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get MProduct from Cache
|
* Get MProduct from Cache
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -570,6 +583,12 @@ public class MProduct extends X_M_Product
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} // storage
|
} // 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
|
// Reset Stocked if not Item
|
||||||
//AZ Goodwill: Bug Fix isStocked always return false
|
//AZ Goodwill: Bug Fix isStocked always return false
|
||||||
|
@ -584,6 +603,24 @@ public class MProduct extends X_M_Product
|
||||||
return true;
|
return true;
|
||||||
} // beforeSave
|
} // 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
|
* After Save
|
||||||
* @param newRecord new
|
* @param newRecord new
|
||||||
|
|
|
@ -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_%'
|
||||||
|
;
|
|
@ -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_%'
|
||||||
|
;
|
||||||
|
|
Loading…
Reference in New Issue