IDEMPIERE-3014 Landed Costs - Wrong GL posting involving multiple foreign currencies

This commit is contained in:
Heng Sin Low 2017-03-06 18:21:05 +08:00
parent 8c099ff144
commit b6421ec51f
1 changed files with 27 additions and 2 deletions

View File

@ -21,6 +21,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@ -901,11 +902,16 @@ public class Doc_Invoice extends Doc
BigDecimal allocationAmt = lca.getAmt();
BigDecimal estimatedAmt = BigDecimal.ZERO;
int oCurrencyId = 0;
boolean usesSchemaCurrency = false;
Timestamp oDateAcct = getDateAcct();
if (lca.getM_InOutLine_ID() > 0)
{
I_M_InOutLine iol = lca.getM_InOutLine();
if (iol.getC_OrderLine_ID() > 0)
{
oCurrencyId = iol.getC_OrderLine().getC_Currency_ID();
oDateAcct = iol.getC_OrderLine().getC_Order().getDateAcct();
MOrderLandedCostAllocation[] allocations = MOrderLandedCostAllocation.getOfOrderLine(iol.getC_OrderLine_ID(), getTrxName());
for(MOrderLandedCostAllocation allocation : allocations)
{
@ -946,6 +952,23 @@ public class Doc_Invoice extends Doc
estimatedAmt = estimatedAmt.add(allocationAmt.negate());
}
}
//added for IDEMPIERE-3014
//convert to accounting schema currency
if (estimatedAmt.signum() > 0 && oCurrencyId != getC_Currency_ID())
{
estimatedAmt = MConversionRate.convert(getCtx(), estimatedAmt,
oCurrencyId, as.getC_Currency_ID(),
oDateAcct, getC_ConversionType_ID(),
getAD_Client_ID(), getAD_Org_ID());
allocationAmt = MConversionRate.convert(getCtx(), allocationAmt,
getC_Currency_ID(), as.getC_Currency_ID(),
getDateAcct(), getC_ConversionType_ID(),
getAD_Client_ID(), getAD_Org_ID());
setC_Currency_ID(as.getC_Currency_ID());
usesSchemaCurrency = true;
}
if (estimatedAmt.signum() > 0)
{
if (allocationAmt.signum() > 0)
@ -1074,6 +1097,8 @@ public class Doc_Invoice extends Doc
fl.setQty(line.getQty());
}
}
if (usesSchemaCurrency)
setC_Currency_ID(line.getC_Currency_ID());
}
else
{