Attached Files | 0_pi_q3.patch [^] (5,316 bytes) 2017-10-13 11:37 [Show Content] [Hide Content]diff -r 53c792d3f781 modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelApplicationInitializer.java
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelApplicationInitializer.java Tue Sep 26 13:26:43 2017 +0200
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelApplicationInitializer.java Fri Oct 13 11:14:58 2017 +0200
@@ -26,6 +26,7 @@
import org.apache.log4j.Logger;
import org.hibernate.dialect.function.StandardSQLFunction;
+import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.StringType;
import org.openbravo.dal.service.OBDal;
import org.openbravo.erpCommon.utility.DateTimeData;
@@ -62,6 +63,8 @@
new StandardSQLFunction("ad_org_getperiodcontrolallow", new StringType()));
OBDal.getInstance().registerSQLFunction("m_isparent_ch_value",
new StandardSQLFunction("m_isparent_ch_value", new StringType()));
+ OBDal.getInstance().registerSQLFunction("m_getjsondescription",
+ new StandardSQLFunction("m_getjsondescription", StandardBasicTypes.STRING));
}
private void checkDatabaseAndTomcatDateTime() {
diff -r 53c792d3f781 src-db/database/sourcedata/AD_MESSAGE.xml
--- a/src-db/database/sourcedata/AD_MESSAGE.xml Tue Sep 26 13:26:43 2017 +0200
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml Fri Oct 13 11:14:58 2017 +0200
@@ -23550,6 +23550,18 @@
<!--9DEDEDDC6E44428A8DC45444FCB9A1DD--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
<!--9DEDEDDC6E44428A8DC45444FCB9A1DD--></AD_MESSAGE>
+<!--9DF58DD1831645A7B240DF296302E9CD--><AD_MESSAGE>
+<!--9DF58DD1831645A7B240DF296302E9CD--> <AD_MESSAGE_ID><![CDATA[9DF58DD1831645A7B240DF296302E9CD]]></AD_MESSAGE_ID>
+<!--9DF58DD1831645A7B240DF296302E9CD--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--9DF58DD1831645A7B240DF296302E9CD--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--9DF58DD1831645A7B240DF296302E9CD--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--9DF58DD1831645A7B240DF296302E9CD--> <VALUE><![CDATA[ExpirationDateLabel]]></VALUE>
+<!--9DF58DD1831645A7B240DF296302E9CD--> <MSGTEXT><![CDATA[Expiration Date]]></MSGTEXT>
+<!--9DF58DD1831645A7B240DF296302E9CD--> <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--9DF58DD1831645A7B240DF296302E9CD--> <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--9DF58DD1831645A7B240DF296302E9CD--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--9DF58DD1831645A7B240DF296302E9CD--></AD_MESSAGE>
+
<!--9E28C2ECFB6F4EBEB05B90F4A71DBBC7--><AD_MESSAGE>
<!--9E28C2ECFB6F4EBEB05B90F4A71DBBC7--> <AD_MESSAGE_ID><![CDATA[9E28C2ECFB6F4EBEB05B90F4A71DBBC7]]></AD_MESSAGE_ID>
<!--9E28C2ECFB6F4EBEB05B90F4A71DBBC7--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -24381,6 +24393,18 @@
<!--B029738DD2604EDFA12785CAF3C7DBA0--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
<!--B029738DD2604EDFA12785CAF3C7DBA0--></AD_MESSAGE>
+<!--B058F7F31D4B40C3ACC0328D898B1A40--><AD_MESSAGE>
+<!--B058F7F31D4B40C3ACC0328D898B1A40--> <AD_MESSAGE_ID><![CDATA[B058F7F31D4B40C3ACC0328D898B1A40]]></AD_MESSAGE_ID>
+<!--B058F7F31D4B40C3ACC0328D898B1A40--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--B058F7F31D4B40C3ACC0328D898B1A40--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--B058F7F31D4B40C3ACC0328D898B1A40--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--B058F7F31D4B40C3ACC0328D898B1A40--> <VALUE><![CDATA[SerialNoLabel]]></VALUE>
+<!--B058F7F31D4B40C3ACC0328D898B1A40--> <MSGTEXT><![CDATA[Serial No]]></MSGTEXT>
+<!--B058F7F31D4B40C3ACC0328D898B1A40--> <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--B058F7F31D4B40C3ACC0328D898B1A40--> <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--B058F7F31D4B40C3ACC0328D898B1A40--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--B058F7F31D4B40C3ACC0328D898B1A40--></AD_MESSAGE>
+
<!--B077B434599241F6B04A8D01E8302C9C--><AD_MESSAGE>
<!--B077B434599241F6B04A8D01E8302C9C--> <AD_MESSAGE_ID><![CDATA[B077B434599241F6B04A8D01E8302C9C]]></AD_MESSAGE_ID>
<!--B077B434599241F6B04A8D01E8302C9C--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -25055,6 +25079,18 @@
<!--BC6E700B0E4745F598FF9A6640F52328--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
<!--BC6E700B0E4745F598FF9A6640F52328--></AD_MESSAGE>
+<!--BC85CF19B1354C5992785126D026D303--><AD_MESSAGE>
+<!--BC85CF19B1354C5992785126D026D303--> <AD_MESSAGE_ID><![CDATA[BC85CF19B1354C5992785126D026D303]]></AD_MESSAGE_ID>
+<!--BC85CF19B1354C5992785126D026D303--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--BC85CF19B1354C5992785126D026D303--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--BC85CF19B1354C5992785126D026D303--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--BC85CF19B1354C5992785126D026D303--> <VALUE><![CDATA[LotLabel]]></VALUE>
+<!--BC85CF19B1354C5992785126D026D303--> <MSGTEXT><![CDATA[Lot]]></MSGTEXT>
+<!--BC85CF19B1354C5992785126D026D303--> <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--BC85CF19B1354C5992785126D026D303--> <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--BC85CF19B1354C5992785126D026D303--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--BC85CF19B1354C5992785126D026D303--></AD_MESSAGE>
+
<!--BCAF7F617142477B95BAD71E41291571--><AD_MESSAGE>
<!--BCAF7F617142477B95BAD71E41291571--> <AD_MESSAGE_ID><![CDATA[BCAF7F617142477B95BAD71E41291571]]></AD_MESSAGE_ID>
<!--BCAF7F617142477B95BAD71E41291571--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
1_posterminal_q3.patch [^] (23,523 bytes) 2017-10-13 11:37 [Show Content] [Hide Content]diff -r 6923a1414373 src/org/openbravo/retail/posterminal/OrderLoader.java
--- a/src/org/openbravo/retail/posterminal/OrderLoader.java Mon Oct 09 15:40:28 2017 +0200
+++ b/src/org/openbravo/retail/posterminal/OrderLoader.java Fri Oct 13 11:21:00 2017 +0200
@@ -82,9 +82,7 @@
import org.openbravo.model.common.order.OrderLineOffer;
import org.openbravo.model.common.order.OrderTax;
import org.openbravo.model.common.order.OrderlineServiceRelation;
-import org.openbravo.model.common.plm.AttributeSet;
import org.openbravo.model.common.plm.AttributeSetInstance;
-import org.openbravo.model.common.plm.Product;
import org.openbravo.model.financialmgmt.payment.FIN_FinaccTransaction;
import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
import org.openbravo.model.financialmgmt.payment.FIN_OrigPaymentScheduleDetail;
@@ -101,6 +99,7 @@
import org.openbravo.model.materialmgmt.transaction.MaterialTransaction;
import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
import org.openbravo.model.materialmgmt.transaction.ShipmentInOutLine;
+import org.openbravo.retail.posterminal.utility.AttributesUtils;
import org.openbravo.service.db.CallStoredProcedure;
import org.openbravo.service.db.DalConnectionProvider;
import org.openbravo.service.importprocess.ImportEntryManager;
@@ -1238,9 +1237,11 @@
line.setMovementQuantity(qty);
line.setStorageBin(bin);
- if (jsonOrderLine.has("attributeValue") && jsonOrderLine.get("attributeValue") != null) {
- line.setAttributeSetValue(fetchAttributeSetValue(jsonOrderLine.get("attributeValue")
- .toString(), jsonOrderLine.getJSONObject("product").get("id").toString()));
+ if (OBMOBCUtils.isJsonObjectPropertyStringPresentNotNullAndNotEmptyString(jsonOrderLine,
+ "attributeValue")) {
+ line.setAttributeSetValue(AttributesUtils.fetchAttributeSetValue(
+ jsonOrderLine.get("attributeValue").toString(), jsonOrderLine.getJSONObject("product")
+ .get("id").toString()));
} else {
line.setAttributeSetValue(attributeSetInstance);
}
@@ -1323,9 +1324,11 @@
// shipment is created or is a C&R and is not a layaway, so all is delivered
orderline.setDeliveredQuantity(orderline.getOrderedQuantity());
}
- if (jsonOrderLine.has("attributeValue") && jsonOrderLine.get("attributeValue") != null) {
- orderline.setAttributeSetValue(fetchAttributeSetValue(jsonOrderLine.get("attributeValue")
- .toString(), jsonOrderLine.getJSONObject("product").get("id").toString()));
+ if (OBMOBCUtils.isJsonObjectPropertyStringPresentNotNullAndNotEmptyString(jsonOrderLine,
+ "attributeValue")) {
+ orderline.setAttributeSetValue(AttributesUtils.fetchAttributeSetValue(
+ jsonOrderLine.get("attributeValue").toString(), jsonOrderLine.getJSONObject("product")
+ .get("id").toString()));
}
lineReferences.add(orderline);
@@ -1408,43 +1411,6 @@
}
}
- private AttributeSetInstance fetchAttributeSetValue(String attributeValue, String productId) {
- AttributeSetInstance attrSetInst = null;
- Product product = OBDal.getInstance().get(Product.class, productId);
- try {
- if (StringUtils.isNotEmpty(attributeValue) || StringUtils.isNotBlank(attributeValue)) {
- OBCriteria<AttributeSetInstance> attrSICrit = OBDal.getInstance().createCriteria(
- AttributeSetInstance.class);
- attrSICrit.add(Restrictions.eq(AttributeSetInstance.PROPERTY_DESCRIPTION, attributeValue));
- List<AttributeSetInstance> attrSIList = attrSICrit.list();
- if (attrSIList.isEmpty() && attrSIList.size() == 0) {
- attrSetInst = createAttributeSetValue(attributeValue, product.getAttributeSet());
- return attrSetInst;
- } else {
- attrSetInst = attrSIList.get(0);
- return attrSetInst;
- }
- } else {
- return attrSetInst;
- }
- } catch (Exception e) {
- throw new OBException(e.getMessage(), e);
- }
- }
-
- private AttributeSetInstance createAttributeSetValue(String string, AttributeSet attributeSet) {
- AttributeSetInstance newAttrSetInst = OBProvider.getInstance().get(AttributeSetInstance.class);
- try {
- newAttrSetInst.setAttributeSet(attributeSet);
- newAttrSetInst.setDescription(string);
- OBDal.getInstance().save(newAttrSetInst);
- OBDal.getInstance().flush();
- } catch (Exception e) {
- throw new OBException(e.getMessage(), e);
- }
- return newAttrSetInst;
- }
-
protected void createLinesForServiceProduct() throws JSONException {
Iterator<Entry<String, JSONArray>> orderLineIterator = orderLineServiceList.entrySet()
.iterator();
diff -r 6923a1414373 src/org/openbravo/retail/posterminal/PaidReceiptLinesProperties.java
--- a/src/org/openbravo/retail/posterminal/PaidReceiptLinesProperties.java Mon Oct 09 15:40:28 2017 +0200
+++ b/src/org/openbravo/retail/posterminal/PaidReceiptLinesProperties.java Fri Oct 13 11:21:00 2017 +0200
@@ -13,6 +13,7 @@
import java.util.List;
import org.openbravo.client.kernel.ComponentProvider.Qualifier;
+import org.openbravo.dal.core.OBContext;
import org.openbravo.mobile.core.model.HQLProperty;
import org.openbravo.mobile.core.model.ModelExtension;
@@ -30,7 +31,7 @@
public List<HQLProperty> getHQLProperties(Object params) {
ArrayList<HQLProperty> list = new ArrayList<HQLProperty>() {
private static final long serialVersionUID = 1L;
-
+ private final String currentLanguage = OBContext.getOBContext().getLanguage().getId();
{
add(new HQLProperty("ordLine.product.id", "id"));
add(new HQLProperty("ordLine.product.name", "name"));
@@ -61,7 +62,9 @@
add(new HQLProperty("returnReason.name", "returnReasonName"));
add(new HQLProperty("ordLine.goodsShipmentLine.id", "goodsShipmentLine"));
add(new HQLProperty(
- "(select case when line.attributeSetValue is not null then line.attributeSetValue.description else null end FROM OrderLine line where line.id = ordLine.id)",
+ "(select case when line.attributeSetValue is not null then (m_getjsondescription(line.attributeSetValue.id, 'Y', '"
+ + currentLanguage
+ + "')) ELSE null end FROM OrderLine line where line.id = ordLine.id)",
"attributeValue"));
}
};
diff -r 6923a1414373 src/org/openbravo/retail/posterminal/utility/AttributesUtils.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/retail/posterminal/utility/AttributesUtils.java Fri Oct 13 11:21:00 2017 +0200
@@ -0,0 +1,338 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2017 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+ */
+package org.openbravo.retail.posterminal.utility;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.hibernate.criterion.Restrictions;
+import org.openbravo.base.exception.OBException;
+import org.openbravo.base.provider.OBProvider;
+import org.openbravo.base.session.OBPropertiesProvider;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBQuery;
+import org.openbravo.model.common.plm.Attribute;
+import org.openbravo.model.common.plm.AttributeInstance;
+import org.openbravo.model.common.plm.AttributeSet;
+import org.openbravo.model.common.plm.AttributeSetInstance;
+import org.openbravo.model.common.plm.AttributeUse;
+import org.openbravo.model.common.plm.AttributeValue;
+import org.openbravo.model.common.plm.Product;
+
+public class AttributesUtils {
+
+ private static final Logger log = Logger.getLogger(AttributesUtils.class);
+
+ public static AttributeSetInstance fetchAttributeSetValue(String attributeValue, String productId) {
+ AttributeSetInstance attrSetInst = null;
+ String validatedAttributeSetInstanceDescription = "";
+ Product product = OBDal.getInstance().get(Product.class, productId);
+ if (product.getAttributeSet() != null) {
+ try {
+ if (StringUtils.isNotEmpty(attributeValue) || StringUtils.isNotBlank(attributeValue)) {
+ validatedAttributeSetInstanceDescription = AttributesUtils
+ .generateValidAttSetInstanceDescription(attributeValue, product);
+
+ OBCriteria<AttributeSetInstance> attrSICrit = OBDal.getInstance().createCriteria(
+ AttributeSetInstance.class);
+ attrSICrit.add(Restrictions.eq(AttributeSetInstance.PROPERTY_DESCRIPTION,
+ validatedAttributeSetInstanceDescription));
+ List<AttributeSetInstance> attrSIList = attrSICrit.list();
+ if (attrSIList.isEmpty() && attrSIList.size() == 0) {
+ attrSetInst = AttributesUtils.createAttributeSetValue(
+ validatedAttributeSetInstanceDescription, product);
+ return attrSetInst;
+ } else {
+ attrSetInst = attrSIList.get(0);
+ return attrSetInst;
+ }
+ } else {
+ return attrSetInst;
+ }
+ } catch (Exception e) {
+ throw new OBException(e.getMessage(), e);
+ }
+ } else {
+ log.warn("Warning: Trying to fetch an Attribute Set instance for a product which is not configured to use attributes. ("
+ + product.getIdentifier() + ")");
+ return null;
+ }
+ }
+
+ public static String generateValidAttSetInstanceDescription(
+ String receivedAttSetInstanceDescription, String productId) {
+ return generateValidAttSetInstanceDescription(receivedAttSetInstanceDescription, OBDal
+ .getInstance().get(Product.class, productId));
+ }
+
+ public static String generateValidAttSetInstanceDescription(
+ String receivedAttSetInstanceDescription, Product product) {
+ if (product.getAttributeSet() != null) {
+ return AttributesUtils.generateValidAttSetInstanceDescription(
+ receivedAttSetInstanceDescription, product, product.getAttributeSet());
+ } else {
+ log.warn("generateValidAttSetInstanceDescription method has been called using a product ("
+ + product.getIdentifier() + ") without attributeSet.");
+ return "";
+ }
+ }
+
+ private static String generateValidAttSetInstanceDescription(
+ String receivedAttSetInstanceDescription, Product product, AttributeSet attSet) {
+ String result = "";
+ log.debug("Att Description received: " + receivedAttSetInstanceDescription);
+ String[] receivedAttSetInstanceDescription_parts = receivedAttSetInstanceDescription.split("_");
+
+ int currentPart = 0;
+ int numberOfParts = receivedAttSetInstanceDescription_parts.length;
+ log.debug("Number of parts of Att Description: " + numberOfParts);
+
+ List<Attribute> lstAttributes = getInstanciableAndMandatoryAttributesUsedByAttributeSetSortedBySeqNoAsc(attSet);
+ for (Attribute att : lstAttributes) {
+ if (currentPart >= numberOfParts) {
+ throw new OBException("Product -" + product.getIdentifier() + "- Uses an AttributeSet -"
+ + attSet.getIdentifier() + "- which requires at least " + (currentPart + 1)
+ + " values, but just " + numberOfParts + " was detected", true);
+ }
+ if (att.isList()) {
+ log.debug("Value for attribute (with restricted list of vaules) -" + att.getIdentifier()
+ + "- of attSet -" + attSet.getIdentifier() + "- used by Product -"
+ + product.getIdentifier() + "- is -"
+ + receivedAttSetInstanceDescription_parts[currentPart] + "-");
+ String valueToValidate = receivedAttSetInstanceDescription_parts[currentPart];
+ if (isValidValueForAttribute(att, valueToValidate)) {
+ result += receivedAttSetInstanceDescription_parts[currentPart] + "_";
+ } else {
+ throw new OBException("Product -" + product.getIdentifier()
+ + "- Uses an Attribute marked as List. Value received (" + valueToValidate
+ + ") is not valid. ", true);
+ }
+ } else {
+ log.debug("Value for attribute (without valid list of vaules) -" + att.getIdentifier()
+ + "- of attSet -" + attSet.getIdentifier() + "- used by Product -"
+ + product.getIdentifier() + "- is -"
+ + receivedAttSetInstanceDescription_parts[currentPart] + "-");
+ result += receivedAttSetInstanceDescription_parts[currentPart] + "_";
+ }
+ log.debug("AttSetInstance description for product -" + product.getIdentifier()
+ + "- after an iteration of attUse is -" + result + "-");
+ currentPart += 1;
+ }
+
+ if (attSet.isLot()) {
+ if (currentPart >= numberOfParts) {
+ throw new OBException("Product -" + product.getIdentifier() + "- Uses an AttributeSet -"
+ + attSet.getIdentifier() + "- which requires at least " + (currentPart + 1)
+ + " values, but just " + numberOfParts + " was detected", true);
+ }
+ log.debug("Att Set (" + attSet.getIdentifier() + ") uses lot. lot value is -"
+ + receivedAttSetInstanceDescription_parts[currentPart] + "-");
+ result += "L" + receivedAttSetInstanceDescription_parts[currentPart] + "_";
+ currentPart += 1;
+ }
+
+ if (attSet.isSerialNo()) {
+ if (currentPart >= numberOfParts) {
+ throw new OBException("Product -" + product.getIdentifier() + "- Uses an AttributeSet -"
+ + attSet.getIdentifier() + "- which requires at least " + (currentPart + 1)
+ + " values, but just " + numberOfParts + " was detected", true);
+ }
+ log.debug("Att Set (" + attSet.getIdentifier()
+ + ") uses serialNo. It must be the first part ("
+ + receivedAttSetInstanceDescription_parts[currentPart] + ")");
+ result += "#" + receivedAttSetInstanceDescription_parts[currentPart] + "_";
+ currentPart += 1;
+ }
+
+ if (attSet.isExpirationDate()) {
+ if (currentPart >= numberOfParts) {
+ throw new OBException("Product -" + product.getIdentifier() + "- Uses an AttributeSet -"
+ + attSet.getIdentifier() + "- which requires at least " + (currentPart + 1)
+ + " values, but just " + numberOfParts + " was detected", true);
+ }
+ String receivedExpirationDateStrValue = receivedAttSetInstanceDescription_parts[currentPart];
+ Date receivedExpirationDate;
+
+ log.debug("Att Set (" + attSet.getIdentifier()
+ + ") uses expiration date. Value received for expDate is -"
+ + receivedExpirationDateStrValue + "-");
+
+ final String dateFormatForDescription = (String) OBPropertiesProvider.getInstance()
+ .getOpenbravoProperties().get("dateFormat.java");
+ try {
+ receivedExpirationDate = new SimpleDateFormat(dateFormatForDescription)
+ .parse(receivedExpirationDateStrValue);
+ } catch (Exception e) {
+ throw new OBException(
+ "Product -"
+ + product.getIdentifier()
+ + "- Uses expirationdate Attribute. Value received is not valid. Format doesn't match. Expected format ("
+ + dateFormatForDescription + ") doesn't match with value ("
+ + receivedExpirationDateStrValue + ")", true);
+ }
+ final String validatedExpirationDateStrValue = new SimpleDateFormat(dateFormatForDescription)
+ .format(receivedExpirationDate);
+ log.debug("Expiration date value for product -" + product.getIdentifier() + "- is -"
+ + validatedExpirationDateStrValue + "-");
+ result += validatedExpirationDateStrValue + "_";
+ currentPart += 1;
+ }
+
+ result = result.substring(0, result.length() - 1);
+ return result;
+ }
+
+ private static AttributeSetInstance createAttributeSetValue(
+ String receivedAttSetInstanceDescriptionWithSymbols, Product product) {
+ if (product.getAttributeSet() != null) {
+ try {
+ String[] receivedAttSetInstanceDescriptionWithSymbols_parts = receivedAttSetInstanceDescriptionWithSymbols
+ .split("_");
+
+ int currentPart = 0;
+ int numberOfParts = receivedAttSetInstanceDescriptionWithSymbols_parts.length;
+
+ // Create Att Set Instance
+ AttributeSetInstance newAttrSetInst = OBProvider.getInstance().get(
+ AttributeSetInstance.class);
+ newAttrSetInst.setAttributeSet(product.getAttributeSet());
+ newAttrSetInst.setDescription(receivedAttSetInstanceDescriptionWithSymbols);
+ OBDal.getInstance().save(newAttrSetInst);
+
+ // If attSet uses other attributes, Att instance must be created
+ List<Attribute> lstAttributes = getInstanciableAndMandatoryAttributesUsedByAttributeSetSortedBySeqNoAsc(product
+ .getAttributeSet());
+ if (lstAttributes != null && lstAttributes.size() > 0) {
+ // We are using attributes -> Att Instance must be created for each attribute used
+ for (Attribute att : lstAttributes) {
+ String attValue = "";
+ attValue = receivedAttSetInstanceDescriptionWithSymbols_parts[currentPart];
+ final AttributeInstance attInstance = (AttributeInstance) OBProvider.getInstance().get(
+ AttributeInstance.ENTITY_NAME);
+ attInstance.setAttribute(att);
+ attInstance.setSearchKey(attValue);
+ attInstance.setAttributeSetValue(newAttrSetInst);
+ OBDal.getInstance().save(attInstance);
+ currentPart += 1;
+ }
+ }
+
+ if (product.getAttributeSet().isLot()) {
+ if (currentPart >= numberOfParts) {
+ // manage error
+ // Should not happen because it has been already managed by
+ // generateValidAttSetInstanceDescription
+ }
+ String currentLotWithSymbol = receivedAttSetInstanceDescriptionWithSymbols_parts[currentPart];
+ String currentLotWithOutSymbol = currentLotWithSymbol.substring(1);
+ newAttrSetInst.setLotName(currentLotWithOutSymbol);
+ currentPart += 1;
+ }
+
+ if (product.getAttributeSet().isSerialNo()) {
+ if (currentPart >= numberOfParts) {
+ // manage error
+ // Should not happen because it has been already managed by
+ // generateValidAttSetInstanceDescription
+ }
+ String currentSerialNoWithSymbol = receivedAttSetInstanceDescriptionWithSymbols_parts[currentPart];
+ String currentSerialNoWithOutSymbol = currentSerialNoWithSymbol.substring(1);
+ newAttrSetInst.setSerialNo(currentSerialNoWithOutSymbol);
+ currentPart += 1;
+ }
+
+ if (product.getAttributeSet().isExpirationDate()) {
+ if (currentPart >= numberOfParts) {
+ // manage error
+ // Should not happen because it has been already managed by
+ // generateValidAttSetInstanceDescription
+ }
+ String receivedExpirationDateStrValue = receivedAttSetInstanceDescriptionWithSymbols_parts[currentPart];
+ Date receivedExpirationDate;
+
+ final String dateFormatForDescription = (String) OBPropertiesProvider.getInstance()
+ .getOpenbravoProperties().get("dateFormat.java");
+ try {
+ receivedExpirationDate = new SimpleDateFormat(dateFormatForDescription)
+ .parse(receivedExpirationDateStrValue);
+ } catch (Exception e) {
+ throw new OBException(
+ "Product -"
+ + product.getIdentifier()
+ + "- Uses expirationdate Attribute. Value received is not valid. Format doesn't match. Expected format ("
+ + dateFormatForDescription + ") doesn't match with value ("
+ + receivedExpirationDateStrValue + ")", true);
+ }
+
+ OBDal.getInstance().flush();
+ newAttrSetInst.setExpirationDate(receivedExpirationDate);
+ currentPart += 1;
+ }
+
+ return newAttrSetInst;
+ } catch (Exception e) {
+ throw new OBException(e.getMessage(), e);
+ }
+ } else {
+ log.warn("createAttributeSetValue method has been called using a product ("
+ + product.getIdentifier() + ") without attributeSet.");
+ return null;
+ }
+ }
+
+ private static List<Attribute> getInstanciableAndMandatoryAttributesUsedByAttributeSetSortedBySeqNoAsc(
+ AttributeSet attributeSet) {
+ List<Attribute> lstAttributes = new ArrayList<Attribute>();
+ try {
+ StringBuilder hqlQueryString = new StringBuilder();
+ hqlQueryString.append("attributeSet.id = :attSetId ");
+ hqlQueryString.append("ORDER BY seqNo asc");
+ OBQuery<AttributeUse> attUseQuery = OBDal.getInstance().createQuery(AttributeUse.class,
+ hqlQueryString.toString());
+ attUseQuery.setNamedParameter("attSetId", attributeSet.getId());
+ List<AttributeUse> lstAttUse = attUseQuery.list();
+ for (AttributeUse attUse : lstAttUse) {
+ if (attUse.getAttribute().isInstanceAttribute() && attUse.getAttribute().isMandatory()) {
+ lstAttributes.add(attUse.getAttribute());
+ }
+ }
+ } catch (Exception e) {
+ throw new OBException(e.getMessage(), e);
+ }
+ return lstAttributes;
+ }
+
+ private static boolean isValidValueForAttribute(Attribute att, String value) {
+ if (!att.isList()) {
+ log.warn("isValidValueForAttribute function is being called for attribute not marked as list -"
+ + att.getIdentifier() + "-");
+ return true;
+ }
+ StringBuilder hqlQueryString = new StringBuilder();
+ hqlQueryString.append("attribute.id = :attId AND ");
+ hqlQueryString.append("name = :nameValue ");
+ OBQuery<AttributeValue> attValueQuery = OBDal.getInstance().createQuery(AttributeValue.class,
+ hqlQueryString.toString());
+ attValueQuery.setNamedParameter("attId", att.getId());
+ attValueQuery.setNamedParameter("nameValue", value);
+ List<AttributeValue> lstAttValues = attValueQuery.list();
+ if (lstAttValues != null) {
+ if (lstAttValues.size() > 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
\ No newline at end of file
diff -r 6923a1414373 web/org.openbravo.retail.posterminal/js/components/renderorderline.js
--- a/web/org.openbravo.retail.posterminal/js/components/renderorderline.js Mon Oct 09 15:40:28 2017 +0200
+++ b/web/org.openbravo.retail.posterminal/js/components/renderorderline.js Fri Oct 13 11:21:00 2017 +0200
@@ -108,7 +108,7 @@
this.createComponent({
style: 'display: block;',
components: [{
- content: OB.I18N.getLabel('OBPOS_AttributeValue') + this.model.get('attributeValue'),
+ content: OB.I18N.getLabel('OBPOS_AttributeValue') + (this.model.get('attSetInstanceDesc') ? this.model.get('attSetInstanceDesc') : this.model.get('attributeValue')),
attributes: {
style: 'float: left; width: 100%; clear: left;'
}
2_mobilecore_q3.patch [^] (1,450 bytes) 2017-10-13 11:37 [Show Content] [Hide Content]diff -r 91cdab9f8609 src/org/openbravo/mobile/core/utils/OBMOBCUtils.java
--- a/src/org/openbravo/mobile/core/utils/OBMOBCUtils.java Sat Oct 07 11:22:26 2017 +0530
+++ b/src/org/openbravo/mobile/core/utils/OBMOBCUtils.java Fri Oct 13 11:15:32 2017 +0200
@@ -19,6 +19,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
@@ -153,4 +154,33 @@
throw new OBException(e.getMessage(), e);
}
}
+
+ /**
+ * Returns TRUE when a certain property of a JSONObject satisfy all of above conditions
+ *
+ * 1. The property Exists
+ *
+ * 2. The property is not NULL
+ *
+ * 3. The property is a String
+ *
+ * 4. The property is a non empty string
+ *
+ * @return is valid or not
+ */
+ public static boolean isJsonObjectPropertyStringPresentNotNullAndNotEmptyString(
+ JSONObject jsonObject, String propertyToCheck) {
+ if (jsonObject.has(propertyToCheck) && !jsonObject.isNull(propertyToCheck)) {
+ String readedValue;
+ try {
+ readedValue = jsonObject.getString(propertyToCheck);
+ if (!StringUtils.isEmpty(readedValue)) {
+ return true;
+ }
+ } catch (JSONException e) {
+ return false;
+ }
+ }
+ return false;
+ }
}
3_returns_q3.patch [^] (3,809 bytes) 2017-10-13 11:37 [Show Content] [Hide Content]
# HG changeset patch
# User Guillermo Alvarez de Eulate <guillermo.alvarez@openbravo.com>
# Date 1507880473 -7200
# Node ID acaab0e5f2d817b8740a605eb6ae1fdacf9699e4
# Parent a5a8157400e3fa9ec0493a5b9b6cb9affde30321
Related to issue 36966: AttValue info retrieved from server y now a json object
- Receive attValue information taking into account new format
- Generate attDescription based on json information
- Compare the input inserted by the user with the attDescription
diff -r a5a8157400e3 -r acaab0e5f2d8 web/org.openbravo.retail.returns/js/modalReturnLines.js
--- a/web/org.openbravo.retail.returns/js/modalReturnLines.js Tue Oct 03 05:55:55 2017 +0000
+++ b/web/org.openbravo.retail.returns/js/modalReturnLines.js Fri Oct 13 09:41:13 2017 +0200
@@ -151,7 +151,7 @@
}, {
name: 'attribute',
classes: 'span4',
- style: 'line-height: 35px; font-size: 17px; width: 180px;'
+ style: 'line-height: 35px; font-size: 17px; width: 180px; text-align: left;'
}, {
name: 'totalQuantity',
classes: 'span2',
@@ -297,7 +297,31 @@
}
this.$.product.setContent(this.newAttribute.name);
if (OB.MobileApp.model.hasPermission('OBPOS_EnableSupportForProductAttributes', true)) {
- this.$.attribute.setContent(this.newAttribute.attributeValue ? this.newAttribute.attributeValue : 'NA');
+ if (this.newAttribute.attributeValue && _.isString(this.newAttribute.attributeValue)) {
+ var jsonAttValues = JSON.parse(this.newAttribute.attributeValue);
+
+ var attSetInstanceDescription = '';
+ _.each(
+ _.keys(jsonAttValues), function (key) {
+ var currentValue = jsonAttValues[key];
+ var attValueContent = '';
+ if (jsonAttValues && currentValue) {
+ attValueContent += currentValue.label ? currentValue.label : currentValue.name;
+ attValueContent += ': ';
+ attValueContent += currentValue.value;
+ attSetInstanceDescription += currentValue.value + "_";
+ this.$.attribute.createComponent({
+ content: attValueContent
+ });
+ }
+ }, this);
+ if (attSetInstanceDescription && attSetInstanceDescription.length > 1) {
+ attSetInstanceDescription = attSetInstanceDescription.substring(0, attSetInstanceDescription.length - 1);
+ }
+ this.newAttribute.attSetInstanceDesc = attSetInstanceDescription;
+ } else {
+ this.$.attribute.setContent('NA');
+ }
} else {
this.$.attribute.hide();
}
diff -r a5a8157400e3 -r acaab0e5f2d8 web/org.openbravo.retail.returns/js/modalproductattributeverifiedreturns.js
--- a/web/org.openbravo.retail.returns/js/modalproductattributeverifiedreturns.js Tue Oct 03 05:55:55 2017 +0000
+++ b/web/org.openbravo.retail.returns/js/modalproductattributeverifiedreturns.js Fri Oct 13 09:41:13 2017 +0200
@@ -116,12 +116,12 @@
fieldChanged: function (inSender, inEvent) {
var me = this,
line = me.args.line,
- validAttribute, orderlineAttribute, orderlineProduct, inpProduct, inpAttribute, lineIndex, focusIndex;
+ validAttribute, orderlineAttribute, orderlineProduct, inpProduct, inpAttribute, lineIndex, focusIndex, transformedAttValue;
lineIndex = 0;
line.forEach(function (theLine) {
validAttribute = false;
orderlineProduct = theLine.id;
- orderlineAttribute = theLine.attributeValue;
+ orderlineAttribute = theLine.attSetInstanceDesc;
inpProduct = me.$.bodyContent.$.verifiedReturns.$['returnLine' + lineIndex].$.productId.getContent();
inpAttribute = me.$.bodyContent.$.verifiedReturns.$['returnLine' + lineIndex].$.valueAttribute.getValue();
if (inpAttribute) {
1_posterminal_q3_2.patch [^] (5,245 bytes) 2017-10-25 08:58 [Show Content] [Hide Content]diff -r 741395712e24 src/org/openbravo/retail/posterminal/OBPOSComponentProvider.java
--- a/src/org/openbravo/retail/posterminal/OBPOSComponentProvider.java Tue Oct 24 12:22:57 2017 +0200
+++ b/src/org/openbravo/retail/posterminal/OBPOSComponentProvider.java Tue Oct 24 12:25:56 2017 +0200
@@ -122,6 +122,7 @@
"components/modalmorepaymentmethods",
// Web POS window
"utils/eventbus",
+ "utils/attributeUtils",
"utils/cashUpReportUtils",
"utils/cashManagementUtils",
"components/keypadcoins",
diff -r 741395712e24 src/org/openbravo/retail/posterminal/OrderLoader.java
--- a/src/org/openbravo/retail/posterminal/OrderLoader.java Tue Oct 24 12:22:57 2017 +0200
+++ b/src/org/openbravo/retail/posterminal/OrderLoader.java Tue Oct 24 12:25:56 2017 +0200
@@ -1238,6 +1238,11 @@
line.setMovementQuantity(qty);
line.setStorageBin(bin);
if (OBMOBCUtils.isJsonObjectPropertyStringPresentNotNullAndNotEmptyString(jsonOrderLine,
+ "attSetInstanceDesc")) {
+ line.setAttributeSetValue(AttributesUtils.fetchAttributeSetValue(
+ jsonOrderLine.get("attSetInstanceDesc").toString(), jsonOrderLine
+ .getJSONObject("product").get("id").toString()));
+ } else if (OBMOBCUtils.isJsonObjectPropertyStringPresentNotNullAndNotEmptyString(jsonOrderLine,
"attributeValue")) {
line.setAttributeSetValue(AttributesUtils.fetchAttributeSetValue(
jsonOrderLine.get("attributeValue").toString(), jsonOrderLine.getJSONObject("product")
diff -r 741395712e24 web/org.openbravo.retail.posterminal/js/model/order.js
--- a/web/org.openbravo.retail.posterminal/js/model/order.js Tue Oct 24 12:22:57 2017 +0200
+++ b/web/org.openbravo.retail.posterminal/js/model/order.js Tue Oct 24 12:25:56 2017 +0200
@@ -4737,6 +4737,14 @@
OB.UTIL.showError("OBDAL error: " + error);
});
});
+ if (OB.MobileApp.model.hasPermission('OBPOS_EnableSupportForProductAttributes', true)) {
+ if (iter.attributeValue && _.isString(iter.attributeValue)) {
+ var processedAttValues = OB.UTIL.AttributeUtils.generateDescriptionBasedOnJson(iter.attributeValue);
+ if (processedAttValues && processedAttValues.keyValue && _.isArray(processedAttValues.keyValue) && processedAttValues.keyValue.length > 0) {
+ iter.attSetInstanceDesc = processedAttValues.description;
+ }
+ }
+ }
newline = new OrderLine({
id: iter.lineId,
product: prod,
@@ -4753,7 +4761,8 @@
id: iter.warehouse,
warehousename: iter.warehousename
},
- relatedLines: iter.relatedLines
+ relatedLines: iter.relatedLines,
+ attSetInstanceDesc: (iter.attSetInstanceDesc ? iter.attSetInstanceDesc : null)
});
// copy verbatim not owned properties -> modular properties.
diff -r 741395712e24 web/org.openbravo.retail.posterminal/js/utils/attributeUtils.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/web/org.openbravo.retail.posterminal/js/utils/attributeUtils.js Tue Oct 24 12:25:56 2017 +0200
@@ -0,0 +1,42 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2012-2017 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+ */
+
+/*global OB, _, Backbone, Promise */
+
+(function () {
+
+ OB.UTIL = window.OB.UTIL || {};
+ OB.UTIL.AttributeUtils = OB.UTIL.AttributeUtils || {};
+
+ OB.UTIL.AttributeUtils.generateDescriptionBasedOnJson = function (jsonStringAttValues) {
+ var jsonAttValues = JSON.parse(jsonStringAttValues);
+ var objToReturn = {
+ keyValue: [],
+ description: ''
+ };
+ var attSetInstanceDescription = '';
+ _.each(
+ _.keys(jsonAttValues), function (key) {
+ var currentValue = jsonAttValues[key];
+ var attValueContent = '';
+ if (jsonAttValues && currentValue && currentValue.value && _.isString(currentValue.value) && currentValue.value.length > 0) {
+ attValueContent += currentValue.label ? currentValue.label : currentValue.name;
+ attValueContent += ': ';
+ attValueContent += currentValue.value;
+ objToReturn.keyValue.push(attValueContent);
+ attSetInstanceDescription += currentValue.value + "_";
+ }
+ }, this);
+ if (attSetInstanceDescription && attSetInstanceDescription.length > 1) {
+ attSetInstanceDescription = attSetInstanceDescription.substring(0, attSetInstanceDescription.length - 1);
+ }
+ objToReturn.description = attSetInstanceDescription;
+ return objToReturn;
+ }
+}());
\ No newline at end of file
0_pi_q3_2.patch [^] (4,569 bytes) 2017-10-25 08:58 [Show Content] [Hide Content]diff -r 32c9467660ff src-db/database/model/functions/M_GETJSONDESCRIPTION.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src-db/database/model/functions/M_GETJSONDESCRIPTION.xml Tue Oct 24 14:24:23 2017 +0200
@@ -0,0 +1,82 @@
+<?xml version="1.0"?>
+ <database name="FUNCTION M_GETJSONDESCRIPTION">
+ <function name="M_GETJSONDESCRIPTION" type="VARCHAR">
+ <parameter name="p_attributesetinstance_id" type="VARCHAR" mode="in">
+ <default/>
+ </parameter>
+ <parameter name="p_exclude_characters" type="VARCHAR" mode="in">
+ <default/>
+ </parameter>
+ <parameter name="p_language_id" type="VARCHAR" mode="in">
+ <default/>
+ </parameter>
+ <parameter name="p_dateformatsql" type="VARCHAR" mode="in">
+ <default><![CDATA[DD-MM-YYYY]]></default>
+ </parameter>
+ <body><![CDATA[/*
+ ************************************************************************************
+ * Copyright (C) 2016-2017 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+ */
+
+ /*
+ * Generates a JSON with the attributesetinstance description.
+ * Example: '{"lot":{"value":"L0","name":"lot"},"serialno":{"value":"#0","name":"serialno"},"CEE55391F603473DBD164BF00A6FCDBC":{"value":"77","name":"Instanciable1"},"AC8962C737FA47D6872654D4C1769427":{"value":"","name":"Not Mandatory"}}'
+ */
+
+ v_json VARCHAR2(2000):='{';
+ v_serno VARCHAR2(2000):='';
+ v_lot VARCHAR2(2000):='';
+ v_guaranteedate VARCHAR2(2000):='';
+ v_serno_sk VARCHAR(60):='SerialNoLabel';
+ v_guaranteedate_sk VARCHAR(60):='ExpirationDateLabel';
+ v_lot_sk VARCHAR(60):='LotLabel';
+ v_serno_label AD_Message.MsgText%TYPE;
+ v_guaranteedate_label AD_Message.MsgText%TYPE;
+ v_lot_label AD_Message.MsgText%TYPE;
+ v_language_code VARCHAR(6);
+ TYPE RECORD IS REF CURSOR;
+ Cur_Attribute RECORD;
+
+BEGIN
+ SELECT ad_language into v_language_code from ad_language where ad_language_id = p_language_id;
+ select ad_message_get2(v_serno_sk, v_language_code) INTO v_serno_label from dual;
+ select ad_message_get2(v_guaranteedate_sk, v_language_code) INTO v_guaranteedate_label from dual;
+ select ad_message_get2(v_lot_sk, v_language_code) INTO v_lot_label from dual;
+
+ FOR Cur_Attribute IN
+ (SELECT mai.m_attribute_id as attributeId, coalesce(to_char(mai.value), '') as attributeValue, ma.name as attributeName, mau.seqno as seqNo, ma.ismandatory as isMandatory
+ FROM m_attributeinstance mai
+ INNER JOIN m_attribute ma on (ma.m_attribute_id=mai.m_attribute_id)
+ INNER JOIN m_attributesetinstance masi on (masi.m_attributesetinstance_id=mai.m_attributesetinstance_id)
+ INNER JOIN m_attributeuse mau on (ma.m_attribute_id = mau.m_attribute_id and masi.m_attributeset_id = mau.m_attributeset_id)
+ WHERE mai.m_attributesetinstance_id = p_attributesetinstance_id
+ ORDER BY seqno asc, ma.name)
+ LOOP
+ v_json:=v_json || '"' || Cur_Attribute.attributeId || '":{"value":"' || Cur_Attribute.attributeValue || '","name":"' || Cur_Attribute.attributeName || '","ismandatory":' || (CASE WHEN (Cur_Attribute.isMandatory = 'Y') THEN 'true' ELSE 'false' END) || ',"seqno":' || Cur_Attribute.seqNo || '},';
+ END LOOP;
+
+ SELECT coalesce(to_char(case when mas.M_SERNOCTL_ID is null AND p_exclude_characters = 'N' then concat('#', masi.serno) else masi.serno end), ''),
+ coalesce(to_char(case when mas.M_LOTCTL_ID is null AND p_exclude_characters = 'N' then concat('L', masi.lot) else masi.lot end), ''),
+ coalesce(to_char(TO_DATE(masi.guaranteedate), p_dateformatsql), '')
+ INTO v_serno,
+ v_lot,
+ v_guaranteedate
+ FROM m_attributesetinstance masi
+ INNER JOIN m_attributeset mas on (mas.m_attributeset_id = masi.m_attributeset_id)
+ where masi.m_attributesetinstance_id = p_attributesetinstance_id;
+
+ v_json:=v_json || '"lot":{"value":"' || v_lot || '","name":"lot","label":"' || v_lot_label || '"},';
+ v_json:=v_json || '"serialno":{"value":"' || v_serno || '","name":"serialno","label":"' || v_serno_label || '"},';
+ v_json:=v_json || '"guaranteedate":{"value":"' || v_guaranteedate || '","name":"guaranteedate","label":"' || v_guaranteedate_label || '"}';
+
+ v_json:=v_json || '}';
+
+ RETURN v_json;
+END M_GETJSONDESCRIPTION
+]]></body>
+ </function>
+ </database>
4_stockvalidation_q3.patch [^] (13,308 bytes) 2017-10-25 08:59 [Show Content] [Hide Content]
# HG changeset patch
# User Guillermo Alvarez de Eulate <guillermo.alvarez@openbravo.com>
# Date 1507880077 -7200
# Node ID e25140ad03838d34a02a7e411d22f7e8510362f0
# Parent 6b5524e30c63f76405668b2107055c4f0040b671
Related to issue 36966: Adapt stock validation module to -support for attributes- project
- When the attributes sent by client side are not valid -> Show error in the frontend
- When an item is not present in m_storage_detail try to pick different locator to use it as overissue
- When a quoation is approved and transformed into a sales order, the stock for the specific attribute is checked. it was not working
diff -r 6b5524e30c63 -r e25140ad0383 src/org/openbravo/retail/stockvalidation/OrderFromQuotationStockChecker.java
--- a/src/org/openbravo/retail/stockvalidation/OrderFromQuotationStockChecker.java Thu Oct 12 18:24:45 2017 +0200
+++ b/src/org/openbravo/retail/stockvalidation/OrderFromQuotationStockChecker.java Fri Oct 13 09:34:37 2017 +0200
@@ -4,6 +4,7 @@
import javax.servlet.ServletException;
+import org.apache.commons.lang.StringUtils;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
@@ -12,7 +13,9 @@
import org.openbravo.base.exception.OBException;
import org.openbravo.dal.core.OBContext;
import org.openbravo.dal.service.OBDal;
+import org.openbravo.mobile.core.utils.OBMOBCUtils;
import org.openbravo.retail.posterminal.JSONProcessSimple;
+import org.openbravo.retail.posterminal.utility.AttributesUtils;
public class OrderFromQuotationStockChecker extends JSONProcessSimple {
@Override
@@ -39,10 +42,18 @@
String productId = "";
String productIdentifier = "";
String lineIndex = "";
+ String attributeValue = "";
+ String validatedAttrSetInstanceDescription = "";
BigDecimal qtyToBuy;
currentTicketLine = linesOfTicket.getJSONObject(i);
qtyToBuy = new BigDecimal(currentTicketLine.getString("qty"));
productId = currentTicketLine.getString("productid");
+ if (OBMOBCUtils.isJsonObjectPropertyStringPresentNotNullAndNotEmptyString(
+ currentTicketLine, "attributeValue")) {
+ attributeValue = currentTicketLine.getString("attributeValue");
+ validatedAttrSetInstanceDescription = AttributesUtils
+ .generateValidAttSetInstanceDescription(attributeValue, productId);
+ }
productIdentifier = currentTicketLine.getString("productidentifier");
lineIndex = currentTicketLine.getString("index");
String hqlQuery = "select sum(ms.quantityOnHand) as qtyonhand "
@@ -50,11 +61,15 @@
+ "SELECT ow.warehouse.id " + "FROM OrganizationWarehouse as ow " + "WHERE "
+ "ow.organization.id = :orgId) and ms.product.id = :productId "
+ "and ms.quantityOnHand > 0 and ms.quantityOnHand > ms.reservedQty";
+ if (attributeValue != null && !attributeValue.isEmpty())
+ hqlQuery += " and ms.attributeSetValue.description = :attSetInstanceDesc";
final Session session = OBDal.getInstance().getSession();
final Query query = session.createQuery(hqlQuery);
query.setString("orgId", orgId);
query.setString("productId", productId);
+ if (attributeValue != null && !attributeValue.isEmpty())
+ query.setString("attSetInstanceDesc", validatedAttrSetInstanceDescription);
if (query.uniqueResult() != null) {
unitsFound = new BigDecimal(query.uniqueResult().toString());
@@ -66,9 +81,13 @@
allowSell = true;
} else {
String hqlQueryStatus = "select ms.storageBin.id as overissueStoreBin "
- + "from MaterialMgmtStorageDetail ms " + "where ms.storageBin.warehouse.id in ("
- + "SELECT ow.warehouse.id " + "FROM OrganizationWarehouse as ow "
- + "WHERE " + "ow.organization.id = :orgId) " + "and ms.product.id = :productId "
+ + "from MaterialMgmtStorageDetail ms "
+ + "where ms.storageBin.warehouse.id in ("
+ + "SELECT ow.warehouse.id "
+ + "FROM OrganizationWarehouse as ow "
+ + "WHERE "
+ + "ow.organization.id = :orgId) "
+ + "and ms.product.id = :productId "
+ "and ms.storageBin.inventoryStatus.overissue = 'Y' order by ms.storageBin.relativePriority";
final Session sessionStatus = OBDal.getInstance().getSession();
final Query queryStatus = sessionStatus.createQuery(hqlQueryStatus);
@@ -81,6 +100,27 @@
overissueQty = qtyToBuy.subtract(unitsFound);
} else {
overissueStoreBin = "";
+ if (StringUtils.isEmpty(overissueStoreBin)) {
+ String hqlQueryAnyOverissueBin = "select loc.id as overissueStoreBin "
+ + "from Locator loc " //
+ + "where loc.warehouse.id in (" //
+ + " SELECT ow.warehouse.id " //
+ + " FROM OrganizationWarehouse as ow " //
+ + " WHERE ow.organization.id = :orgId" //
+ + " ) " //
+ + "AND loc.inventoryStatus.overissue = 'Y' " //
+ + "ORDER BY loc.relativePriority ASC";
+ final Query queryAnyOverissueBin = OBDal.getInstance().getSession()
+ .createQuery(hqlQueryAnyOverissueBin);
+ queryAnyOverissueBin.setString("orgId", orgId);
+ queryAnyOverissueBin.setMaxResults(1);
+ if (queryAnyOverissueBin.uniqueResult() != null) {
+ overissueStoreBin = (String) queryAnyOverissueBin.uniqueResult();
+ overissueQty = BigDecimal.ZERO;
+ } else {
+ overissueStoreBin = "";
+ }
+ }
}
}
diff -r 6b5524e30c63 -r e25140ad0383 src/org/openbravo/retail/stockvalidation/StockChecker.java
--- a/src/org/openbravo/retail/stockvalidation/StockChecker.java Thu Oct 12 18:24:45 2017 +0200
+++ b/src/org/openbravo/retail/stockvalidation/StockChecker.java Fri Oct 13 09:34:37 2017 +0200
@@ -4,6 +4,7 @@
import javax.servlet.ServletException;
+import org.apache.commons.lang.StringUtils;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.hibernate.Query;
@@ -11,7 +12,9 @@
import org.openbravo.base.exception.OBException;
import org.openbravo.dal.core.OBContext;
import org.openbravo.dal.service.OBDal;
+import org.openbravo.mobile.core.utils.OBMOBCUtils;
import org.openbravo.retail.posterminal.JSONProcessSimple;
+import org.openbravo.retail.posterminal.utility.AttributesUtils;
public class StockChecker extends JSONProcessSimple {
@Override
@@ -20,6 +23,7 @@
BigDecimal unitsFound = new BigDecimal(0);
String overissueStoreBin = "";
BigDecimal overissueQty = BigDecimal.ZERO;
+ String validatedAttrSetInstanceDescription = "";
OBContext.setAdminMode(true);
try {
String orgId;
@@ -31,8 +35,12 @@
jsonOrderLine = jsonData.getJSONObject("orderLine");
jsonProduct = jsonOrderLine.getJSONObject("product");
- if (jsonOrderLine.has("attributeValue") && !jsonOrderLine.isNull("attributeValue")) {
+ String productId = jsonProduct.getString("id");
+ if (OBMOBCUtils.isJsonObjectPropertyStringPresentNotNullAndNotEmptyString(jsonOrderLine,
+ "attributeValue")) {
attributeValue = jsonOrderLine.getString("attributeValue");
+ validatedAttrSetInstanceDescription = AttributesUtils
+ .generateValidAttSetInstanceDescription(attributeValue, productId);
}
String hqlQuery = "select sum(ms.quantityOnHand-ms.reservedQty) as qtyonhand "
+ "from MaterialMgmtStorageDetail ms " + "where ms.storageBin.warehouse.id in ("
@@ -40,12 +48,16 @@
+ "ow.organization.id = :orgId) " + "and ms.product.id = :productId "
+ "and ms.quantityOnHand > 0 and ms.quantityOnHand > ms.reservedQty";
if (attributeValue != null && !attributeValue.isEmpty())
- hqlQuery += " and ms.attributeSetValue.description = '" + attributeValue + "'";
+ if (attributeValue != null && !attributeValue.isEmpty())
+ hqlQuery += " and ms.attributeSetValue.description = :attSetInstanceDesc";
final Session session = OBDal.getInstance().getSession();
final Query query = session.createQuery(hqlQuery);
query.setString("orgId", orgId);
- query.setString("productId", jsonProduct.getString("id"));
+ query.setString("productId", productId);
+ if (attributeValue != null && !attributeValue.isEmpty())
+ query.setString("attSetInstanceDesc", validatedAttrSetInstanceDescription);
+
if (query.uniqueResult() != null) {
unitsFound = new BigDecimal(query.uniqueResult().toString());
} else {
@@ -56,14 +68,18 @@
allowSell = true;
} else {
String hqlQueryStatus = "select ms.storageBin.id as overissueStoreBin "
- + "from MaterialMgmtStorageDetail ms " + "where ms.storageBin.warehouse.id in ("
- + "SELECT ow.warehouse.id " + "FROM OrganizationWarehouse as ow " + "WHERE "
- + "ow.organization.id = :orgId) " + "and ms.product.id = :productId "
+ + "from MaterialMgmtStorageDetail ms "
+ + "where ms.storageBin.warehouse.id in ("
+ + "SELECT ow.warehouse.id "
+ + "FROM OrganizationWarehouse as ow "
+ + "WHERE "
+ + "ow.organization.id = :orgId) "
+ + "and ms.product.id = :productId "
+ "and ms.storageBin.inventoryStatus.overissue = 'Y' order by ms.storageBin.relativePriority";
final Session sessionStatus = OBDal.getInstance().getSession();
final Query queryStatus = sessionStatus.createQuery(hqlQueryStatus);
queryStatus.setString("orgId", orgId);
- queryStatus.setString("productId", jsonProduct.getString("id"));
+ queryStatus.setString("productId", productId);
queryStatus.setMaxResults(1);
if (queryStatus.uniqueResult() != null) {
@@ -71,11 +87,31 @@
overissueQty = qtyToBuy.subtract(unitsFound);
} else {
overissueStoreBin = "";
+ if (StringUtils.isEmpty(overissueStoreBin)) {
+ String hqlQueryAnyOverissueBin = "select loc.id as overissueStoreBin "
+ + "from Locator loc " //
+ + "where loc.warehouse.id in (" //
+ + " SELECT ow.warehouse.id " //
+ + " FROM OrganizationWarehouse as ow " //
+ + " WHERE ow.organization.id = :orgId" //
+ + " ) " //
+ + "AND loc.inventoryStatus.overissue = 'Y' " //
+ + "ORDER BY loc.relativePriority ASC";
+ final Query queryAnyOverissueBin = OBDal.getInstance().getSession()
+ .createQuery(hqlQueryAnyOverissueBin);
+ queryAnyOverissueBin.setString("orgId", orgId);
+ queryAnyOverissueBin.setMaxResults(1);
+ if (queryAnyOverissueBin.uniqueResult() != null) {
+ overissueStoreBin = (String) queryAnyOverissueBin.uniqueResult();
+ overissueQty = BigDecimal.ZERO;
+ } else {
+ overissueStoreBin = "";
+ }
+ }
}
}
-
} catch (Exception e) {
- throw new OBException();
+ throw new OBException(e.getMessage(), true);
} finally {
OBContext.restorePreviousMode();
}
diff -r 6b5524e30c63 -r e25140ad0383 web/org.openbravo.retail.stockvalidation/js/modals.js
--- a/web/org.openbravo.retail.stockvalidation/js/modals.js Thu Oct 12 18:24:45 2017 +0200
+++ b/web/org.openbravo.retail.stockvalidation/js/modals.js Fri Oct 13 09:34:37 2017 +0200
@@ -42,6 +42,19 @@
}, function (data, message) {
statusMessage.hide();
OB.UTIL.showLoading(false);
+ if (data.exception) {
+ OB.UTIL.showConfirmation.display(OB.I18N.getLabel('OBMOBC_Error'), data.exception.message);
+ if (me.model.get('order').get('undo')) {
+ me.model.get('order').get('undo').undo(me.model);
+ } else {
+ if (data.qty <= 0) {
+ me.model.get('order').deleteLine(changedModel);
+ } else {
+ changedModel.set('qty', data.qty);
+ }
+ }
+ return true;
+ }
if (data.allowSell === false) {
if (data.allowNegativeStock) {
changedModel.set('overissueStoreBin', data.overissueStoreBin, {
@@ -239,6 +252,9 @@
lineToSend.qty = curLine.get('qty');
lineToSend.index = index;
lineToSend.stocked = curLine.get('product').get('stocked');
+ if (curLine.get('product').get('hasAttributes') && _.isString(curLine.get('attributeValue')) && curLine.get('attributeValue').length > 0) {
+ lineToSend.attributeValue = curLine.get('attributeValue');
+ }
dataToSend.push(lineToSend);
}
}, this);
4_stockvalidation_q3_2.patch [^] (1,050 bytes) 2017-10-25 09:00 [Show Content] [Hide Content]diff -r e25140ad0383 src/org/openbravo/retail/stockvalidation/StockChecker.java
--- a/src/org/openbravo/retail/stockvalidation/StockChecker.java Fri Oct 13 09:34:37 2017 +0200
+++ b/src/org/openbravo/retail/stockvalidation/StockChecker.java Tue Oct 24 12:29:40 2017 +0200
@@ -37,8 +37,14 @@
jsonProduct = jsonOrderLine.getJSONObject("product");
String productId = jsonProduct.getString("id");
if (OBMOBCUtils.isJsonObjectPropertyStringPresentNotNullAndNotEmptyString(jsonOrderLine,
- "attributeValue")) {
+ "attSetInstanceDesc")) {
+ attributeValue = jsonOrderLine.getString("attSetInstanceDesc");
+ } else if (OBMOBCUtils.isJsonObjectPropertyStringPresentNotNullAndNotEmptyString(
+ jsonOrderLine, "attributeValue")) {
attributeValue = jsonOrderLine.getString("attributeValue");
+ }
+
+ if (attributeValue != null) {
validatedAttrSetInstanceDescription = AttributesUtils
.generateValidAttSetInstanceDescription(attributeValue, productId);
}
3_returns_q3_2.patch [^] (2,536 bytes) 2017-10-25 09:00 [Show Content] [Hide Content]diff -r 26b91d28bd60 web/org.openbravo.retail.returns/js/modalReturnLines.js
--- a/web/org.openbravo.retail.returns/js/modalReturnLines.js Tue Oct 24 12:26:14 2017 +0200
+++ b/web/org.openbravo.retail.returns/js/modalReturnLines.js Tue Oct 24 12:28:37 2017 +0200
@@ -257,7 +257,8 @@
}
},
initComponents: function () {
- var movementQty = OB.DEC.Zero;
+ var movementQty = OB.DEC.Zero,
+ me = this;
_.each(this.newAttribute.shipmentlines, function (shipment) {
movementQty += shipment.remainingQty;
});
@@ -298,27 +299,17 @@
this.$.product.setContent(this.newAttribute.name);
if (OB.MobileApp.model.hasPermission('OBPOS_EnableSupportForProductAttributes', true)) {
if (this.newAttribute.attributeValue && _.isString(this.newAttribute.attributeValue)) {
- var jsonAttValues = JSON.parse(this.newAttribute.attributeValue);
-
- var attSetInstanceDescription = '';
- _.each(
- _.keys(jsonAttValues), function (key) {
- var currentValue = jsonAttValues[key];
- var attValueContent = '';
- if (jsonAttValues && currentValue) {
- attValueContent += currentValue.label ? currentValue.label : currentValue.name;
- attValueContent += ': ';
- attValueContent += currentValue.value;
- attSetInstanceDescription += currentValue.value + "_";
- this.$.attribute.createComponent({
- content: attValueContent
+ var processedAttValues = OB.UTIL.AttributeUtils.generateDescriptionBasedOnJson(this.newAttribute.attributeValue);
+ if (processedAttValues && processedAttValues.keyValue && _.isArray(processedAttValues.keyValue) && processedAttValues.keyValue.length > 0) {
+ _.each(processedAttValues.keyValue, function (item) {
+ me.$.attribute.createComponent({
+ content: item
});
- }
- }, this);
- if (attSetInstanceDescription && attSetInstanceDescription.length > 1) {
- attSetInstanceDescription = attSetInstanceDescription.substring(0, attSetInstanceDescription.length - 1);
+ });
+ this.newAttribute.attSetInstanceDesc = processedAttValues.description;
+ } else {
+ this.$.attribute.setContent('NA');
}
- this.newAttribute.attSetInstanceDesc = attSetInstanceDescription;
} else {
this.$.attribute.setContent('NA');
}
|