IDEMPIERE-5578 Data corruption when copying order lines from a closed order (#2269)
- fix new problem reported by Martin Schönbeck - fix issue found when rounding the unit price of UOM articles
This commit is contained in:
parent
2e76fbce5b
commit
96898995ec
|
@ -811,7 +811,9 @@ public class MOrder extends X_C_Order implements DocAction
|
|||
line.setQtyInvoiced(Env.ZERO);
|
||||
line.setQtyReserved(Env.ZERO);
|
||||
line.setQtyLostSales(Env.ZERO);
|
||||
line.setQty(fromLines[i].getQtyEntered());
|
||||
line.setQtyEntered(fromLines[i].getQtyEntered());
|
||||
BigDecimal ordered = MUOMConversion.convertProductFrom (getCtx(), line.getM_Product_ID(), line.getC_UOM_ID(), line.getQtyEntered());
|
||||
line.setQtyOrdered(ordered);
|
||||
line.setDateDelivered(null);
|
||||
line.setDateInvoiced(null);
|
||||
line.setOrder(this);
|
||||
|
|
|
@ -51,7 +51,7 @@ public class MUOMConversion extends X_C_UOM_Conversion implements ImmutablePOSup
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1772365359514185604L;
|
||||
private static final long serialVersionUID = -6477844604059539239L;
|
||||
|
||||
/**
|
||||
* Convert qty to target UOM and round.
|
||||
|
@ -529,8 +529,12 @@ public class MUOMConversion extends X_C_UOM_Conversion implements ImmutablePOSup
|
|||
for (int i = 0; i < rates.length; i++)
|
||||
{
|
||||
MUOMConversion rate = rates[i];
|
||||
if (rate.getC_UOM_To_ID() == C_UOM_To_ID)
|
||||
return rate.getMultiplyRate();
|
||||
if (rate.getC_UOM_To_ID() == C_UOM_To_ID) {
|
||||
if (rate.getMultiplyRate().compareTo(Env.ONE) >= 0)
|
||||
return rate.getMultiplyRate();
|
||||
else
|
||||
return getOppositeRate(rate.getDivideRate(), 50); // get it with many decimals to minimize rounding issues
|
||||
}
|
||||
}
|
||||
|
||||
//fall back to generic conversion
|
||||
|
@ -542,8 +546,12 @@ public class MUOMConversion extends X_C_UOM_Conversion implements ImmutablePOSup
|
|||
for (int i = 0; i < conversions.size(); i++)
|
||||
{
|
||||
MUOMConversion rate = conversions.get(i);
|
||||
if (rate.getC_UOM_To_ID() == C_UOM_To_ID)
|
||||
return rate.getMultiplyRate();
|
||||
if (rate.getC_UOM_To_ID() == C_UOM_To_ID) {
|
||||
if (rate.getMultiplyRate().compareTo(Env.ONE) >= 0)
|
||||
return rate.getMultiplyRate();
|
||||
else
|
||||
return getOppositeRate(rate.getDivideRate(), 50); // get it with many decimals to minimize rounding issues
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} // getProductRateTo
|
||||
|
@ -898,6 +906,16 @@ public class MUOMConversion extends X_C_UOM_Conversion implements ImmutablePOSup
|
|||
* @return {@link BigDecimal}
|
||||
*/
|
||||
public static BigDecimal getOppositeRate(BigDecimal rate) {
|
||||
return Env.ONE.divide(rate, 12, RoundingMode.HALF_UP);
|
||||
return getOppositeRate(rate, 12);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate opposite conversion rate, i.e calculate divide rate for multiply rate and vice versa.
|
||||
* @param rate
|
||||
* @return {@link BigDecimal}
|
||||
*/
|
||||
public static BigDecimal getOppositeRate(BigDecimal rate, int scale) {
|
||||
return Env.ONE.divide(rate, scale, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
} // UOMConversion
|
||||
|
|
Loading…
Reference in New Issue