Related to Issue 28301: Fix on updateBDCostingTimeRange function.
authorUnai Martirena <unai.martirena@openbravo.com>
Fri, 05 Dec 2014 08:33:57 +0100
changeset 25512 8c12e7511fd5
parent 25511 f5b046cebc71
child 25513 cd56a855a806
Related to Issue 28301: Fix on updateBDCostingTimeRange function.

If the movement date of the inventory transaction related to current costing record is before the movement date of the inventory transaction related to backdated costing record, then the backdated costing record would be the current costing record. In other case the current costing record would remain as current costing record.
src/org/openbravo/costing/AverageCostAdjustment.java
--- a/src/org/openbravo/costing/AverageCostAdjustment.java	Fri Dec 05 08:04:23 2014 +0100
+++ b/src/org/openbravo/costing/AverageCostAdjustment.java	Fri Dec 05 08:33:57 2014 +0100
@@ -761,8 +761,14 @@
 
     Costing curCosting = getTrxCurrentCosting(trx);
     if (curCosting != null) {
-      curCosting.setEndingDate(bdCosting.getEndingDate());
-      bdCosting.setEndingDate(trx.getTransactionProcessDate());
+      if (curCosting.getInventoryTransaction().getMovementDate()
+          .before(bdCosting.getInventoryTransaction().getMovementDate())) {
+        bdCosting.setEndingDate(curCosting.getEndingDate());
+        curCosting.setEndingDate(trx.getTransactionProcessDate());
+      } else {
+        curCosting.setEndingDate(bdCosting.getEndingDate());
+        bdCosting.setEndingDate(trx.getTransactionProcessDate());
+      }
       OBDal.getInstance().save(curCosting);
     } else {
       // There isn't any previous costing.