IDEMPIERE-2057 Modify "Update Costing" process to create a cost adjustment document / IDEMPIERE-2306 Can't create cost detail when costing level is Batch/Lot from import inventory

This commit is contained in:
Carlos Ruiz 2014-11-11 14:19:02 -05:00
parent fe3ebcd1ae
commit ab37dd1258
7 changed files with 43 additions and 20 deletions

View File

@ -513,7 +513,7 @@ public class CostUpdate extends SvrProcess
} }
if (retValue == null) if (retValue == null)
{ {
MProduct product = MProduct.get(getCtx(), cost.getM_Product_ID()); MProduct product = new MProduct(getCtx(), cost.getM_Product_ID(), get_TrxName());
MAcctSchema as = MAcctSchema.get(getCtx(), cost.getC_AcctSchema_ID()); MAcctSchema as = MAcctSchema.get(getCtx(), cost.getC_AcctSchema_ID());
retValue = MCost.getLastInvoicePrice(product, retValue = MCost.getLastInvoicePrice(product,
cost.getM_AttributeSetInstance_ID(), cost.getAD_Org_ID(), as.getC_Currency_ID()); cost.getM_AttributeSetInstance_ID(), cost.getAD_Org_ID(), as.getC_Currency_ID());
@ -532,7 +532,7 @@ public class CostUpdate extends SvrProcess
} }
if (retValue == null) if (retValue == null)
{ {
MProduct product = MProduct.get(getCtx(), cost.getM_Product_ID()); MProduct product = new MProduct(getCtx(), cost.getM_Product_ID(), get_TrxName());
MAcctSchema as = MAcctSchema.get(getCtx(), cost.getC_AcctSchema_ID()); MAcctSchema as = MAcctSchema.get(getCtx(), cost.getC_AcctSchema_ID());
retValue = MCost.getLastPOPrice(product, retValue = MCost.getLastPOPrice(product,
cost.getM_AttributeSetInstance_ID(), cost.getAD_Org_ID(), as.getC_Currency_ID()); cost.getM_AttributeSetInstance_ID(), cost.getAD_Org_ID(), as.getC_Currency_ID());

View File

@ -400,7 +400,7 @@ public class ImportInventory extends SvrProcess
x_isInternalUse = isInternalUse; x_isInternalUse = isInternalUse;
noInsert++; noInsert++;
} }
MProduct product = MProduct.get(getCtx(), imp.getM_Product_ID()); MProduct product = new MProduct(getCtx(), imp.getM_Product_ID(), get_TrxName());
// Line // Line
int M_AttributeSetInstance_ID = 0; int M_AttributeSetInstance_ID = 0;
if ((imp.getLot() != null && imp.getLot().length() > 0) || (imp.getSerNo() != null && imp.getSerNo().length() > 0)) if ((imp.getLot() != null && imp.getLot().length() > 0) || (imp.getSerNo() != null && imp.getSerNo().length() > 0))
@ -519,10 +519,13 @@ public class ImportInventory extends SvrProcess
costASI = 0; costASI = 0;
} else if (MAcctSchema.COSTINGLEVEL_Organization.equals(costingLevel)) { } else if (MAcctSchema.COSTINGLEVEL_Organization.equals(costingLevel)) {
costASI = 0; costASI = 0;
} else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(costingLevel)) {
costOrgID = 0;
} }
MCost cost = MCost.get (MProduct.get(getCtx(), imp.getM_Product_ID()), costASI MCost cost = MCost.get (product, costASI
, acctSchema, costOrgID, p_M_CostElement_ID, get_TrxName()); , acctSchema, costOrgID, p_M_CostElement_ID, get_TrxName());
if (cost.is_new())
cost.saveEx();
if (costingDoc == null) { if (costingDoc == null) {
costingDoc = new MInventory(getCtx(), 0, get_TrxName()); costingDoc = new MInventory(getCtx(), 0, get_TrxName());
costingDoc.setC_DocType_ID(p_C_DocType_ID); costingDoc.setC_DocType_ID(p_C_DocType_ID);
@ -539,6 +542,7 @@ public class ImportInventory extends SvrProcess
costingLine.setNewCostPrice(imp.getCurrentCostPrice()); costingLine.setNewCostPrice(imp.getCurrentCostPrice());
costingLine.setM_Locator_ID(0); costingLine.setM_Locator_ID(0);
costingLine.setAD_Org_ID(imp.getAD_Org_ID()); costingLine.setAD_Org_ID(imp.getAD_Org_ID());
costingLine.setM_AttributeSetInstance_ID(costASI);
costingLine.saveEx(); costingLine.saveEx();
imp.setM_CostingLine_ID(costingLine.getM_InventoryLine_ID()); imp.setM_CostingLine_ID(costingLine.getM_InventoryLine_ID());

View File

@ -55,14 +55,10 @@ import org.compiere.util.Trx;
*/ */
public class MCost extends X_M_Cost public class MCost extends X_M_Cost
{ {
/**
*
*/
/** private static final long serialVersionUID = -8904980122276406878L;
*
*/
private static final long serialVersionUID = -127982599769472918L;
/** /**
* Retrieve/Calculate Current Cost Price * Retrieve/Calculate Current Cost Price
@ -1520,6 +1516,19 @@ public class MCost extends X_M_Cost
setCurrentQty(getCurrentQty().add(qty)); setCurrentQty(getCurrentQty().add(qty));
} // setWeightedAverage } // setWeightedAverage
/**
* @param amt unit amt
*/
public void setWeightedAverageInitial (BigDecimal amtUnit)
{
BigDecimal cost = amtUnit;
if (cost.scale() > (getPrecision()*2))
{
cost = cost.setScale((getPrecision()*2), BigDecimal.ROUND_HALF_UP);
}
setCurrentCostPrice(cost);
} // setWeightedAverageInitial
/** /**
* Get Costing Precision * Get Costing Precision
* @return precision (6) * @return precision (6)

View File

@ -833,7 +833,7 @@ public class MCostDetail extends X_M_CostDetail
// get costing level for product // get costing level for product
MAcctSchema as = MAcctSchema.get(getCtx(), getC_AcctSchema_ID()); MAcctSchema as = MAcctSchema.get(getCtx(), getC_AcctSchema_ID());
MProduct product = MProduct.get(getCtx(), getM_Product_ID()); MProduct product = new MProduct(getCtx(), getM_Product_ID(), get_TrxName());
String CostingLevel = product.getCostingLevel(as); String CostingLevel = product.getCostingLevel(as);
// Org Element // Org Element
int Org_ID = getAD_Org_ID(); int Org_ID = getAD_Org_ID();
@ -1152,7 +1152,12 @@ public class MCostDetail extends X_M_CostDetail
costingMethod = getM_InventoryLine().getM_Inventory().getCostingMethod(); costingMethod = getM_InventoryLine().getM_Inventory().getCostingMethod();
if (MCostElement.COSTINGMETHOD_AverageInvoice.equals(costingMethod)) if (MCostElement.COSTINGMETHOD_AverageInvoice.equals(costingMethod))
{ {
cost.setWeightedAverage(amt.multiply(cost.getCurrentQty()), qty); if (cost.getCurrentQty().signum() == 0 && qty.signum() == 0) {
// IDEMPIERE-2057 - this is a cost adjustment when there is no qty - setting the initial cost
cost.setWeightedAverageInitial(amt);
} else {
cost.setWeightedAverage(amt.multiply(cost.getCurrentQty()), qty);
}
} }
} }
else if (addition) else if (addition)
@ -1177,7 +1182,12 @@ public class MCostDetail extends X_M_CostDetail
costingMethod = getM_InventoryLine().getM_Inventory().getCostingMethod(); costingMethod = getM_InventoryLine().getM_Inventory().getCostingMethod();
if (MCostElement.COSTINGMETHOD_AveragePO.equals(costingMethod)) if (MCostElement.COSTINGMETHOD_AveragePO.equals(costingMethod))
{ {
cost.setWeightedAverage(amt.multiply(cost.getCurrentQty()), qty); if (cost.getCurrentQty().signum() == 0 && qty.signum() == 0) {
// IDEMPIERE-2057 - this is a cost adjustment when there is no qty - setting the initial cost
cost.setWeightedAverageInitial(amt);
} else {
cost.setWeightedAverage(amt.multiply(cost.getCurrentQty()), qty);
}
} }
} }
else if (addition) else if (addition)

View File

@ -353,7 +353,7 @@ public class MInventoryLine extends X_M_InventoryLine
} }
int M_ASI_ID = getM_AttributeSetInstance_ID(); int M_ASI_ID = getM_AttributeSetInstance_ID();
MProduct product = getProduct(); MProduct product = new MProduct(getCtx(), getM_Product_ID(), get_TrxName());
MClient client = MClient.get(getCtx()); MClient client = MClient.get(getCtx());
MAcctSchema as = client.getAcctSchema(); MAcctSchema as = client.getAcctSchema();
String costingLevel = product.getCostingLevel(as); String costingLevel = product.getCostingLevel(as);

View File

@ -910,7 +910,7 @@ public class MProduct extends X_M_Product
if (ce == null) { if (ce == null) {
return null; return null;
} }
MCost cost = MCost.get(this, M_ASI_ID, as, AD_Org_ID, ce.getM_CostElement_ID(), (String)null); MCost cost = MCost.get(this, M_ASI_ID, as, AD_Org_ID, ce.getM_CostElement_ID(), get_TrxName());
return cost.is_new() ? null : cost; return cost.is_new() ? null : cost;
} }
} // MProduct } // MProduct

View File

@ -48,7 +48,7 @@ public class ProductCost
{ {
m_M_Product_ID = M_Product_ID; m_M_Product_ID = M_Product_ID;
if (m_M_Product_ID != 0) if (m_M_Product_ID != 0)
m_product = MProduct.get (ctx, M_Product_ID); m_product = new MProduct(ctx, M_Product_ID, trxName);
m_M_AttributeSetInstance_ID = M_AttributeSetInstance_ID; m_M_AttributeSetInstance_ID = M_AttributeSetInstance_ID;
m_trxName = trxName; m_trxName = trxName;
} // ProductCost } // ProductCost