details:   https://code.openbravo.com/erp/devel/pi/rev/1dbba4eb40f8
changeset: 34463:1dbba4eb40f8
user:      Mark <markmm82 <at> gmail.com>
date:      Wed Jul 18 17:56:03 2018 -0400
summary:   Fixes issue 38861: Fixed Create Variants if  ProductCharacteristic 
hasn't values

An empty error message was shown in Create Variants if the Product 
Characteristic
hadd Subset but not values because it was trying to iterate hover an empty 
collection
in an incorrect way.

This solution includes:
- Save in a local variable the list with the Product Characteristics to be 
processed
  to avoid calling  .list() method twice because it will repeat the same query 
and it is
  not needed.
- Avoid using a OBCriteria to get the list of ProductCharacteristicConf objects 
defined
  for the ProductCharacteristic is processing. This list is accessed directly 
from the
  object by calling the prCh.getProductCharacteristicConfList() method.
- If the processing ProductCharacteristic hasn't any configuration then it is 
not executed
  the section of code in charge of create the auxiliary information to be used 
to create
  the variants. In this way the exception throwed in the issue is not happening.
- Avoid to try to generate variants if there aren't any product characteristic 
configuration.
  The hasNext flag is initiallized with true if exists at least one variant to 
be created, and false
  in other case.
- Modified the do {} while block to use a while block and avoid create the 
first variant if any exists.

diffstat:

 src/org/openbravo/materialmgmt/VariantAutomaticGenerationProcess.java |  32 
++++-----
 1 files changed, 15 insertions(+), 17 deletions(-)

diffs (80 lines):

diff -r 3af494a7f094 -r 1dbba4eb40f8 
src/org/openbravo/materialmgmt/VariantAutomaticGenerationProcess.java
--- a/src/org/openbravo/materialmgmt/VariantAutomaticGenerationProcess.java     
Tue Jul 24 13:02:16 2018 +0200
+++ b/src/org/openbravo/materialmgmt/VariantAutomaticGenerationProcess.java     
Wed Jul 18 17:56:03 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) 2013-2015 Openbravo SLU
+ * All portions are Copyright (C) 2013-2018 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -82,22 +82,18 @@
       prChCrit.add(Restrictions.eq(ProductCharacteristic.PROPERTY_PRODUCT, 
product));
       prChCrit.add(Restrictions.eq(ProductCharacteristic.PROPERTY_VARIANT, 
true));
       prChCrit.addOrderBy(ProductCharacteristic.PROPERTY_SEQUENCENUMBER, true);
+      List<ProductCharacteristic> prChCritList = prChCrit.list();
       List<String> prChs = new ArrayList<String>();
-      for (ProductCharacteristic pc : prChCrit.list()) {
+      for (ProductCharacteristic pc : prChCritList) {
         prChs.add(pc.getId());
       }
       int chNumber = prChs.size();
       String[] currentValues = new String[chNumber];
 
       int i = 0;
-      for (ProductCharacteristic prCh : prChCrit.list()) {
-        OBCriteria<ProductCharacteristicConf> prChConfCrit = 
OBDal.getInstance().createCriteria(
-            ProductCharacteristicConf.class);
-        prChConfCrit.add(Restrictions.eq(
-            ProductCharacteristicConf.PROPERTY_CHARACTERISTICOFPRODUCT, prCh));
-
+      for (ProductCharacteristic prCh : prChCritList) {
         List<String> prChConfs = new ArrayList<String>();
-        for (ProductCharacteristicConf pcc : prChConfCrit.list()) {
+        for (ProductCharacteristicConf pcc : 
prCh.getProductCharacteristicConfList()) {
           prChConfs.add(pcc.getId());
         }
         long valuesCount = prChConfs.size();
@@ -120,21 +116,24 @@
         if (useCode) {
           totalMaxLength += maxLength;
         }
-        ProductCharacteristicAux prChAux = new 
ProductCharacteristicAux(useCode, prChConfs);
-        currentValues[i] = prChAux.getNextValue();
-        prChUseCode.put(prCh.getId(), prChAux);
-        i++;
+
+        if (!prChConfs.isEmpty()) {
+          ProductCharacteristicAux prChAux = new 
ProductCharacteristicAux(useCode, prChConfs);
+          currentValues[i] = prChAux.getNextValue();
+          prChUseCode.put(prCh.getId(), prChAux);
+          i++;
+        }
       }
       totalMaxLength += Long.toString(variantNumber).length();
       boolean useCodes = totalMaxLength <= searchKeyLength;
 
-      boolean hasNext = true;
+      boolean hasNext = variantNumber > 0;
       int productNo = 0;
       int k = 0;
       Long start = System.currentTimeMillis();
       boolean multilingualDocs = OBDal.getInstance()
           .get(Client.class, 
bundle.getContext().getClient()).isMultilingualDocuments();
-      do {
+      while (hasNext) {
         k = k + 1;
         // Create variant product
         product = OBDal.getInstance().get(Product.class, recordID);
@@ -224,8 +223,7 @@
           k = 0;
           start = System.currentTimeMillis();
         }
-
-      } while (hasNext);
+      }
 
       OBDal.getInstance().flush();
       OBDal.getInstance().getSession().clear();

------------------------------------------------------------------------------
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