Description | Up to now, the SAF-T module does not allow any user to update the name of any product already sold into a store set as “Portuguese Configuration”=true. This requirement is based on changing this behaviour.
Specifically, the scenario to cover is the one below: the same product that is sold in several countries is sold first in Portugal and for any reason its name needs to be updated. Currently, this will not be allowed due to the current validation, even if the change is done for a need in another country.
From this point on, the validation should be done on the Portuguese translation record of Product>Translation tab (M_Product_Trl). The objective of the change request is avoiding the impact of the validation to other countries where the Portuguese Configuration, and therefore the SAF-T modules, is not applying.
Obviously, from a business point of view, it is important to remark that this change will not be a removal of the existing validation but an update.
In addition it is important to raise that the new rule will be always configurable, so can be adaptable in each case.
Development rule:
--A new flag “Use translation product name” will be added in the ‘Organization’ window, ‘Portuguese Configuration’ section. The new flag will indicate where the validation is done.
--In case the flag mentioned above is marked for a selected SAF-T informer organization, the value informed as product name in the SAF-T/e-Fatura file will be the Portuguese translation one. If not existing, will inform the header product name.
This could trigger the following scenarios:
-Use translation product name=false
--In this case, the validation won’t be modified. It will be based on the header name of the products even if a portuguese translation exists.
-Use translation product name=true
--For the products where a Portuguese translation exists, the validation will apply on the translation name.
--For the products where a Portuguese translation does not exists, the validation will remain based on the header name of the products.
As per the scenarios described above, there is a need to warn the users about a missing PT translation in case the new flag “Use translation product name” is enabled:
In such case, if a product with no PT translation is called into a Portuguese POS (this means, the related store has Portuguese Configuration=true) a warning popup message should be raised.
Regarding an eCommerce scenario, if a product with no PT translation is involved in an order requested to be integrated in Openbravo, a warning message should be raised.
|
Attached Files | 0001-Fixes-issue-NOE-5142-Update-product-name-validation.patch [^] (20,583 bytes) 2021-11-30 17:29 [Show Content] [Hide Content]From 539261d89fa1a0402023c1c6c3c43dfd0254fca6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roberto=20Carlos=20Toledano=20G=C3=B3mez?=
<rctg82@gmail.com>
Date: Tue, 30 Nov 2021 10:23:25 -0500
Subject: [PATCH] Fixes issue NOE-5142: Update product name validation.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Development rules:
A new flag “Use translation product name” is added in the ‘Organization’ window, ‘Portuguese Configuration’ section. The new flag will indicate where the validation is done.
In case the flag mentioned above is marked for a selected SAF-T informer organization, the value informed as product name in SAF-T/e-Fatura file will be the Portuguese translation one. If not existing, will inform the header product name.
---
.../database/model/modifiedTables/AD_ORG.xml | 5 ++
src-db/database/sourcedata/AD_COLUMN.xml | 46 +++++++++++-
src-db/database/sourcedata/AD_ELEMENT.xml | 14 ++++
src-db/database/sourcedata/AD_FIELD.xml | 31 ++++++++
.../handler/SaftProductFieldsHandler.java | 40 +++++-----
.../handler/SaftProductTrlFieldsHandler.java | 73 +++++++++++++++++++
6 files changed, 185 insertions(+), 24 deletions(-)
create mode 100644 src/com/practicsbs/saftpt/handler/SaftProductTrlFieldsHandler.java
diff --git a/src-db/database/model/modifiedTables/AD_ORG.xml b/src-db/database/model/modifiedTables/AD_ORG.xml
index 18cfc3b..ba3d3fa 100644
--- a/src-db/database/model/modifiedTables/AD_ORG.xml
+++ b/src-db/database/model/modifiedTables/AD_ORG.xml
@@ -13,7 +13,12 @@
<default/>
<onCreateDefault/>
</column>
+ <column name="EM_SAFT_USETRANSLATION" primaryKey="false" required="true" type="CHAR" size="1" autoIncrement="false">
+ <default><![CDATA[N]]></default>
+ <onCreateDefault><![CDATA['N']]></onCreateDefault>
+ </column>
<check name="EM_SAFT_ISCASHVAT_CHECK"><![CDATA[ISACTIVE IN ('Y', 'N')]]></check>
<check name="EM_SAFT_ISPTCONFIG_CHECK"><![CDATA[ISACTIVE IN ('Y', 'N')]]></check>
+ <check name="EM_SAFT_USETRANSLATION_CHECK"><![CDATA[EM_SAFT_USETRANSLATION IN ('Y', 'N')]]></check>
</table>
</database>
diff --git a/src-db/database/sourcedata/AD_COLUMN.xml b/src-db/database/sourcedata/AD_COLUMN.xml
index 2641895..a4ef597 100644
--- a/src-db/database/sourcedata/AD_COLUMN.xml
+++ b/src-db/database/sourcedata/AD_COLUMN.xml
@@ -4315,7 +4315,7 @@
<!--CBAFE5B1B5C44E25A1EEB821F0809299--> <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
<!--CBAFE5B1B5C44E25A1EEB821F0809299--> <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
<!--CBAFE5B1B5C44E25A1EEB821F0809299--> <AD_MODULE_ID><![CDATA[AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA]]></AD_MODULE_ID>
-<!--CBAFE5B1B5C44E25A1EEB821F0809299--> <POSITION><![CDATA[107]]></POSITION>
+<!--CBAFE5B1B5C44E25A1EEB821F0809299--> <POSITION><![CDATA[119]]></POSITION>
<!--CBAFE5B1B5C44E25A1EEB821F0809299--> <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
<!--CBAFE5B1B5C44E25A1EEB821F0809299--> <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
<!--CBAFE5B1B5C44E25A1EEB821F0809299--> <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
@@ -4668,7 +4668,7 @@
<!--D8374533C5054DC7AFA85DDF6E558C27--> <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
<!--D8374533C5054DC7AFA85DDF6E558C27--> <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
<!--D8374533C5054DC7AFA85DDF6E558C27--> <AD_MODULE_ID><![CDATA[AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA]]></AD_MODULE_ID>
-<!--D8374533C5054DC7AFA85DDF6E558C27--> <POSITION><![CDATA[108]]></POSITION>
+<!--D8374533C5054DC7AFA85DDF6E558C27--> <POSITION><![CDATA[120]]></POSITION>
<!--D8374533C5054DC7AFA85DDF6E558C27--> <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
<!--D8374533C5054DC7AFA85DDF6E558C27--> <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
<!--D8374533C5054DC7AFA85DDF6E558C27--> <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
@@ -4837,6 +4837,46 @@
<!--DCA194DB22F9422C9580AB4408D3F54D--> <IS_CHILD_PROPERTY_IN_PARENT><![CDATA[Y]]></IS_CHILD_PROPERTY_IN_PARENT>
<!--DCA194DB22F9422C9580AB4408D3F54D--></AD_COLUMN>
+<!--DE773FACC045458887A90A1CC6EB49D5--><AD_COLUMN>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <AD_COLUMN_ID><![CDATA[DE773FACC045458887A90A1CC6EB49D5]]></AD_COLUMN_ID>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <NAME><![CDATA[EM_Saft_Usetranslation]]></NAME>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <DESCRIPTION><![CDATA[Activate the product name validation on its Portuguese translation]]></DESCRIPTION>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <HELP><![CDATA[Activate the product name validation on its Portuguese translation. For the products where a Portuguese translation does not exists, the validation will remain based on the header name of the products.]]></HELP>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <COLUMNNAME><![CDATA[EM_Saft_Usetranslation]]></COLUMNNAME>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <AD_TABLE_ID><![CDATA[155]]></AD_TABLE_ID>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <AD_REFERENCE_ID><![CDATA[20]]></AD_REFERENCE_ID>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <FIELDLENGTH><![CDATA[1]]></FIELDLENGTH>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <DEFAULTVALUE><![CDATA[N]]></DEFAULTVALUE>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISKEY><![CDATA[N]]></ISKEY>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <SEQNO><![CDATA[921]]></SEQNO>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <AD_ELEMENT_ID><![CDATA[614BDE43BBB5423B99033E9C736EB549]]></AD_ELEMENT_ID>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <AD_MODULE_ID><![CDATA[AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA]]></AD_MODULE_ID>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <POSITION><![CDATA[126]]></POSITION>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ALLOWSORTING><![CDATA[Y]]></ALLOWSORTING>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ALLOWFILTERING><![CDATA[Y]]></ALLOWFILTERING>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <ALLOWED_CROSS_ORG_LINK><![CDATA[N]]></ALLOWED_CROSS_ORG_LINK>
+<!--DE773FACC045458887A90A1CC6EB49D5--> <IS_CHILD_PROPERTY_IN_PARENT><![CDATA[N]]></IS_CHILD_PROPERTY_IN_PARENT>
+<!--DE773FACC045458887A90A1CC6EB49D5--></AD_COLUMN>
+
<!--DF1A136717FD41268B3D93343F361CD8--><AD_COLUMN>
<!--DF1A136717FD41268B3D93343F361CD8--> <AD_COLUMN_ID><![CDATA[DF1A136717FD41268B3D93343F361CD8]]></AD_COLUMN_ID>
<!--DF1A136717FD41268B3D93343F361CD8--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -5015,7 +5055,7 @@
<!--E8BBAF4765754053B98A535A81D32FFA--> <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
<!--E8BBAF4765754053B98A535A81D32FFA--> <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
<!--E8BBAF4765754053B98A535A81D32FFA--> <AD_MODULE_ID><![CDATA[AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA]]></AD_MODULE_ID>
-<!--E8BBAF4765754053B98A535A81D32FFA--> <POSITION><![CDATA[109]]></POSITION>
+<!--E8BBAF4765754053B98A535A81D32FFA--> <POSITION><![CDATA[121]]></POSITION>
<!--E8BBAF4765754053B98A535A81D32FFA--> <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
<!--E8BBAF4765754053B98A535A81D32FFA--> <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
<!--E8BBAF4765754053B98A535A81D32FFA--> <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
diff --git a/src-db/database/sourcedata/AD_ELEMENT.xml b/src-db/database/sourcedata/AD_ELEMENT.xml
index 1be55c3..b82a6d1 100644
--- a/src-db/database/sourcedata/AD_ELEMENT.xml
+++ b/src-db/database/sourcedata/AD_ELEMENT.xml
@@ -354,6 +354,20 @@
<!--5FAB6CB3C4734B619D475AD604D013DB--> <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
<!--5FAB6CB3C4734B619D475AD604D013DB--></AD_ELEMENT>
+<!--614BDE43BBB5423B99033E9C736EB549--><AD_ELEMENT>
+<!--614BDE43BBB5423B99033E9C736EB549--> <AD_ELEMENT_ID><![CDATA[614BDE43BBB5423B99033E9C736EB549]]></AD_ELEMENT_ID>
+<!--614BDE43BBB5423B99033E9C736EB549--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--614BDE43BBB5423B99033E9C736EB549--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--614BDE43BBB5423B99033E9C736EB549--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--614BDE43BBB5423B99033E9C736EB549--> <COLUMNNAME><![CDATA[EM_Saft_Usetranslation]]></COLUMNNAME>
+<!--614BDE43BBB5423B99033E9C736EB549--> <NAME><![CDATA[Use translation product name]]></NAME>
+<!--614BDE43BBB5423B99033E9C736EB549--> <PRINTNAME><![CDATA[Use translation product name]]></PRINTNAME>
+<!--614BDE43BBB5423B99033E9C736EB549--> <DESCRIPTION><![CDATA[Activate the product name validation on its Portuguese translation]]></DESCRIPTION>
+<!--614BDE43BBB5423B99033E9C736EB549--> <HELP><![CDATA[Activate the product name validation on its Portuguese translation. For the products where a Portuguese translation does not exists, the validation will remain based on the header name of the products.]]></HELP>
+<!--614BDE43BBB5423B99033E9C736EB549--> <AD_MODULE_ID><![CDATA[AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA]]></AD_MODULE_ID>
+<!--614BDE43BBB5423B99033E9C736EB549--> <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
+<!--614BDE43BBB5423B99033E9C736EB549--></AD_ELEMENT>
+
<!--6457B61CD12E465F8571E10CB9480712--><AD_ELEMENT>
<!--6457B61CD12E465F8571E10CB9480712--> <AD_ELEMENT_ID><![CDATA[6457B61CD12E465F8571E10CB9480712]]></AD_ELEMENT_ID>
<!--6457B61CD12E465F8571E10CB9480712--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff --git a/src-db/database/sourcedata/AD_FIELD.xml b/src-db/database/sourcedata/AD_FIELD.xml
index e73da8a..54f7a72 100644
--- a/src-db/database/sourcedata/AD_FIELD.xml
+++ b/src-db/database/sourcedata/AD_FIELD.xml
@@ -3020,6 +3020,37 @@
<!--F0D5A8809AF04C46A5D828578DDAF258--> <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
<!--F0D5A8809AF04C46A5D828578DDAF258--></AD_FIELD>
+<!--F326595CB90043BBBA4D9172966AFBF7--><AD_FIELD>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <AD_FIELD_ID><![CDATA[F326595CB90043BBBA4D9172966AFBF7]]></AD_FIELD_ID>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <NAME><![CDATA[Use translation product name]]></NAME>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <DESCRIPTION><![CDATA[Activate the product name validation on its Portuguese translation]]></DESCRIPTION>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <HELP><![CDATA[Activate the product name validation on its Portuguese translation. For the products where a Portuguese translation does not exists, the validation will remain based on the header name of the products.]]></HELP>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <AD_TAB_ID><![CDATA[143]]></AD_TAB_ID>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <AD_COLUMN_ID><![CDATA[DE773FACC045458887A90A1CC6EB49D5]]></AD_COLUMN_ID>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <AD_FIELDGROUP_ID><![CDATA[8B0DC58E8AF54346A62A4D5E96D30D4B]]></AD_FIELDGROUP_ID>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <DISPLAYLOGIC><![CDATA[@em_saft_isptconfig@='Y']]></DISPLAYLOGIC>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <DISPLAYLENGTH><![CDATA[0]]></DISPLAYLENGTH>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <SEQNO><![CDATA[115]]></SEQNO>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <AD_MODULE_ID><![CDATA[AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA]]></AD_MODULE_ID>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <GRID_SEQNO><![CDATA[1500]]></GRID_SEQNO>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--F326595CB90043BBBA4D9172966AFBF7--> <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--F326595CB90043BBBA4D9172966AFBF7--></AD_FIELD>
+
<!--F61F9800D5CC465BBE69522BC0591E29--><AD_FIELD>
<!--F61F9800D5CC465BBE69522BC0591E29--> <AD_FIELD_ID><![CDATA[F61F9800D5CC465BBE69522BC0591E29]]></AD_FIELD_ID>
<!--F61F9800D5CC465BBE69522BC0591E29--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff --git a/src/com/practicsbs/saftpt/handler/SaftProductFieldsHandler.java b/src/com/practicsbs/saftpt/handler/SaftProductFieldsHandler.java
index 79fb0ab..6c4ba9b 100644
--- a/src/com/practicsbs/saftpt/handler/SaftProductFieldsHandler.java
+++ b/src/com/practicsbs/saftpt/handler/SaftProductFieldsHandler.java
@@ -2,15 +2,15 @@ package com.practicsbs.saftpt.handler;
import javax.enterprise.event.Observes;
-import org.hibernate.criterion.Restrictions;
import org.openbravo.base.exception.OBException;
import org.openbravo.base.model.Entity;
import org.openbravo.base.model.ModelProvider;
import org.openbravo.base.model.Property;
+import org.openbravo.base.structure.BaseOBObject;
import org.openbravo.client.kernel.event.EntityNewEvent;
import org.openbravo.client.kernel.event.EntityUpdateEvent;
-import org.openbravo.dal.service.OBCriteria;
import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBQuery;
import org.openbravo.model.common.invoice.InvoiceLine;
import org.openbravo.model.common.order.OrderLine;
import org.openbravo.model.common.plm.Product;
@@ -85,27 +85,25 @@ public class SaftProductFieldsHandler extends SaftFieldsHandler {
return;
}
- // Check Invoice Lines:
- OBCriteria<InvoiceLine> invoiceLineCriteria = OBDal.getInstance()
- .createCriteria(InvoiceLine.class);
- invoiceLineCriteria.add(Restrictions.eq(InvoiceLine.PROPERTY_PRODUCT, prod));
- invoiceLineCriteria.add(Restrictions.isNotNull(InvoiceLine.PROPERTY_SAFTLINENUM));
- invoiceLineCriteria.setMaxResults(1);
- invoiceLineCriteria.setFilterOnReadableOrganization(false);
-
- if (invoiceLineCriteria.count() != 0) {
+ if (checkLines(InvoiceLine.class, prod) || checkLines(OrderLine.class, prod)) {
throw new OBException(SaftUtility.getMessageFromBD("SAFT_ChangeProductDescription"));
}
+ }
- // Check Order Lines:
- OBCriteria<OrderLine> orderLineCriteria = OBDal.getInstance().createCriteria(OrderLine.class);
- orderLineCriteria.add(Restrictions.eq(OrderLine.PROPERTY_PRODUCT, prod));
- orderLineCriteria.add(Restrictions.isNotNull(OrderLine.PROPERTY_SAFTLINENUM));
- orderLineCriteria.setFilterOnReadableOrganization(false);
- orderLineCriteria.setMaxResults(1);
-
- if (orderLineCriteria.count() != 0) {
- throw new OBException(SaftUtility.getMessageFromBD("SAFT_ChangeProductDescription"));
- }
+ private boolean checkLines(Class<? extends BaseOBObject> obDalType, final Product prod) {
+ // @formatter:off
+ String hql = " as l "
+ + " join l.organization o "
+ + " where l.product.id = :productId "
+ + " and l.saftLinenum is not NULL "
+ + " and (o.saftUsetranslation = false "
+ + " or not exists (select 1 from ProductTrl pt where pt.product.id = :productId and pt.language.language = 'pt_PT') "
+ + " ) ";
+ // @formatter:on
+ OBQuery<?> query = OBDal.getInstance().createQuery(obDalType, hql);
+ query.setNamedParameter("productId", prod.getId());
+ query.setFilterOnReadableOrganization(false);
+ query.setMaxResult(1);
+ return query.uniqueResult() != null;
}
}
diff --git a/src/com/practicsbs/saftpt/handler/SaftProductTrlFieldsHandler.java b/src/com/practicsbs/saftpt/handler/SaftProductTrlFieldsHandler.java
new file mode 100644
index 0000000..77b0513
--- /dev/null
+++ b/src/com/practicsbs/saftpt/handler/SaftProductTrlFieldsHandler.java
@@ -0,0 +1,73 @@
+package com.practicsbs.saftpt.handler;
+
+import javax.enterprise.event.Observes;
+
+import org.openbravo.base.exception.OBException;
+import org.openbravo.base.model.Entity;
+import org.openbravo.base.model.ModelProvider;
+import org.openbravo.base.model.Property;
+import org.openbravo.base.structure.BaseOBObject;
+import org.openbravo.client.kernel.event.EntityUpdateEvent;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBQuery;
+import org.openbravo.model.common.invoice.InvoiceLine;
+import org.openbravo.model.common.order.OrderLine;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.common.plm.ProductTrl;
+
+import com.practicsbs.saftpt.SaftUtility;
+
+public class SaftProductTrlFieldsHandler extends SaftFieldsHandler {
+
+ private static Entity[] entities = {
+ ModelProvider.getInstance().getEntity(ProductTrl.ENTITY_NAME) };
+
+ @Override
+ protected Entity[] getObservedEntities() {
+ return entities;
+ }
+
+ public void onUpdate(@Observes EntityUpdateEvent event) {
+ if (!isValidEvent(event)) {
+ return;
+ }
+ ProductTrl prodTrl = (ProductTrl) event.getTargetInstance();
+
+ if (!isPortugueseConfigurationEnabled(prodTrl.getProduct())) {
+ return;
+ }
+
+ validateChangeProductTrlDescription(event, prodTrl);
+ }
+
+ private void validateChangeProductTrlDescription(EntityUpdateEvent event, ProductTrl prodTrl) {
+
+ Entity targetEntity = event.getTargetInstance().getEntity();
+
+ Property propName = targetEntity.getProperty(ProductTrl.PROPERTY_NAME);
+ String oldName = (String) event.getPreviousState(propName);
+ Product prod = prodTrl.getProduct();
+
+ if (!oldName.equalsIgnoreCase(prodTrl.getName())
+ && prodTrl.getLanguage().getLanguage().equals("pt_PT")
+ && (checkLines(InvoiceLine.class, prod) || checkLines(OrderLine.class, prod))) {
+ throw new OBException(SaftUtility.getMessageFromBD("SAFT_ChangeProductDescription"));
+ }
+ }
+
+ private boolean checkLines(Class<? extends BaseOBObject> obDalType, final Product prod) {
+ // @formatter:off
+ String hql = " as l "
+ + " join l.organization o "
+ + " where l.product.id = :productId "
+ + " and l.saftLinenum is not null "
+ + " and o.saftUsetranslation = true ";
+
+ // @formatter:on
+ OBQuery<?> query = OBDal.getInstance().createQuery(obDalType, hql);
+ query.setNamedParameter("productId", prod.getId());
+ query.setFilterOnReadableOrganization(false);
+ query.setMaxResult(1);
+ return query.uniqueResult() != null;
+ }
+}
--
2.30.2
|