Fixed issue 34900: Email definition of the template was not correctly selected
authorNaroa Iriarte <>
Thu, 12 Jan 2017 17:07:55 +0100
changeset 31479 ec94c6362d99
parent 31478 4cd8e4f37081
child 31480 1a343ca1fb00
Fixed issue 34900: Email definition of the template was not correctly selected

If there was more than one email definition, one of them set as default, sometimes, when clicking the email button, the application was not choosing the correct email definition, which is the one with the "default" checkbox checked. It can happen also to have an email definition with the default checked but the language is different from the bussines partner's language, in this case if there exists another template which is not checked as default, but its language is the language of the business partner, this will have priority.

The problem here was that there was a piece of code which was using a Map, and it was overwritting the email definitions with the same language. This happened because the key used to store the email definitions in that map was the language it self. So, in the case of having, for example three email definitions with the same language and one of them set as default was failing because in the map was only stored the last one.

To fix this a new condition has been added. Now, if the email definition is marked as default, it is stored in the map. It does not matter to overwrite the other email definitions because only one can be the default and will be the one stored here. If the email definition is not marked as default instead, a comparation will be done to check if there already exists an email definition with the same language. If not, then, this email configuration will be added to the map. This is to prevent deleting the default configurations of a language.
--- a/src/org/openbravo/erpCommon/utility/reporting/	Fri Jan 13 11:47:44 2017 +0100
+++ b/src/org/openbravo/erpCommon/utility/reporting/	Thu Jan 12 17:07:55 2017 +0100
@@ -49,7 +49,7 @@
       _Body = emailDefinitionData.getField("body");
       _Language = emailDefinitionData.getField("ad_language");
       if (emailDefinitionData.getField("isdefault") != null) {
-        _IsDefault = emailDefinitionData.getField("isdefault") == "Y" ? true : false;
+        _IsDefault = ("Y").equals(emailDefinitionData.getField("isdefault")) ? true : false;
       _Id = emailDefinitionData.getField("id");
@@ -94,10 +94,13 @@
       if (emailDefinitionsData.length > 0) {
         for (final EmailDefinitionData emailDefinitionData : emailDefinitionsData) {
           final EmailDefinition emailDefinition = new EmailDefinition(emailDefinitionData);
-          _EmailDefinitions.put(emailDefinition.getLanguage(), emailDefinition);
-          if (emailDefinition.isDefault())
+          String language = emailDefinition.getLanguage();
+          if (emailDefinition.isDefault()) {
             _DefaultEmailDefinition = emailDefinition;
+            _EmailDefinitions.put(language, emailDefinition);
+          } else if (!_EmailDefinitions.containsKey(language)) {
+            _EmailDefinitions.put(language, emailDefinition);
+          }
         if (_DefaultEmailDefinition == null && !_EmailDefinitions.isEmpty()) {
           _DefaultEmailDefinition = _EmailDefinitions.values().iterator().next();