diff --git a/src-db/database/sourcedata/AD_COLUMN.xml b/src-db/database/sourcedata/AD_COLUMN.xml
--- a/src-db/database/sourcedata/AD_COLUMN.xml
+++ b/src-db/database/sourcedata/AD_COLUMN.xml
@@ -337847,6 +337847,7 @@
+
diff --git a/src-db/database/sourcedata/AD_FIELD.xml b/src-db/database/sourcedata/AD_FIELD.xml
--- a/src-db/database/sourcedata/AD_FIELD.xml
+++ b/src-db/database/sourcedata/AD_FIELD.xml
@@ -191411,6 +191411,7 @@
+
diff --git a/src-db/database/model/views/M_PRODCHVIEW_V.xml b/src-db/database/model/views/M_PRODCHVIEW_V.xml
new file mode 100644
--- /dev/null
+++ b/src-db/database/model/views/M_PRODCHVIEW_V.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/src-db/database/sourcedata/AD_COLUMN.xml b/src-db/database/sourcedata/AD_COLUMN.xml
--- a/src-db/database/sourcedata/AD_COLUMN.xml
+++ b/src-db/database/sourcedata/AD_COLUMN.xml
@@ -226358,6 +226358,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -227744,6 +227780,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -231930,6 +231999,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -232178,6 +232281,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -233455,6 +233593,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -234061,6 +234232,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -234809,6 +235014,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -236165,6 +236405,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -236411,6 +236686,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -243078,6 +243388,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -275843,6 +276187,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -289268,6 +289647,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -307372,6 +307786,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -309373,6 +309824,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -318046,6 +318530,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -334936,6 +335457,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -336891,6 +337448,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -337249,6 +337841,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src-db/database/sourcedata/AD_ELEMENT.xml b/src-db/database/sourcedata/AD_ELEMENT.xml
--- a/src-db/database/sourcedata/AD_ELEMENT.xml
+++ b/src-db/database/sourcedata/AD_ELEMENT.xml
@@ -21684,6 +21684,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src-db/database/sourcedata/AD_FIELD.xml b/src-db/database/sourcedata/AD_FIELD.xml
--- a/src-db/database/sourcedata/AD_FIELD.xml
+++ b/src-db/database/sourcedata/AD_FIELD.xml
@@ -181543,6 +181543,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -181910,6 +181937,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -185693,6 +185746,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -190432,6 +190513,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -191296,6 +191405,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -211106,6 +211242,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -227681,6 +227846,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -250385,6 +250578,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -256902,6 +257122,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -271428,6 +271678,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -287049,6 +287327,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -297791,6 +298097,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -301534,6 +301871,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -302075,6 +302437,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src-db/database/sourcedata/AD_REFERENCE.xml b/src-db/database/sourcedata/AD_REFERENCE.xml
--- a/src-db/database/sourcedata/AD_REFERENCE.xml
+++ b/src-db/database/sourcedata/AD_REFERENCE.xml
@@ -4212,6 +4212,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src-db/database/sourcedata/AD_TAB.xml b/src-db/database/sourcedata/AD_TAB.xml
--- a/src-db/database/sourcedata/AD_TAB.xml
+++ b/src-db/database/sourcedata/AD_TAB.xml
@@ -17797,6 +17797,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @CharacteristicValue.id@)]]>
+
+
+
+
+
+
+
+
+
+
diff --git a/src-db/database/sourcedata/AD_TABLE.xml b/src-db/database/sourcedata/AD_TABLE.xml
--- a/src-db/database/sourcedata/AD_TABLE.xml
+++ b/src-db/database/sourcedata/AD_TABLE.xml
@@ -8872,6 +8872,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src-db/database/sourcedata/AD_WINDOW.xml b/src-db/database/sourcedata/AD_WINDOW.xml
--- a/src-db/database/sourcedata/AD_WINDOW.xml
+++ b/src-db/database/sourcedata/AD_WINDOW.xml
@@ -3151,6 +3151,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml b/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml
--- a/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml
+++ b/src-db/database/sourcedata/OBUIAPP_PARAMETER.xml
@@ -438,17 +438,15 @@
-
-
-
+
-
-
-
+
+
+
-
-
-
+
+
+
diff --git a/src-db/database/sourcedata/OBUIAPP_PROCESS.xml b/src-db/database/sourcedata/OBUIAPP_PROCESS.xml
--- a/src-db/database/sourcedata/OBUIAPP_PROCESS.xml
+++ b/src-db/database/sourcedata/OBUIAPP_PROCESS.xml
@@ -429,7 +429,7 @@
-
+
diff --git a/src-db/database/sourcedata/OBUIAPP_REF_WINDOW.xml b/src-db/database/sourcedata/OBUIAPP_REF_WINDOW.xml
--- a/src-db/database/sourcedata/OBUIAPP_REF_WINDOW.xml
+++ b/src-db/database/sourcedata/OBUIAPP_REF_WINDOW.xml
@@ -63,6 +63,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/org/openbravo/materialmgmt/actionhandler/AddProductsToChValue.java b/src/org/openbravo/materialmgmt/actionhandler/AddProductsToChValue.java
--- a/src/org/openbravo/materialmgmt/actionhandler/AddProductsToChValue.java
+++ b/src/org/openbravo/materialmgmt/actionhandler/AddProductsToChValue.java
@@ -11,13 +11,14 @@
* 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 Openbravo SLU
+ * All portions are Copyright (C) 2013-2015 Openbravo SLU
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************
*/
package org.openbravo.materialmgmt.actionhandler;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -25,19 +26,13 @@
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
-import org.hibernate.criterion.Restrictions;
-import org.openbravo.base.provider.OBProvider;
import org.openbravo.client.application.process.BaseProcessActionHandler;
import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBCriteria;
import org.openbravo.dal.service.OBDal;
import org.openbravo.erpCommon.utility.OBMessageUtils;
import org.openbravo.materialmgmt.CharacteristicsUtils;
-import org.openbravo.model.common.plm.Characteristic;
import org.openbravo.model.common.plm.CharacteristicValue;
import org.openbravo.model.common.plm.Product;
-import org.openbravo.model.common.plm.ProductCharacteristic;
-import org.openbravo.model.common.plm.ProductCharacteristicValue;
import org.openbravo.service.db.DbUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,98 +42,73 @@
@Override
protected JSONObject doExecute(Map parameters, String content) {
- JSONObject jsonRequest = null;
+ JSONObject jsonResponse = new JSONObject();
OBContext.setAdminMode(true);
try {
- jsonRequest = new JSONObject(content);
+ JSONObject jsonRequest = new JSONObject(content);
JSONObject params = jsonRequest.getJSONObject("_params");
+ JSONObject view = params.getJSONObject("m_prodchview_v");
+ JSONArray selected = view.getJSONArray("_selection");
log.debug("{}", jsonRequest);
final String strChValueId = jsonRequest.getString("inpmChValueId");
CharacteristicValue chValue = OBDal.getInstance()
.get(CharacteristicValue.class, strChValueId);
- JSONArray productIds = params.getJSONArray("M_Product_ID");
- int count = addProducts(chValue, productIds);
+ int total = processProducts(chValue, selected);
Map map = new HashMap();
- map.put("productNumer", Integer.toString(count));
+ map.put("productNumer", Integer.toString(total));
map.put("chValueName", chValue.getName());
String messageText = OBMessageUtils.messageBD("AddProductsResult");
JSONObject msg = new JSONObject();
msg.put("severity", "success");
msg.put("text", OBMessageUtils.parseTranslation(messageText, map));
- jsonRequest.put("message", msg);
+ jsonResponse.put("message", msg);
} catch (Exception e) {
log.error("Error in Add Products to Ch Value Action Handler", e);
try {
- jsonRequest = new JSONObject();
Throwable ex = DbUtility.getUnderlyingSQLException(e);
String message = OBMessageUtils.translateError(ex.getMessage()).getMessage();
JSONObject errorMessage = new JSONObject();
errorMessage.put("severity", "error");
errorMessage.put("text", message);
- jsonRequest.put("message", errorMessage);
- } catch (Exception e2) {
- log.error(e.getMessage(), e2);
+ jsonResponse.put("message", errorMessage);
+ } catch (JSONException e2) {
// do nothing, give up
}
} finally {
OBContext.restorePreviousMode();
}
- return jsonRequest;
+
+ return jsonResponse;
}
- private int addProducts(CharacteristicValue chValue, JSONArray productIds) throws JSONException {
+ private int processProducts(CharacteristicValue chValue, JSONArray selected) {
int count = 0;
- for (int i = 0; i < productIds.length(); i++) {
- final String strProductId = productIds.getString(i);
- final Product product = OBDal.getInstance().get(Product.class, strProductId);
- if (CharacteristicsUtils.getCharacteristicValue(product, chValue.getCharacteristic()) != null) {
- // The product already has a value the characteristic, skip it.
- continue;
+ List selectedProductIds = new ArrayList();
+ try {
+ for (int i = 0; i < selected.length(); i++) {
+ JSONObject productJSON = selected.getJSONObject(i);
+ String strProductId;
+ strProductId = productJSON.getString("product");
+ final Product product = OBDal.getInstance().get(Product.class, strProductId);
+ CharacteristicsUtils.setCharacteristicValue(product, chValue);
+ selectedProductIds.add(strProductId);
+ count++;
+ for (Product variant : product.getProductGenericProductList()) {
+ if (selectedProductIds.contains(variant.getId())) {
+ continue;
+ }
+ CharacteristicsUtils.setCharacteristicValue(variant, chValue);
+ count++;
+ }
}
- ProductCharacteristicValue newPrChValue = OBProvider.getInstance().get(
- ProductCharacteristicValue.class);
- newPrChValue.setCharacteristic(chValue.getCharacteristic());
- newPrChValue.setCharacteristicValue(chValue);
- newPrChValue.setProduct(product);
- newPrChValue.setOrganization(product.getOrganization());
- OBDal.getInstance().save(newPrChValue);
-
- if (doesNotHaveCharacteristic(product, chValue.getCharacteristic())) {
- ProductCharacteristic newPrCh = OBProvider.getInstance().get(ProductCharacteristic.class);
- newPrCh.setProduct(product);
- newPrCh.setCharacteristic(chValue.getCharacteristic());
- newPrCh.setOrganization(product.getOrganization());
- newPrCh.setVariant(false);
- newPrCh.setSequenceNumber((product.getProductCharacteristicList().size() + 1) * 10L);
- OBDal.getInstance().save(newPrCh);
- }
-
- if (product.isGeneric()) {
- List variants = product.getProductGenericProductList();
- JSONArray variantsArray = new JSONArray();
- for (Product variant : variants) {
- variantsArray.put(variant.getId());
- }
- count += addProducts(chValue, variantsArray);
- }
-
- count++;
+ } catch (JSONException ignore) {
}
return count;
- }
- private boolean doesNotHaveCharacteristic(Product product, Characteristic characteristic) {
- OBCriteria prChCrit = OBDal.getInstance().createCriteria(
- ProductCharacteristic.class);
- prChCrit.add(Restrictions.eq(ProductCharacteristic.PROPERTY_CHARACTERISTIC, characteristic));
- prChCrit.add(Restrictions.eq(ProductCharacteristic.PROPERTY_PRODUCT, product));
- prChCrit.setFilterOnReadableOrganization(false);
- prChCrit.setFilterOnActive(false);
- return prChCrit.count() == 0;
}
}