Fixes bug 29836: Avoid creating unnecessary backdated adjustments.
authorUnai Martirena <unai.martirena@openbravo.com>
Mon, 11 May 2015 10:15:38 +0200
changeset 26690 a76de5445a7f
parent 26689 91d01b8f8436
child 26691 26d39e051d58
Fixes bug 29836: Avoid creating unnecessary backdated adjustments.

The problem was happening when costing precision was different from standard precision. When calculating the expected cost of a transaction to know if an adjustment is necessary to be created, it has to be rounded to standard precision because the amounts always have to be created in standard precision. In this case, while comparing expected cost with actual cost from database, as in database values are rounded to standard precision, and expected cost was being rounded to cost precission, an adjustment was being created with the difference, that corresponds just to the precision lost, and finally an adjustment of Zero amount was being created.
src/org/openbravo/costing/AverageCostAdjustment.java
--- a/src/org/openbravo/costing/AverageCostAdjustment.java	Wed May 06 11:09:24 2015 +0200
+++ b/src/org/openbravo/costing/AverageCostAdjustment.java	Mon May 11 10:15:38 2015 +0200
@@ -352,7 +352,7 @@
           if (!trx.isCostPermanent()) {
             // Check current trx unit cost matches new expected cost
             BigDecimal expectedCost = cost.multiply(trx.getMovementQuantity().abs()).setScale(
-                costCurPrecission, RoundingMode.HALF_UP);
+                stdCurPrecission, RoundingMode.HALF_UP);
             BigDecimal unitCost = CostAdjustmentUtils.getTrxCost(trx, true, OBDal.getInstance()
                 .get(Currency.class, strCurrentCurId));
             unitCost = unitCost.add(trxAdjAmt);