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:
Carlos Ruiz 2024-03-16 14:28:21 +01:00
parent 2e76fbce5b
commit 96898995ec
2 changed files with 27 additions and 7 deletions

View File

@ -811,7 +811,9 @@ public class MOrder extends X_C_Order implements DocAction
line.setQtyInvoiced(Env.ZERO); line.setQtyInvoiced(Env.ZERO);
line.setQtyReserved(Env.ZERO); line.setQtyReserved(Env.ZERO);
line.setQtyLostSales(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.setDateDelivered(null);
line.setDateInvoiced(null); line.setDateInvoiced(null);
line.setOrder(this); line.setOrder(this);

View File

@ -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. * 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++) for (int i = 0; i < rates.length; i++)
{ {
MUOMConversion rate = rates[i]; MUOMConversion rate = rates[i];
if (rate.getC_UOM_To_ID() == C_UOM_To_ID) if (rate.getC_UOM_To_ID() == C_UOM_To_ID) {
return rate.getMultiplyRate(); 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 //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++) for (int i = 0; i < conversions.size(); i++)
{ {
MUOMConversion rate = conversions.get(i); MUOMConversion rate = conversions.get(i);
if (rate.getC_UOM_To_ID() == C_UOM_To_ID) if (rate.getC_UOM_To_ID() == C_UOM_To_ID) {
return rate.getMultiplyRate(); 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; return null;
} // getProductRateTo } // getProductRateTo
@ -898,6 +906,16 @@ public class MUOMConversion extends X_C_UOM_Conversion implements ImmutablePOSup
* @return {@link BigDecimal} * @return {@link BigDecimal}
*/ */
public static BigDecimal getOppositeRate(BigDecimal rate) { 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 } // UOMConversion