details:   https://code.openbravo.com/erp/devel/pi/rev/fa5700b5eeb2
changeset: 33852:fa5700b5eeb2
user:      Armaignac <collazoandy4 <at> gmail.com>
date:      Mon Apr 16 15:59:24 2018 -0400
summary:   Fixes issue 38240: Wrong average cost for production products, Total 
Movement
Quantity is not correct

Wrong average cost for production products, Total Movement Quantity and Total 
Stock
Valuation is not correct because the cost for production is calculated at 
client level
and the stock and stock valuation was filtering by Legal Entity.

Now the stock and stock valuation is filtered by client level for production 
products

diffstat:

 src/org/openbravo/costing/CostingUtils.java |  26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)

diffs (64 lines):

diff -r 0d6f2565e5fc -r fa5700b5eeb2 src/org/openbravo/costing/CostingUtils.java
--- a/src/org/openbravo/costing/CostingUtils.java       Tue Apr 17 15:59:58 
2018 +0200
+++ b/src/org/openbravo/costing/CostingUtils.java       Mon Apr 16 15:59:24 
2018 -0400
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2012-2017 Openbravo SLU
+ * All portions are Copyright (C) 2012-2018 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -432,7 +432,11 @@
     if (costDimensions.get(CostDimension.Warehouse) != null) {
       select.append(" and locator." + Locator.PROPERTY_WAREHOUSE + ".id = 
:warehouse");
     }
-    select.append(" and trx." + MaterialTransaction.PROPERTY_ORGANIZATION + 
".id in (:orgs)");
+    if (product.isProduction()) {
+      select.append(" and trx." + MaterialTransaction.PROPERTY_CLIENT + ".id = 
:client");
+    } else {
+      select.append(" and trx." + MaterialTransaction.PROPERTY_ORGANIZATION + 
".id in (:orgs)");
+    }
     Query trxQry = 
OBDal.getInstance().getSession().createQuery(select.toString());
     trxQry.setParameter("product", product.getId());
     trxQry.setParameter("dateTo", dateTo);
@@ -451,7 +455,11 @@
     if (costDimensions.get(CostDimension.Warehouse) != null) {
       trxQry.setParameter("warehouse", 
costDimensions.get(CostDimension.Warehouse).getId());
     }
-    trxQry.setParameterList("orgs", orgs);
+    if (product.isProduction()) {
+      trxQry.setParameter("client", product.getClient().getId());
+    } else {
+      trxQry.setParameterList("orgs", orgs);
+    }
     BigDecimal stock = (BigDecimal) trxQry.uniqueResult();
     if (stock == null) {
       stock = BigDecimal.ZERO;
@@ -555,7 +563,11 @@
     if (costDimensions.get(CostDimension.Warehouse) != null) {
       select.append(" and locator." + Locator.PROPERTY_WAREHOUSE + ".id = 
:warehouse");
     }
-    select.append(" and trx." + MaterialTransaction.PROPERTY_ORGANIZATION + 
".id in (:orgs)");
+    if (product.isProduction()) {
+      select.append(" and trx." + MaterialTransaction.PROPERTY_CLIENT + ".id = 
:client");
+    } else {
+      select.append(" and trx." + MaterialTransaction.PROPERTY_ORGANIZATION + 
".id in (:orgs)");
+    }
     select.append(" group by tc." + TransactionCost.PROPERTY_CURRENCY + ",");
     select.append(" tc." + TransactionCost.PROPERTY_ACCOUNTINGDATE);
 
@@ -577,7 +589,11 @@
     if (costDimensions.get(CostDimension.Warehouse) != null) {
       trxQry.setParameter("warehouse", 
costDimensions.get(CostDimension.Warehouse).getId());
     }
-    trxQry.setParameterList("orgs", orgs);
+    if (product.isProduction()) {
+      trxQry.setParameter("client", product.getClient().getId());
+    } else {
+      trxQry.setParameterList("orgs", orgs);
+    }
 
     ScrollableResults scroll = trxQry.scroll(ScrollMode.FORWARD_ONLY);
     BigDecimal sum = BigDecimal.ZERO;

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to