1003754 Landed cost issue -- related to IDEMPIERE-1285. Fix rounding issue. Fix wrong posting when estimated landed cost is more than actual landed cost.

This commit is contained in:
Heng Sin Low 2014-05-12 16:15:15 +08:00
parent 8cbea90a1b
commit cfa8050b0b
5 changed files with 57 additions and 46 deletions

View File

@ -869,13 +869,17 @@ public class Doc_Invoice extends Doc
BigDecimal qty = allocation.getQty();
if (qty.compareTo(iol.getMovementQty()) != 0)
{
amt = amt.multiply(iol.getMovementQty()).divide(qty, BigDecimal.ROUND_HALF_UP);
amt = amt.multiply(iol.getMovementQty()).divide(qty, 12, BigDecimal.ROUND_HALF_UP);
}
estimatedAmt = estimatedAmt.add(amt);
}
}
}
if (estimatedAmt.scale() > as.getCostingPrecision())
{
estimatedAmt.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
}
BigDecimal costAdjustmentAmt = allocationAmt;
if (estimatedAmt.signum() > 0)
{
@ -907,9 +911,11 @@ public class Doc_Invoice extends Doc
if (!dr)
costAdjustmentAmt = costAdjustmentAmt.negate();
boolean zeroQty = false;
if (costAdjustmentAmt.signum() != 0)
{
Trx trx = Trx.get(getTrxName(), false);
Savepoint savepoint = null;
boolean zeroQty = false;
try {
savepoint = trx.setSavepoint(null);
BigDecimal costDetailAmt = costAdjustmentAmt;
@ -946,6 +952,7 @@ public class Doc_Invoice extends Doc
} catch (SQLException e) {}
}
}
}
boolean reversal = false;
if (allocationAmt.signum() < 0) //reversal
@ -978,8 +985,8 @@ public class Doc_Invoice extends Doc
}
else if (compare < 0)
{
drAmt = dr ? (reversal ? null : allocationAmt) : (reversal ? allocationAmt : null);
crAmt = dr ? (reversal ? allocationAmt : null) : (reversal ? null : allocationAmt);
drAmt = dr ? (reversal ? null : estimatedAmt) : (reversal ? estimatedAmt : null);
crAmt = dr ? (reversal ? estimatedAmt : null) : (reversal ? null : estimatedAmt);
account = pc.getAccount(ProductCost.ACCTTYPE_P_LandedCostClearing, as);
FactLine fl = fact.createLine (line, account, getC_Currency_ID(), drAmt, crAmt);
fl.setDescription(desc);

View File

@ -508,7 +508,7 @@ public class Doc_MatchInv extends Doc
{
BigDecimal totalAmt = allocation.getAmt();
BigDecimal totalQty = allocation.getQty();
BigDecimal amt = totalAmt.multiply(tQty).divide(totalQty, BigDecimal.ROUND_HALF_UP);
BigDecimal amt = totalAmt.multiply(tQty).divide(totalQty, 12, BigDecimal.ROUND_HALF_UP);
if (orderLine.getC_Currency_ID() != as.getC_Currency_ID())
{
I_C_Order order = orderLine.getC_Order();

View File

@ -198,7 +198,7 @@ public class Doc_MatchPO extends Doc
{
BigDecimal totalAmt = allocation.getAmt();
BigDecimal totalQty = allocation.getQty();
BigDecimal amt = totalAmt.multiply(m_ioLine.getMovementQty()).divide(totalQty, as.getCostingPrecision(), RoundingMode.HALF_UP);
BigDecimal amt = totalAmt.multiply(m_ioLine.getMovementQty()).divide(totalQty, 12, RoundingMode.HALF_UP);
if (m_oLine.getC_Currency_ID() != as.getC_Currency_ID())
{
MOrder order = m_oLine.getParent();
@ -213,11 +213,11 @@ public class Doc_MatchPO extends Doc
return null;
}
amt = amt.multiply(rate);
if (amt.scale() > as.getCostingPrecision())
amt = amt.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
}
amt = amt.divide(getQty(), as.getCostingPrecision(), RoundingMode.HALF_UP);
amt = amt.divide(getQty(), 12, RoundingMode.HALF_UP);
landedCost = landedCost.add(amt);
if (landedCost.scale() > as.getCostingPrecision())
landedCost = landedCost.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
int elementId = allocation.getC_OrderLandedCost().getM_CostElement_ID();
BigDecimal elementAmt = landedCostMap.get(elementId);
if (elementAmt == null)
@ -442,6 +442,8 @@ public class Doc_MatchPO extends Doc
return error;
}
if (tAmt.scale() > as.getCostingPrecision())
tAmt = tAmt.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
// Set Total Amount and Total Quantity from Matched PO
if (!MCostDetail.createOrder(as, m_oLine.getAD_Org_ID(),
getM_Product_ID(), mMatchPO.getM_AttributeSetInstance_ID(),
@ -471,6 +473,8 @@ public class Doc_MatchPO extends Doc
{
BigDecimal amt = landedCostMap.get(elementId);
amt = amt.multiply(tQty);
if (amt.scale() > as.getCostingPrecision())
amt = amt.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
if (!MCostDetail.createOrder(as, m_oLine.getAD_Org_ID(),
getM_Product_ID(), mMatchPO.getM_AttributeSetInstance_ID(),
m_oLine.getC_OrderLine_ID(), elementId,

View File

@ -1098,7 +1098,7 @@ public class MInvoiceLine extends X_C_InvoiceLine
{
double result = getLineNetAmt().multiply(base).doubleValue();
result /= total.doubleValue();
lca.setAmt(result, getPrecision());
lca.setAmt(result, getParent().getC_Currency().getCostingPrecision());
}
if (!lca.save()){
msgreturn = new StringBuilder("Cannot save line Allocation = ").append(lca);
@ -1223,7 +1223,7 @@ public class MInvoiceLine extends X_C_InvoiceLine
{
double result = getLineNetAmt().multiply(base).doubleValue();
result /= total.doubleValue();
lca.setAmt(result, getPrecision());
lca.setAmt(result, getParent().getC_Currency().getCostingPrecision());
}
if (!lca.save()){
msgreturn = new StringBuilder("Cannot save line Allocation = ").append(lca);

View File

@ -146,8 +146,8 @@ public class MOrderLandedCost extends X_C_OrderLandedCost {
if (base.signum() != 0)
{
BigDecimal result = getAmt().multiply(base);
result = result.divide(total, orderLine.getParent().getC_Currency().getStdPrecision(), BigDecimal.ROUND_HALF_UP);
allocation.setAmt(result.doubleValue(), orderLine.getParent().getC_Currency().getStdPrecision());
result = result.divide(total, orderLine.getParent().getC_Currency().getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
allocation.setAmt(result.doubleValue(), orderLine.getParent().getC_Currency().getCostingPrecision());
}
allocation.saveEx();
}