Fixes bug 28509: Inventory Amt Update now works with negative stock.
authorUnai Martirena <unai.martirena@openbravo.com>
Wed, 31 Dec 2014 13:50:58 +0100
changeset 25710 5d9b7b151669
parent 25709 e087d572eed7
child 25711 2161bdf91225
Fixes bug 28509: Inventory Amt Update now works with negative stock.

In this case the Qty Count and Qty Book have been reverted in the Physical Inventory Lines and negate them to make them positive, maintaining the difference between them to create the same transaction quantity.

Also getInventoryClosingCost function in AverageAlgorithm has been changed to negate the cost obtained from an inventory closing when the movement qty is positive (closing from negative to 0), because the cost obtained was negative, and this is wrong.
src/org/openbravo/costing/AverageAlgorithm.java
src/org/openbravo/costing/InventoryAmountUpdateProcess.java
--- a/src/org/openbravo/costing/AverageAlgorithm.java	Wed Dec 31 11:03:15 2014 +0100
+++ b/src/org/openbravo/costing/AverageAlgorithm.java	Wed Dec 31 13:50:58 2014 +0100
@@ -104,6 +104,9 @@
         transaction.getProduct(), costOrg, transaction.getMovementDate(), costDimensions,
         transaction.getStorageBin(), transaction.getAttributeSetValue(), costCurrency,
         costingRule.isBackdatedTransactionsFixed());
+    if (transaction.getMovementQuantity().signum() == 1) {
+      cost = cost.negate();
+    }
     return cost;
   }
 
--- a/src/org/openbravo/costing/InventoryAmountUpdateProcess.java	Wed Dec 31 11:03:15 2014 +0100
+++ b/src/org/openbravo/costing/InventoryAmountUpdateProcess.java	Wed Dec 31 13:50:58 2014 +0100
@@ -220,10 +220,10 @@
         } else {
           openInventoryLine = insertInventoryLine(inv.getInitInventory(),
               line.getProduct().getId(), attrSetInsId, uomId, orderUOMId, locatorId,
-              BigDecimal.ZERO, qty, BigDecimal.ZERO, orderQty == null ? null : orderQty, lineNo,
-              closingInventoryLine, line.getUnitCost());
+              BigDecimal.ZERO, qty.negate(), BigDecimal.ZERO, orderQty == null ? null : orderQty,
+              lineNo, closingInventoryLine, line.getUnitCost());
           insertInventoryLine(inv.getCloseInventory(), line.getProduct().getId(), attrSetInsId,
-              uomId, orderUOMId, locatorId, qty == null ? null : qty, BigDecimal.ZERO,
+              uomId, orderUOMId, locatorId, qty == null ? null : qty.negate(), BigDecimal.ZERO,
               orderQty == null ? null : orderQty, BigDecimal.ZERO, lineNo, openInventoryLine, null);
 
         }