IDEMPIERE-2752 Same Attribute Instance on many Products

This commit is contained in:
Carlos Ruiz 2015-08-05 07:11:13 -05:00
parent a674a185a3
commit 2694d54b71
2 changed files with 23 additions and 11 deletions

View File

@ -598,19 +598,31 @@ public class MProduct extends X_M_Product
m_precision = null;
// AttributeSetInstance reset
if (is_ValueChanged(COLUMNNAME_M_AttributeSet_ID))
if (getM_AttributeSetInstance_ID() > 0 && is_ValueChanged(COLUMNNAME_M_AttributeSet_ID))
{
MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), getM_AttributeSetInstance_ID(), get_TrxName());
if (asi.getM_AttributeSet_ID() != getM_AttributeSet_ID())
setM_AttributeSetInstance_ID(0);
}
if (!newRecord && is_ValueChanged(COLUMNNAME_M_AttributeSetInstance_ID))
{
// IDEMPIERE-2752 check if the ASI is referenced in other products before trying to delete it
int oldasiid = get_ValueOldAsInt(COLUMNNAME_M_AttributeSetInstance_ID);
if (oldasiid > 0) {
MAttributeSetInstance oldasi = new MAttributeSetInstance(getCtx(), get_ValueOldAsInt(COLUMNNAME_M_AttributeSetInstance_ID), get_TrxName());
int cnt = DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM M_Product WHERE M_AttributeSetInstance_ID=?", oldasi.getM_AttributeSetInstance_ID());
if (cnt == 1) {
// Delete the old m_attributesetinstance
try {
asi.deleteEx(true, get_TrxName());
oldasi.deleteEx(true, get_TrxName());
} catch (AdempiereException ex)
{
log.saveError("Error", "Error deleting the AttributeSetInstance");
return false;
}
}
}
}
return true;
} // beforeSave

View File

@ -253,7 +253,8 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
MAttributeSet as = null;
if (m_M_Product_ID != 0)
int M_AttributeSet_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "M_AttributeSet_ID");
if (m_M_Product_ID != 0 && M_AttributeSet_ID == 0)
{
// Get Model
m_masi = MAttributeSetInstance.get(Env.getCtx(), m_M_AttributeSetInstance_ID, m_M_Product_ID);
@ -269,7 +270,6 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
}
else
{
int M_AttributeSet_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "M_AttributeSet_ID");
m_masi = new MAttributeSetInstance (Env.getCtx(), m_M_AttributeSetInstance_ID, M_AttributeSet_ID, null);
as = m_masi.getMAttributeSet();
}