Fixes BUG-42398: When validating a new costing rule, physical inventories should
authorArmaignac <collazoandy4@gmail.com>
Thu, 05 Dec 2019 15:06:14 +0100
changeset 36846 4f441ebb434f
parent 36845 7452c8180172
child 36847 f45e0aa5902d
Fixes BUG 42398: When validating a new costing rule, physical inventories should
be created in the warehouse's organization

The warehouse organization is not taked into account when the inventory count is created
in the costing rule validation process

Now the warehouse organization is used to create the physical inventories when validating
a new costing rule
src/org/openbravo/costing/CostingRuleProcess.java
--- a/src/org/openbravo/costing/CostingRuleProcess.java	Thu Dec 05 08:21:58 2019 +0100
+++ b/src/org/openbravo/costing/CostingRuleProcess.java	Thu Dec 05 15:06:14 2019 +0100
@@ -496,11 +496,13 @@
     }
     String clientId = rule.getClient().getId();
     String orgId = rule.getOrganization().getId();
+    Warehouse warehouse = (Warehouse) OBDal.getInstance()
+        .getProxy(Warehouse.ENTITY_NAME, warehouseId);
     CostingRuleInit cri = OBProvider.getInstance().get(CostingRuleInit.class);
     cri.setClient((Client) OBDal.getInstance().getProxy(Client.ENTITY_NAME, clientId));
     cri.setOrganization(
         (Organization) OBDal.getInstance().getProxy(Organization.ENTITY_NAME, orgId));
-    cri.setWarehouse((Warehouse) OBDal.getInstance().getProxy(Warehouse.ENTITY_NAME, warehouseId));
+    cri.setWarehouse(warehouse);
     cri.setCostingRule(rule);
     List<CostingRuleInit> criList = rule.getCostingRuleInitList();
     criList.add(cri);
@@ -508,22 +510,18 @@
 
     InventoryCount closeInv = OBProvider.getInstance().get(InventoryCount.class);
     closeInv.setClient((Client) OBDal.getInstance().getProxy(Client.ENTITY_NAME, clientId));
-    closeInv.setOrganization(
-        (Organization) OBDal.getInstance().getProxy(Organization.ENTITY_NAME, orgId));
+    closeInv.setOrganization(warehouse.getOrganization());
     closeInv.setName(OBMessageUtils.messageBD("CostCloseInventory"));
-    closeInv
-        .setWarehouse((Warehouse) OBDal.getInstance().getProxy(Warehouse.ENTITY_NAME, warehouseId));
+    closeInv.setWarehouse(warehouse);
     closeInv.setMovementDate(localDate);
     closeInv.setInventoryType("C");
     cri.setCloseInventory(closeInv);
 
     InventoryCount initInv = OBProvider.getInstance().get(InventoryCount.class);
     initInv.setClient((Client) OBDal.getInstance().getProxy(Client.ENTITY_NAME, clientId));
-    initInv.setOrganization(
-        (Organization) OBDal.getInstance().getProxy(Organization.ENTITY_NAME, orgId));
+    initInv.setOrganization(warehouse.getOrganization());
     initInv.setName(OBMessageUtils.messageBD("CostInitInventory"));
-    initInv
-        .setWarehouse((Warehouse) OBDal.getInstance().getProxy(Warehouse.ENTITY_NAME, warehouseId));
+    initInv.setWarehouse(warehouse);
     initInv.setMovementDate(localDate);
     initInv.setInventoryType("O");
     cri.setInitInventory(initInv);