Related to Issue 28301: Fix on updateBDCostingTimeRange function.
authorUnai Martirena <unai.martirena@openbravo.com>
Fri, 05 Dec 2014 08:33:57 +0100
changeset 25624 d9a1d24601e3
parent 25623 a39bd13414a2
child 25625 9425fd00c025
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	Thu Dec 04 11:37:10 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.