Fixes issue 25049: Filter "and" clause is not working ok
authorAugusto Mauch <augusto.mauch@openbravo.com>
Wed, 30 Oct 2013 23:39:07 +0100
changeset 21408 5a980493ea05
parent 21407 e5445b0f76a3
child 21409 4a43e052de88
child 22246 70b714f9e44e
Fixes issue 25049: Filter "and" clause is not working ok

This happened because a criterion with an 'and' operation does not include the fieldName as a root property. This property can be accessed from any of its inner criteria.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js	Wed Oct 30 20:46:49 2013 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js	Wed Oct 30 23:39:07 2013 +0100
@@ -236,7 +236,20 @@
   },
 
   canEditCriterion: function (criterion) {
-    return criterion && (criterion.fieldName === this.name || (this.criteriaField && (criterion.fieldName === this.criteriaField)));
+    var firstCriteria;
+    if (criterion.operator === 'and') {
+      // and operator does not include the fieldName as a root property
+      if (!criterion.criteria || criterion.criteria.length === 0) {
+        return true;
+      } else {
+        // all criteria of the criterion are associated with the same name, pick the first
+        firstCriteria = criterion.criteria[0];
+        return (firstCriteria.fieldName === this.name || (this.criteriaField && (firstCriteria.fieldName === this.criteriaField)));
+      }
+
+    } else {
+      return criterion && (criterion.fieldName === this.name || (this.criteriaField && (criterion.fieldName === this.criteriaField)));
+    }
   },
 
   getCriterion: function (textMatchStyle) {