[ 1674225 ] Delete Product: Costing deletion error
This commit is contained in:
parent
19e13965de
commit
f866eef6b7
|
|
@ -1,8 +1,8 @@
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* 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 *
|
||||||
* by the Free Software Foundation. This program is distributed in the hope *
|
* by the Free Software Foundation. This program is distributed in the hope *
|
||||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||||
|
|
@ -99,12 +99,12 @@ public class MProduct extends X_M_Product
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param M_Product_ID id
|
* @param M_Product_ID id
|
||||||
* @return true if found and stocked - false otherwise
|
* @return true if found and stocked - false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isProductStocked (Properties ctx, int M_Product_ID)
|
public static boolean isProductStocked (Properties ctx, int M_Product_ID)
|
||||||
{
|
{
|
||||||
MProduct product = get (ctx, M_Product_ID);
|
MProduct product = get (ctx, M_Product_ID);
|
||||||
return product.isStocked();
|
return product.isStocked();
|
||||||
} // isProductStocked
|
} // isProductStocked
|
||||||
|
|
||||||
/** Cache */
|
/** Cache */
|
||||||
private static CCache<Integer,MProduct> s_cache = new CCache<Integer,MProduct>("M_Product", 40, 5); // 5 minutes
|
private static CCache<Integer,MProduct> s_cache = new CCache<Integer,MProduct>("M_Product", 40, 5); // 5 minutes
|
||||||
|
|
@ -160,25 +160,25 @@ public class MProduct extends X_M_Product
|
||||||
* Parent Constructor
|
* Parent Constructor
|
||||||
* @param et parent
|
* @param et parent
|
||||||
*/
|
*/
|
||||||
public MProduct (MExpenseType et)
|
public MProduct (MExpenseType et)
|
||||||
{
|
{
|
||||||
this (et.getCtx(), 0, et.get_TrxName());
|
this (et.getCtx(), 0, et.get_TrxName());
|
||||||
setProductType(X_M_Product.PRODUCTTYPE_ExpenseType);
|
setProductType(X_M_Product.PRODUCTTYPE_ExpenseType);
|
||||||
setExpenseType(et);
|
setExpenseType(et);
|
||||||
} // MProduct
|
} // MProduct
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parent Constructor
|
* Parent Constructor
|
||||||
* @param resource parent
|
* @param resource parent
|
||||||
* @param resourceType resource type
|
* @param resourceType resource type
|
||||||
*/
|
*/
|
||||||
public MProduct (MResource resource, MResourceType resourceType)
|
public MProduct (MResource resource, MResourceType resourceType)
|
||||||
{
|
{
|
||||||
this (resource.getCtx(), 0, resource.get_TrxName());
|
this (resource.getCtx(), 0, resource.get_TrxName());
|
||||||
setProductType(X_M_Product.PRODUCTTYPE_Resource);
|
setProductType(X_M_Product.PRODUCTTYPE_Resource);
|
||||||
setResource(resource);
|
setResource(resource);
|
||||||
setResource(resourceType);
|
setResource(resourceType);
|
||||||
} // MProduct
|
} // MProduct
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Import Constructor
|
* Import Constructor
|
||||||
|
|
@ -610,25 +610,25 @@ public class MProduct extends X_M_Product
|
||||||
|
|
||||||
// New - Acct, Tree, Old Costing
|
// New - Acct, Tree, Old Costing
|
||||||
if (newRecord)
|
if (newRecord)
|
||||||
{
|
{
|
||||||
insert_Accounting("M_Product_Acct", "M_Product_Category_Acct",
|
insert_Accounting("M_Product_Acct", "M_Product_Category_Acct",
|
||||||
"p.M_Product_Category_ID=" + getM_Product_Category_ID());
|
"p.M_Product_Category_ID=" + getM_Product_Category_ID());
|
||||||
insert_Tree(X_AD_Tree.TREETYPE_Product);
|
insert_Tree(X_AD_Tree.TREETYPE_Product);
|
||||||
//
|
//
|
||||||
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID(), get_TrxName());
|
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID(), get_TrxName());
|
||||||
for (int i = 0; i < mass.length; i++)
|
for (int i = 0; i < mass.length; i++)
|
||||||
{
|
{
|
||||||
// Old
|
// Old
|
||||||
MProductCosting pcOld = new MProductCosting(this, mass[i].getC_AcctSchema_ID());
|
MProductCosting pcOld = new MProductCosting(this, mass[i].getC_AcctSchema_ID());
|
||||||
pcOld.save();
|
pcOld.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// New Costing
|
// New Costing
|
||||||
if (newRecord || is_ValueChanged("M_Product_Category_ID"))
|
if (newRecord || is_ValueChanged("M_Product_Category_ID"))
|
||||||
MCost.create(this);
|
MCost.create(this);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
} // afterSave
|
} // afterSave
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -668,6 +668,31 @@ public class MProduct extends X_M_Product
|
||||||
MProductCosting[] costings = MProductCosting.getOfProduct(getCtx(), get_ID(), get_TrxName());
|
MProductCosting[] costings = MProductCosting.getOfProduct(getCtx(), get_ID(), get_TrxName());
|
||||||
for (int i = 0; i < costings.length; i++)
|
for (int i = 0; i < costings.length; i++)
|
||||||
costings[i].delete(true, get_TrxName());
|
costings[i].delete(true, get_TrxName());
|
||||||
|
|
||||||
|
// [ 1674225 ] Delete Product: Costing deletion error
|
||||||
|
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(getCtx(),
|
||||||
|
getAD_Client_ID(), get_TrxName());
|
||||||
|
for(int i=0; i<mass.length; i++)
|
||||||
|
{
|
||||||
|
// Get Cost Elements
|
||||||
|
MCostElement[] ces = MCostElement.getCostingMethods(this);
|
||||||
|
MCostElement ce = null;
|
||||||
|
for(int j=0; j<ces.length; j++)
|
||||||
|
{
|
||||||
|
if(MCostElement.COSTINGMETHOD_StandardCosting.equals(ces[i].getCostingMethod()))
|
||||||
|
{
|
||||||
|
ce = ces[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ce == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
MCost mcost = MCost.get(this, 0, mass[i], 0, ce.getM_CostElement_ID());
|
||||||
|
mcost.delete(true, get_TrxName());
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return delete_Accounting("M_Product_Acct");
|
return delete_Accounting("M_Product_Acct");
|
||||||
} // beforeDelete
|
} // beforeDelete
|
||||||
|
|
@ -677,11 +702,11 @@ public class MProduct extends X_M_Product
|
||||||
* @param success
|
* @param success
|
||||||
* @return deleted
|
* @return deleted
|
||||||
*/
|
*/
|
||||||
protected boolean afterDelete (boolean success)
|
protected boolean afterDelete (boolean success)
|
||||||
{
|
{
|
||||||
if (success)
|
if (success)
|
||||||
delete_Tree(X_AD_Tree.TREETYPE_Product);
|
delete_Tree(X_AD_Tree.TREETYPE_Product);
|
||||||
return success;
|
return success;
|
||||||
} // afterDelete
|
} // afterDelete
|
||||||
|
|
||||||
} // MProduct
|
} // MProduct
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue