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:
parent
fe3ebcd1ae
commit
ab37dd1258
|
@ -513,7 +513,7 @@ public class CostUpdate extends SvrProcess
|
|||
}
|
||||
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());
|
||||
retValue = MCost.getLastInvoicePrice(product,
|
||||
cost.getM_AttributeSetInstance_ID(), cost.getAD_Org_ID(), as.getC_Currency_ID());
|
||||
|
@ -532,7 +532,7 @@ public class CostUpdate extends SvrProcess
|
|||
}
|
||||
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());
|
||||
retValue = MCost.getLastPOPrice(product,
|
||||
cost.getM_AttributeSetInstance_ID(), cost.getAD_Org_ID(), as.getC_Currency_ID());
|
||||
|
|
|
@ -400,7 +400,7 @@ public class ImportInventory extends SvrProcess
|
|||
x_isInternalUse = isInternalUse;
|
||||
noInsert++;
|
||||
}
|
||||
MProduct product = MProduct.get(getCtx(), imp.getM_Product_ID());
|
||||
MProduct product = new MProduct(getCtx(), imp.getM_Product_ID(), get_TrxName());
|
||||
// Line
|
||||
int M_AttributeSetInstance_ID = 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;
|
||||
} else if (MAcctSchema.COSTINGLEVEL_Organization.equals(costingLevel)) {
|
||||
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());
|
||||
|
||||
if (cost.is_new())
|
||||
cost.saveEx();
|
||||
if (costingDoc == null) {
|
||||
costingDoc = new MInventory(getCtx(), 0, get_TrxName());
|
||||
costingDoc.setC_DocType_ID(p_C_DocType_ID);
|
||||
|
@ -539,6 +542,7 @@ public class ImportInventory extends SvrProcess
|
|||
costingLine.setNewCostPrice(imp.getCurrentCostPrice());
|
||||
costingLine.setM_Locator_ID(0);
|
||||
costingLine.setAD_Org_ID(imp.getAD_Org_ID());
|
||||
costingLine.setM_AttributeSetInstance_ID(costASI);
|
||||
costingLine.saveEx();
|
||||
|
||||
imp.setM_CostingLine_ID(costingLine.getM_InventoryLine_ID());
|
||||
|
|
|
@ -55,14 +55,10 @@ import org.compiere.util.Trx;
|
|||
*/
|
||||
public class MCost extends X_M_Cost
|
||||
{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -127982599769472918L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -8904980122276406878L;
|
||||
|
||||
/**
|
||||
* Retrieve/Calculate Current Cost Price
|
||||
|
@ -1520,6 +1516,19 @@ public class MCost extends X_M_Cost
|
|||
setCurrentQty(getCurrentQty().add(qty));
|
||||
} // 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
|
||||
* @return precision (6)
|
||||
|
|
|
@ -833,7 +833,7 @@ public class MCostDetail extends X_M_CostDetail
|
|||
|
||||
// get costing level for product
|
||||
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);
|
||||
// Org Element
|
||||
int Org_ID = getAD_Org_ID();
|
||||
|
@ -1152,7 +1152,12 @@ public class MCostDetail extends X_M_CostDetail
|
|||
costingMethod = getM_InventoryLine().getM_Inventory().getCostingMethod();
|
||||
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)
|
||||
|
@ -1177,7 +1182,12 @@ public class MCostDetail extends X_M_CostDetail
|
|||
costingMethod = getM_InventoryLine().getM_Inventory().getCostingMethod();
|
||||
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)
|
||||
|
|
|
@ -353,7 +353,7 @@ public class MInventoryLine extends X_M_InventoryLine
|
|||
}
|
||||
|
||||
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());
|
||||
MAcctSchema as = client.getAcctSchema();
|
||||
String costingLevel = product.getCostingLevel(as);
|
||||
|
|
|
@ -910,7 +910,7 @@ public class MProduct extends X_M_Product
|
|||
if (ce == 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;
|
||||
}
|
||||
} // MProduct
|
||||
|
|
|
@ -48,7 +48,7 @@ public class ProductCost
|
|||
{
|
||||
m_M_Product_ID = M_Product_ID;
|
||||
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_trxName = trxName;
|
||||
} // ProductCost
|
||||
|
|
Loading…
Reference in New Issue