[ 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 *
|
||||
* 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 *
|
||||
/******************************************************************************
|
||||
* 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 *
|
||||
* 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 *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
|
@ -99,12 +99,12 @@ public class MProduct extends X_M_Product
|
|||
* @param ctx context
|
||||
* @param M_Product_ID id
|
||||
* @return true if found and stocked - false otherwise
|
||||
*/
|
||||
public static boolean isProductStocked (Properties ctx, int M_Product_ID)
|
||||
{
|
||||
MProduct product = get (ctx, M_Product_ID);
|
||||
return product.isStocked();
|
||||
} // isProductStocked
|
||||
*/
|
||||
public static boolean isProductStocked (Properties ctx, int M_Product_ID)
|
||||
{
|
||||
MProduct product = get (ctx, M_Product_ID);
|
||||
return product.isStocked();
|
||||
} // isProductStocked
|
||||
|
||||
/** Cache */
|
||||
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
|
||||
* @param et parent
|
||||
*/
|
||||
public MProduct (MExpenseType et)
|
||||
{
|
||||
this (et.getCtx(), 0, et.get_TrxName());
|
||||
setProductType(X_M_Product.PRODUCTTYPE_ExpenseType);
|
||||
setExpenseType(et);
|
||||
} // MProduct
|
||||
|
||||
public MProduct (MExpenseType et)
|
||||
{
|
||||
this (et.getCtx(), 0, et.get_TrxName());
|
||||
setProductType(X_M_Product.PRODUCTTYPE_ExpenseType);
|
||||
setExpenseType(et);
|
||||
} // MProduct
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param resource parent
|
||||
* @param resourceType resource type
|
||||
*/
|
||||
public MProduct (MResource resource, MResourceType resourceType)
|
||||
{
|
||||
this (resource.getCtx(), 0, resource.get_TrxName());
|
||||
setProductType(X_M_Product.PRODUCTTYPE_Resource);
|
||||
setResource(resource);
|
||||
setResource(resourceType);
|
||||
} // MProduct
|
||||
public MProduct (MResource resource, MResourceType resourceType)
|
||||
{
|
||||
this (resource.getCtx(), 0, resource.get_TrxName());
|
||||
setProductType(X_M_Product.PRODUCTTYPE_Resource);
|
||||
setResource(resource);
|
||||
setResource(resourceType);
|
||||
} // MProduct
|
||||
|
||||
/**
|
||||
* Import Constructor
|
||||
|
@ -610,25 +610,25 @@ public class MProduct extends X_M_Product
|
|||
|
||||
// New - Acct, Tree, Old Costing
|
||||
if (newRecord)
|
||||
{
|
||||
insert_Accounting("M_Product_Acct", "M_Product_Category_Acct",
|
||||
"p.M_Product_Category_ID=" + getM_Product_Category_ID());
|
||||
insert_Tree(X_AD_Tree.TREETYPE_Product);
|
||||
//
|
||||
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID(), get_TrxName());
|
||||
for (int i = 0; i < mass.length; i++)
|
||||
{
|
||||
insert_Accounting("M_Product_Acct", "M_Product_Category_Acct",
|
||||
"p.M_Product_Category_ID=" + getM_Product_Category_ID());
|
||||
insert_Tree(X_AD_Tree.TREETYPE_Product);
|
||||
//
|
||||
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID(), get_TrxName());
|
||||
for (int i = 0; i < mass.length; i++)
|
||||
{
|
||||
// Old
|
||||
MProductCosting pcOld = new MProductCosting(this, mass[i].getC_AcctSchema_ID());
|
||||
pcOld.save();
|
||||
}
|
||||
}
|
||||
|
||||
// New Costing
|
||||
if (newRecord || is_ValueChanged("M_Product_Category_ID"))
|
||||
MCost.create(this);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// New Costing
|
||||
if (newRecord || is_ValueChanged("M_Product_Category_ID"))
|
||||
MCost.create(this);
|
||||
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
|
@ -668,6 +668,31 @@ public class MProduct extends X_M_Product
|
|||
MProductCosting[] costings = MProductCosting.getOfProduct(getCtx(), get_ID(), get_TrxName());
|
||||
for (int i = 0; i < costings.length; i++)
|
||||
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");
|
||||
} // beforeDelete
|
||||
|
@ -677,11 +702,11 @@ public class MProduct extends X_M_Product
|
|||
* @param success
|
||||
* @return deleted
|
||||
*/
|
||||
protected boolean afterDelete (boolean success)
|
||||
{
|
||||
if (success)
|
||||
delete_Tree(X_AD_Tree.TREETYPE_Product);
|
||||
return success;
|
||||
} // afterDelete
|
||||
|
||||
protected boolean afterDelete (boolean success)
|
||||
{
|
||||
if (success)
|
||||
delete_Tree(X_AD_Tree.TREETYPE_Product);
|
||||
return success;
|
||||
} // afterDelete
|
||||
|
||||
} // MProduct
|
||||
|
|
Loading…
Reference in New Issue