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:
parent
8cbea90a1b
commit
cfa8050b0b
|
@ -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,43 +911,46 @@ public class Doc_Invoice extends Doc
|
|||
if (!dr)
|
||||
costAdjustmentAmt = costAdjustmentAmt.negate();
|
||||
|
||||
Trx trx = Trx.get(getTrxName(), false);
|
||||
Savepoint savepoint = null;
|
||||
boolean zeroQty = false;
|
||||
try {
|
||||
savepoint = trx.setSavepoint(null);
|
||||
BigDecimal costDetailAmt = costAdjustmentAmt;
|
||||
//convert to accounting schema currency
|
||||
if (getC_Currency_ID() != as.getC_Currency_ID())
|
||||
costDetailAmt = MConversionRate.convert(getCtx(), costDetailAmt,
|
||||
getC_Currency_ID(), as.getC_Currency_ID(),
|
||||
getDateAcct(), getC_ConversionType_ID(),
|
||||
getAD_Client_ID(), getAD_Org_ID());
|
||||
if (costDetailAmt.scale() > as.getCostingPrecision())
|
||||
costDetailAmt = costDetailAmt.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
if (!MCostDetail.createInvoice(as, lca.getAD_Org_ID(),
|
||||
lca.getM_Product_ID(), lca.getM_AttributeSetInstance_ID(),
|
||||
C_InvoiceLine_ID, lca.getM_CostElement_ID(),
|
||||
costDetailAmt, lca.getQty(),
|
||||
desc, getTrxName())) {
|
||||
throw new RuntimeException("Failed to create cost detail record.");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e.getLocalizedMessage(), e);
|
||||
} catch (AverageCostingZeroQtyException e) {
|
||||
zeroQty = true;
|
||||
if (costAdjustmentAmt.signum() != 0)
|
||||
{
|
||||
Trx trx = Trx.get(getTrxName(), false);
|
||||
Savepoint savepoint = null;
|
||||
try {
|
||||
trx.rollback(savepoint);
|
||||
savepoint = null;
|
||||
} catch (SQLException e1) {
|
||||
throw new RuntimeException(e1.getLocalizedMessage(), e1);
|
||||
}
|
||||
} finally {
|
||||
if (savepoint != null) {
|
||||
savepoint = trx.setSavepoint(null);
|
||||
BigDecimal costDetailAmt = costAdjustmentAmt;
|
||||
//convert to accounting schema currency
|
||||
if (getC_Currency_ID() != as.getC_Currency_ID())
|
||||
costDetailAmt = MConversionRate.convert(getCtx(), costDetailAmt,
|
||||
getC_Currency_ID(), as.getC_Currency_ID(),
|
||||
getDateAcct(), getC_ConversionType_ID(),
|
||||
getAD_Client_ID(), getAD_Org_ID());
|
||||
if (costDetailAmt.scale() > as.getCostingPrecision())
|
||||
costDetailAmt = costDetailAmt.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
if (!MCostDetail.createInvoice(as, lca.getAD_Org_ID(),
|
||||
lca.getM_Product_ID(), lca.getM_AttributeSetInstance_ID(),
|
||||
C_InvoiceLine_ID, lca.getM_CostElement_ID(),
|
||||
costDetailAmt, lca.getQty(),
|
||||
desc, getTrxName())) {
|
||||
throw new RuntimeException("Failed to create cost detail record.");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e.getLocalizedMessage(), e);
|
||||
} catch (AverageCostingZeroQtyException e) {
|
||||
zeroQty = true;
|
||||
try {
|
||||
trx.releaseSavepoint(savepoint);
|
||||
} catch (SQLException e) {}
|
||||
trx.rollback(savepoint);
|
||||
savepoint = null;
|
||||
} catch (SQLException e1) {
|
||||
throw new RuntimeException(e1.getLocalizedMessage(), e1);
|
||||
}
|
||||
} finally {
|
||||
if (savepoint != null) {
|
||||
try {
|
||||
trx.releaseSavepoint(savepoint);
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue