details:   https://code.openbravo.com/erp/devel/pi/rev/1939f4cf8828
changeset: 24055:1939f4cf8828
user:      Daniel Ruiz <daniel.ruiz <at> openbravo.com>
date:      Thu Jul 10 18:12:58 2014 +0200
summary:   Fixes Issue 26553: ActualAmount (Details tab,Commission Payment) is 
wrong calculated

details:   https://code.openbravo.com/erp/devel/pi/rev/c563d84563da
changeset: 24056:c563d84563da
user:      Daniel Ruiz <daniel.ruiz <at> openbravo.com>
date:      Tue Jul 15 11:02:51 2014 +0200
summary:   Fixes Issue 26867:manage variants process causes server crash

diffstat:

 src-db/database/model/functions/C_COMMISSION_PROCESS.xml              |   2 +-
 src-db/database/sourcedata/OBUIAPP_PARAMETER.xml                      |   1 +
 src/org/openbravo/materialmgmt/ManageVariantsDS.java                  |   4 +
 src/org/openbravo/materialmgmt/VariantAutomaticGenerationProcess.java |  61 
+++++++--
 web/js/productCharacteristicsProcess.js                               |  13 +-
 5 files changed, 63 insertions(+), 18 deletions(-)

diffs (234 lines):

diff -r 571b30a93645 -r c563d84563da 
src-db/database/model/functions/C_COMMISSION_PROCESS.xml
--- a/src-db/database/model/functions/C_COMMISSION_PROCESS.xml  Thu Jul 17 
10:29:50 2014 +0200
+++ b/src-db/database/model/functions/C_COMMISSION_PROCESS.xml  Tue Jul 15 
11:02:51 2014 +0200
@@ -259,7 +259,7 @@
               || 'CASE WHEN (COST.cost is null AND prd.ISSTOCKED=''Y'' AND 
prd.PRODUCTTYPE=''I'') THEN 0 '
               || 'WHEN (M_GET_NO_TRX_PRODUCT_COST(prd.M_PRODUCT_ID, 
h.DATEINVOICED, ''STA'', h.ad_org_id, null, h.C_CURRENCY_ID) is null AND 
(prd.ISSTOCKED=''N'' OR prd.PRODUCTTYPE<>''I'')) THEN 0 '
               || 'ELSE CASE WHEN dt.docbasetype IN (''ARC'',''APC'') THEN -1 
ELSE 1 END '
-              || '     * CASE WHEN (prd.ISSTOCKED=''Y'' AND 
prd.PRODUCTTYPE=''I'') THEN l.linenetamt - 
(qtyinvoiced*(COST.cost/(-1*m_transaction.movementqty))) ELSE l.linenetamt - 
(M_GET_NO_TRX_PRODUCT_COST(prd.M_PRODUCT_ID, h.DATEINVOICED, ''STA'', 
h.ad_org_id, null, h.C_CURRENCY_ID)*l.QTYINVOICED) END '
+              || '     * CASE WHEN ( prd.isstocked = ''Y'' AND prd.producttype 
= ''I'' ) THEN CASE WHEN dt.docbasetype=''ARI_RM'' THEN l.linenetamt + ( 
qtyinvoiced * (COST.cost / ( -1 * m_transaction.movementqty ) ) ) ELSE 
l.linenetamt - ( qtyinvoiced * (COST.cost / ( -1 * m_transaction.movementqty ) 
) ) END ELSE l.linenetamt - (M_get_no_trx_product_cost(prd.m_product_id, 
h.dateinvoiced, ''STA'', h.ad_org_id, NULL, h.c_currency_id) * l.qtyinvoiced ) 
END '
               || 'END AS margin, '
               || 'CASE WHEN dt.docbasetype IN (''ARC'',''APC'') THEN -1 ELSE 1 
END * l.QtyInvoiced, '
               || 'NULL, l.C_InvoiceLine_ID, h.DocumentNo, 
substr(COALESCE(prd.Name,l.Description),1,60), '
diff -r 571b30a93645 -r c563d84563da 
src-db/database/sourcedata/OBUIAPP_PARAMETER.xml
--- a/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml  Thu Jul 17 10:29:50 
2014 +0200
+++ b/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml  Tue Jul 15 11:02:51 
2014 +0200
@@ -208,6 +208,7 @@
 <!--6B15654D49A4408DBC25E63836D02199-->  
<STARTINNEWLINE><![CDATA[N]]></STARTINNEWLINE>
 <!--6B15654D49A4408DBC25E63836D02199-->  
<DISPLAYEDROWS><![CDATA[5]]></DISPLAYEDROWS>
 <!--6B15654D49A4408DBC25E63836D02199-->  
<DISPLAYTITLE><![CDATA[N]]></DISPLAYTITLE>
+<!--6B15654D49A4408DBC25E63836D02199-->  
<ONGRIDLOADFUNCTION><![CDATA[OB.ProductCharacteristics.TestOnGridLoad]]></ONGRIDLOADFUNCTION>
 <!--6B15654D49A4408DBC25E63836D02199--></OBUIAPP_PARAMETER>
 
 <!--6B8309393CF44CCD977219C72458D625--><OBUIAPP_PARAMETER>
diff -r 571b30a93645 -r c563d84563da 
src/org/openbravo/materialmgmt/ManageVariantsDS.java
--- a/src/org/openbravo/materialmgmt/ManageVariantsDS.java      Thu Jul 17 
10:29:50 2014 +0200
+++ b/src/org/openbravo/materialmgmt/ManageVariantsDS.java      Tue Jul 15 
11:02:51 2014 +0200
@@ -127,6 +127,10 @@
         prChUseCode.put(prCh, prChAux);
         i++;
       }
+
+      if (variantNumber > 1000) {
+        return result;
+      }
       totalMaxLength += Long.toString(variantNumber).length();
       boolean useCodes = totalMaxLength <= searchKeyLength;
 
diff -r 571b30a93645 -r c563d84563da 
src/org/openbravo/materialmgmt/VariantAutomaticGenerationProcess.java
--- a/src/org/openbravo/materialmgmt/VariantAutomaticGenerationProcess.java     
Thu Jul 17 10:29:50 2014 +0200
+++ b/src/org/openbravo/materialmgmt/VariantAutomaticGenerationProcess.java     
Tue Jul 15 11:02:51 2014 +0200
@@ -19,7 +19,9 @@
 package org.openbravo.materialmgmt;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -67,22 +69,25 @@
     try {
       // retrieve standard params
       final String recordID = (String) bundle.getParams().get("M_Product_ID");
-      final Product product = OBDal.getInstance().get(Product.class, recordID);
+      Product product = OBDal.getInstance().get(Product.class, recordID);
 
       runChecks(product);
 
       int totalMaxLength = product.getSearchKey().length();
       long variantNumber = 1;
-      Map<ProductCharacteristic, ProductCharacteristicAux> prChUseCode = new 
HashMap<ProductCharacteristic, ProductCharacteristicAux>();
+      Map<String, ProductCharacteristicAux> prChUseCode = new HashMap<String, 
ProductCharacteristicAux>();
 
       OBCriteria<ProductCharacteristic> prChCrit = 
OBDal.getInstance().createCriteria(
           ProductCharacteristic.class);
       prChCrit.add(Restrictions.eq(ProductCharacteristic.PROPERTY_PRODUCT, 
product));
       prChCrit.add(Restrictions.eq(ProductCharacteristic.PROPERTY_VARIANT, 
true));
       prChCrit.addOrderBy(ProductCharacteristic.PROPERTY_SEQUENCENUMBER, true);
-      List<ProductCharacteristic> prChs = prChCrit.list();
+      List<String> prChs = new ArrayList<String>();
+      for (ProductCharacteristic pc : prChCrit.list()) {
+        prChs.add(pc.getId());
+      }
       int chNumber = prChs.size();
-      ProductCharacteristicConf[] currentValues = new 
ProductCharacteristicConf[chNumber];
+      String[] currentValues = new String[chNumber];
 
       int i = 0;
       for (ProductCharacteristic prCh : prChCrit.list()) {
@@ -90,12 +95,18 @@
             ProductCharacteristicConf.class);
         prChConfCrit.add(Restrictions.eq(
             ProductCharacteristicConf.PROPERTY_CHARACTERISTICOFPRODUCT, prCh));
-        List<ProductCharacteristicConf> prChConfs = prChConfCrit.list();
+
+        List<String> prChConfs = new ArrayList<String>();
+        for (ProductCharacteristicConf pcc : prChConfCrit.list()) {
+          prChConfs.add(pcc.getId());
+        }
         long valuesCount = prChConfs.size();
 
         boolean useCode = true;
         int maxLength = 0;
-        for (ProductCharacteristicConf prChConf : prChConfs) {
+        for (String id : prChConfs) {
+          ProductCharacteristicConf prChConf = OBDal.getInstance().get(
+              ProductCharacteristicConf.class, id);
           if (StringUtils.isBlank(prChConf.getCode())) {
             useCode = false;
             break;
@@ -111,7 +122,7 @@
         }
         ProductCharacteristicAux prChAux = new 
ProductCharacteristicAux(useCode, prChConfs);
         currentValues[i] = prChAux.getNextValue();
-        prChUseCode.put(prCh, prChAux);
+        prChUseCode.put(prCh.getId(), prChAux);
         i++;
       }
       totalMaxLength += Long.toString(variantNumber).length();
@@ -119,8 +130,12 @@
 
       boolean hasNext = true;
       int productNo = 0;
+      int k = 0;
+      Long start = new Date().getTime();
       do {
+        k = k + 1;
         // Create variant product
+        product = OBDal.getInstance().get(Product.class, recordID);
         Product variant = (Product) DalUtil.copy(product);
 
         variant.setGenericProduct(product);
@@ -132,7 +147,8 @@
 
         String searchKey = product.getSearchKey();
         for (i = 0; i < chNumber; i++) {
-          ProductCharacteristicConf prChConf = currentValues[i];
+          ProductCharacteristicConf prChConf = OBDal.getInstance().get(
+              ProductCharacteristicConf.class, currentValues[i]);
           ProductCharacteristicAux prChConfAux = prChUseCode.get(prChs.get(i));
 
           if (useCodes && prChConfAux.isUseCode()) {
@@ -146,10 +162,10 @@
         searchKey += productNo;
         variant.setSearchKey(searchKey);
         OBDal.getInstance().save(variant);
-        OBDal.getInstance().flush();
 
         for (i = 0; i < chNumber; i++) {
-          ProductCharacteristicConf prChConf = currentValues[i];
+          ProductCharacteristicConf prChConf = OBDal.getInstance().get(
+              ProductCharacteristicConf.class, currentValues[i]);
           ProductCharacteristicValue newPrChValue = 
OBProvider.getInstance().get(
               ProductCharacteristicValue.class);
           
newPrChValue.setCharacteristic(prChConf.getCharacteristicOfProduct().getCharacteristic());
@@ -168,7 +184,6 @@
           }
         }
         OBDal.getInstance().save(variant);
-        OBDal.getInstance().flush();
         new VariantChDescUpdateProcess().update(variant.getId(), null);
 
         for (i = 0; i < chNumber; i++) {
@@ -181,8 +196,22 @@
           }
         }
         productNo++;
+
+        // Create variants from 1 to 1000.
+        if (k == 1000) {
+          OBDal.getInstance().flush();
+          OBDal.getInstance().getSession().clear();
+          log4j.error("dentro bucle variants: " + productNo + " : "
+              + ((new Date().getTime()) - (start)));
+          k = 0;
+          start = new Date().getTime();
+        }
+
       } while (hasNext);
 
+      OBDal.getInstance().flush();
+      OBDal.getInstance().getSession().clear();
+
       String message = OBMessageUtils.messageBD("variantsCreated");
       Map<String, String> map = new HashMap<String, String>();
       map.put("variantNo", Long.toString(productNo));
@@ -268,10 +297,10 @@
   private static class ProductCharacteristicAux {
     private boolean useCode;
     private boolean isIteratorReset;
-    private List<ProductCharacteristicConf> values;
-    private Iterator<ProductCharacteristicConf> iterator;
+    private List<String> values;
+    private Iterator<String> iterator;
 
-    ProductCharacteristicAux(boolean _useCode, List<ProductCharacteristicConf> 
_values) {
+    ProductCharacteristicAux(boolean _useCode, List<String> _values) {
       useCode = _useCode;
       values = _values;
     }
@@ -284,8 +313,8 @@
       return isIteratorReset;
     }
 
-    public ProductCharacteristicConf getNextValue() {
-      ProductCharacteristicConf prChConf;
+    public String getNextValue() {
+      String prChConf;
       if (iterator == null || !iterator.hasNext()) {
         iterator = values.iterator();
         isIteratorReset = true;
diff -r 571b30a93645 -r c563d84563da web/js/productCharacteristicsProcess.js
--- a/web/js/productCharacteristicsProcess.js   Thu Jul 17 10:29:50 2014 +0200
+++ b/web/js/productCharacteristicsProcess.js   Tue Jul 15 11:02:51 2014 +0200
@@ -50,9 +50,19 @@
     params.processId = 'A832A5DA28FB4BB391BDE883E928DFC5';
     params.action = 'INITIALIZE';
     OB.ProductCharacteristics.execute(params, view);
-  }
+  },
+  
+  TestOnGridLoad: function (grid) {
+         var nRecordsReceived = grid.getData().getLength(),
+             messageBar = grid.view.messageBar;
+         if (nRecordsReceived==0){
+                 messageBar.setMessage('info', 'The number of records is too 
high. Please, try to review product characteristics.');
+         }
+         //messageBar.setMessage('info', 'The number of records is too high. 
Please, try to review product characteristics.');
+       },
 };
 
+
 isc.defineClass('UpdateInvariantCharacteristicsPopup', isc.OBPopup);
 
 // This popup will show a combo for each of the product invariant
@@ -77,6 +87,7 @@
         params = this.params,
         i;
 
+        
     // Populates the combos using the provided characteristicList
     this.characteristicCombos = [];
     for (i = 0; i < this.characteristicList.length; i++) {

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to