Attached Files | Feature Request.diff [^] (15,690 bytes) 2021-09-10 14:48 [Show Content] [Hide Content]diff --git a/src-db/database/sourcedata/AD_MESSAGE.xml b/src-db/database/sourcedata/AD_MESSAGE.xml
index c851319858bfd766a2313d7c1d17fc1239a9a5a3..ba1cea9b50f5b419dba3fb95c3a67ffba0701ef8 100644
--- a/src-db/database/sourcedata/AD_MESSAGE.xml
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml
@@ -1,5 +1,17 @@
<?xml version='1.0' encoding='UTF-8'?>
<data>
+<!--21D3391F62954DDDBD4B572E0019001B--><AD_MESSAGE>
+<!--21D3391F62954DDDBD4B572E0019001B--> <AD_MESSAGE_ID><![CDATA[21D3391F62954DDDBD4B572E0019001B]]></AD_MESSAGE_ID>
+<!--21D3391F62954DDDBD4B572E0019001B--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--21D3391F62954DDDBD4B572E0019001B--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--21D3391F62954DDDBD4B572E0019001B--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--21D3391F62954DDDBD4B572E0019001B--> <VALUE><![CDATA[OBCOMBO_ImportProductInDiscountPrompt]]></VALUE>
+<!--21D3391F62954DDDBD4B572E0019001B--> <MSGTEXT><![CDATA[Upload a file to import products into the combo family]]></MSGTEXT>
+<!--21D3391F62954DDDBD4B572E0019001B--> <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--21D3391F62954DDDBD4B572E0019001B--> <AD_MODULE_ID><![CDATA[4A04E9526D26474999736FE44BFF57FF]]></AD_MODULE_ID>
+<!--21D3391F62954DDDBD4B572E0019001B--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--21D3391F62954DDDBD4B572E0019001B--></AD_MESSAGE>
+
<!--391D0B6193B24F62BE0FF7D60E80695D--><AD_MESSAGE>
<!--391D0B6193B24F62BE0FF7D60E80695D--> <AD_MESSAGE_ID><![CDATA[391D0B6193B24F62BE0FF7D60E80695D]]></AD_MESSAGE_ID>
<!--391D0B6193B24F62BE0FF7D60E80695D--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff --git a/src-db/database/sourcedata/AD_MODEL_OBJECT.xml b/src-db/database/sourcedata/AD_MODEL_OBJECT.xml
new file mode 100644
index 0000000000000000000000000000000000000000..c89a2af4b62f7881d62deb2c1ec44b97644b5fc6
--- /dev/null
+++ b/src-db/database/sourcedata/AD_MODEL_OBJECT.xml
@@ -0,0 +1,16 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<data>
+<!--A6F61361698D44D8A0A95A6B28A2ACCA--><AD_MODEL_OBJECT>
+<!--A6F61361698D44D8A0A95A6B28A2ACCA--> <AD_MODEL_OBJECT_ID><![CDATA[A6F61361698D44D8A0A95A6B28A2ACCA]]></AD_MODEL_OBJECT_ID>
+<!--A6F61361698D44D8A0A95A6B28A2ACCA--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A6F61361698D44D8A0A95A6B28A2ACCA--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A6F61361698D44D8A0A95A6B28A2ACCA--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A6F61361698D44D8A0A95A6B28A2ACCA--> <ACTION><![CDATA[P]]></ACTION>
+<!--A6F61361698D44D8A0A95A6B28A2ACCA--> <CLASSNAME><![CDATA[org.openbravo.retail.discounts.combo.businesslogic.ImportProductIntoComboFamily]]></CLASSNAME>
+<!--A6F61361698D44D8A0A95A6B28A2ACCA--> <ISDEFAULT><![CDATA[N]]></ISDEFAULT>
+<!--A6F61361698D44D8A0A95A6B28A2ACCA--> <AD_MODULE_ID><![CDATA[4A04E9526D26474999736FE44BFF57FF]]></AD_MODULE_ID>
+<!--A6F61361698D44D8A0A95A6B28A2ACCA--> <OBJECT_TYPE><![CDATA[S]]></OBJECT_TYPE>
+<!--A6F61361698D44D8A0A95A6B28A2ACCA--> <NAME><![CDATA[Import Product into Combo Family]]></NAME>
+<!--A6F61361698D44D8A0A95A6B28A2ACCA--></AD_MODEL_OBJECT>
+
+</data>
diff --git a/src-db/database/sourcedata/AD_MODEL_OBJECT_MAPPING.xml b/src-db/database/sourcedata/AD_MODEL_OBJECT_MAPPING.xml
new file mode 100644
index 0000000000000000000000000000000000000000..f99cd59fd435491b0d0f93a7a38b45574186a77b
--- /dev/null
+++ b/src-db/database/sourcedata/AD_MODEL_OBJECT_MAPPING.xml
@@ -0,0 +1,13 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<data>
+<!--FA0DBEBBCACB48629BB77EE5EB42C831--><AD_MODEL_OBJECT_MAPPING>
+<!--FA0DBEBBCACB48629BB77EE5EB42C831--> <AD_MODEL_OBJECT_MAPPING_ID><![CDATA[FA0DBEBBCACB48629BB77EE5EB42C831]]></AD_MODEL_OBJECT_MAPPING_ID>
+<!--FA0DBEBBCACB48629BB77EE5EB42C831--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FA0DBEBBCACB48629BB77EE5EB42C831--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FA0DBEBBCACB48629BB77EE5EB42C831--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FA0DBEBBCACB48629BB77EE5EB42C831--> <AD_MODEL_OBJECT_ID><![CDATA[A6F61361698D44D8A0A95A6B28A2ACCA]]></AD_MODEL_OBJECT_ID>
+<!--FA0DBEBBCACB48629BB77EE5EB42C831--> <MAPPINGNAME><![CDATA[/ApplicationDataUpload/ImportProductIntoComboFamily]]></MAPPINGNAME>
+<!--FA0DBEBBCACB48629BB77EE5EB42C831--> <ISDEFAULT><![CDATA[Y]]></ISDEFAULT>
+<!--FA0DBEBBCACB48629BB77EE5EB42C831--></AD_MODEL_OBJECT_MAPPING>
+
+</data>
diff --git a/src/org/openbravo/retail/discounts/combo/ComboComponentProvide.java b/src/org/openbravo/retail/discounts/combo/ComboComponentProvide.java
index bfe671dc1f47e5558a312ff7573c0394b6377a56..2e4d5bf845ce7c32e722d5848fe9d327a21590aa 100644
--- a/src/org/openbravo/retail/discounts/combo/ComboComponentProvide.java
+++ b/src/org/openbravo/retail/discounts/combo/ComboComponentProvide.java
@@ -37,6 +37,8 @@ public class ComboComponentProvide extends BaseComponentProvider {
final List<ComponentResource> globalResources = new ArrayList<>();
final String prefix = "web/org.openbravo.retail.discounts.combo";
+ final String[] staticResourceDependency = { "combo-import-product-toolbar" };
+
final String[] resourceDependency = { "combo-rule-impl", "combo-popup", "combo-datahook" };
final String[] cssDependency = { "css/combo-popup" };
@@ -51,6 +53,12 @@ public class ComboComponentProvide extends BaseComponentProvider {
prefix + "/assets/" + resource + ".css", "WebPOS"));
}
+ globalResources.add(createStyleSheetResource(prefix + "/assets/css/combo-popup.css", false));
+
+ for (String resource : staticResourceDependency) {
+ globalResources.add(createStaticResource(prefix + "/source/" + resource + ".js", true));
+ }
+
final ArrayList<String> appDependency = new ArrayList<>();
appDependency.add("model/masterdata/DiscountFilterFamilyModel");
appDependency.add("model/masterdata/DiscountFilterFamilyProductModel");
diff --git a/src/org/openbravo/retail/discounts/combo/businesslogic/ImportProductIntoComboFamily.java b/src/org/openbravo/retail/discounts/combo/businesslogic/ImportProductIntoComboFamily.java
new file mode 100644
index 0000000000000000000000000000000000000000..8584e1b02fba829a19599f2e8554e87b02eca1a2
--- /dev/null
+++ b/src/org/openbravo/retail/discounts/combo/businesslogic/ImportProductIntoComboFamily.java
@@ -0,0 +1,133 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.1 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2019 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ */
+
+package org.openbravo.retail.discounts.combo.businesslogic;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.math.BigDecimal;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.List;
+
+import org.codehaus.jettison.json.JSONObject;
+import org.hibernate.Session;
+import org.hibernate.query.NativeQuery;
+import org.openbravo.base.provider.OBProvider;
+import org.openbravo.client.application.businesslogic.ProcessUploadedFile;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBQuery;
+import org.openbravo.erpCommon.utility.OBMessageUtils;
+import org.openbravo.retail.discounts.combo.ComboProduct;
+import org.openbravo.retail.discounts.combo.ComboProductFamily;
+
+public class ImportProductIntoComboFamily extends ProcessUploadedFile {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void clearBeforeImport(String ownerId, JSONObject paramValues) {
+ @SuppressWarnings("unchecked")
+ NativeQuery<String> qry = OBDal.getInstance()
+ .getSession()
+ .createNativeQuery(
+ "delete from OBCOMBO_Product where Obcombo_Family_ID = :obcombo_family_id");
+ qry.setParameter("obcombo_family_id", ownerId);
+ qry.executeUpdate();
+ }
+
+ @Override
+ protected UploadResult doProcessFile(JSONObject paramValues, File file) throws Exception {
+ final UploadResult uploadResult = new UploadResult();
+ final String familyId = paramValues.getString("inpOwnerId");
+ final ComboProductFamily comboFamily = OBDal.getInstance()
+ .get(ComboProductFamily.class, familyId);
+ final String errorMsgProductNotFound = OBMessageUtils.getI18NMessage("OBUIAPP_ProductNotFound",
+ new String[0]);
+ final String errorMsgProductNotUnique = OBMessageUtils
+ .getI18NMessage("OBUIAPP_ProductNotUnique", new String[0]);
+
+ try (BufferedReader br = Files.newBufferedReader(Paths.get(file.getAbsolutePath()))) {
+ String line;
+ while ((line = br.readLine()) != null) {
+ String[] productLine = line.split(",");
+ // ignore spaces
+ if (productLine.length == 0) {
+ continue;
+ }
+
+ String productSearchKey = productLine[0].trim();
+
+ BigDecimal fixedPrice = productLine.length == 2 ? new BigDecimal(productLine[1].trim())
+ : new BigDecimal("-1");
+
+ uploadResult.incTotalCount();
+
+ final List<String> productIds = getProductIds(productSearchKey);
+ if (productIds.size() == 0) {
+ uploadResult.incErrorCount();
+ uploadResult.addErrorMessage(productSearchKey + " --> " + errorMsgProductNotFound + "\n");
+ } else if (productIds.size() > 1) {
+ uploadResult.incErrorCount();
+ uploadResult
+ .addErrorMessage(productSearchKey + " --> " + errorMsgProductNotUnique + "\n");
+ } else {
+ // check if the line already exists
+ final String productId = productIds.get(0);
+ final OBQuery<ComboProduct> comboProductQry = OBDal.getInstance()
+ .createQuery(ComboProduct.class,
+ "Obcombo_Family_ID=:obcombo_family_id and m_product_id=:m_product_id");
+ comboProductQry.setNamedParameter("obcombo_family_id", familyId);
+ comboProductQry.setNamedParameter("m_product_id", productId);
+ final List<ComboProduct> lines = comboProductQry.list();
+ ComboProduct productDiscount = null;
+ if (lines.size() == 0) {
+ // create a new one
+ productDiscount = OBProvider.getInstance().get(ComboProduct.class);
+ productDiscount.setClient(comboFamily.getClient());
+ productDiscount.setOrganization(comboFamily.getOrganization());
+ productDiscount.setObcomboFamily(comboFamily);
+ productDiscount.setProduct(
+ OBDal.getInstance().get(org.openbravo.model.common.plm.Product.class, productId));
+ } else {
+ // get the line from the result
+ productDiscount = lines.get(0);
+ }
+
+ if (fixedPrice.compareTo(new BigDecimal("-1")) != 0
+ && "FIXPRICE".equals(comboFamily.getDiscountType())) {
+ productDiscount.setProductFixedPrice(fixedPrice);
+ }
+ OBDal.getInstance().save(productDiscount);
+ }
+ }
+ }
+ return uploadResult;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected List<String> getProductIds(String productKey) {
+ String sql = "SELECT m_product_id from m_product where value=:value";
+ Session session = OBDal.getInstance().getSession();
+ @SuppressWarnings("rawtypes")
+ NativeQuery qry = session.createNativeQuery(sql).setParameter("value", productKey);
+ // only need max 2 to identify that there is more than one
+ qry.setMaxResults(2);
+ return (List<String>) qry.list();
+ }
+}
diff --git a/web/org.openbravo.retail.discounts.combo/assets/css/combo-popup.css b/web/org.openbravo.retail.discounts.combo/assets/css/combo-popup.css
index 5ded3af1b67a6b36c17439a2f73b788c0039be6b..c496c93ee1ce8cbad80d91bda4cbf2ffc31cce8a 100644
--- a/web/org.openbravo.retail.discounts.combo/assets/css/combo-popup.css
+++ b/web/org.openbravo.retail.discounts.combo/assets/css/combo-popup.css
@@ -262,4 +262,16 @@ li.selected > .obObposPointOfSaleUiComboPopupBodycFamilyButton {
font-size: 24px;
background-color: var(--color-primary);
color: #e8e8e8;
+}
+
+.OBToolbarIconButton_icon_ob-upload-import-product-in-combo-family {
+ background-repeat: no-repeat;
+ background-position: center center;
+ background-image: url(./../../../org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.client.application/images/toolbar/iconButton-import.png);
+}
+
+.OBToolbarIconButton_icon_ob-upload-import-product-in-combo-familyProgress {
+ background-repeat: no-repeat;
+ background-position: center center;
+ background-image: url(./../../../org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.client.application/images/toolbar/iconButton-progress.gif); /* Generated @ http://www.ajaxload.info/ */ /* Indicator type: 'Snake' - Background color: #64932D - Transparent background - Foreground color: #FFFFFF */
}
\ No newline at end of file
diff --git a/web/org.openbravo.retail.discounts.combo/source/combo-import-product-toolbar.js b/web/org.openbravo.retail.discounts.combo/source/combo-import-product-toolbar.js
new file mode 100644
index 0000000000000000000000000000000000000000..f2d01a466645f7deec6f85704bc9dc026d2377e5
--- /dev/null
+++ b/web/org.openbravo.retail.discounts.combo/source/combo-import-product-toolbar.js
@@ -0,0 +1,40 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.1 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2021 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s): ______________________________________.
+ ************************************************************************
+ */
+
+(function() {
+ // Import Product in Discounts
+ var ProductDiscountButtonProps = isc.addProperties(
+ {},
+ isc.OBUploadView.UPLOAD_BUTTON_PROPERTIES,
+ {
+ actionUrl: './ApplicationDataUpload/ImportProductIntoComboFamily',
+ inChildTab: true,
+ popupTitle: OB.I18N.getLabel('OBUIAPP_ImportProductInDiscount'),
+ prompt: OB.I18N.getLabel('OBCOMBO_ImportProductInDiscountPrompt'),
+ buttonType: 'ob-upload-import-product-in-combo-family'
+ }
+ );
+ OB.ToolbarRegistry.registerButton(
+ ProductDiscountButtonProps.buttonType,
+ isc.OBToolbarIconButton,
+ ProductDiscountButtonProps,
+ 500,
+ ['25EAF1C2A3BA4F6597DAD51B7695DABB', 'B43CA46F193F40038947BC08A4DB6662']
+ );
+})();
|