svn commit: r1750856 - /ofbiz/trunk/framework/common/groovyScripts/FindAutocompleteOptions.groovy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1750856 - /ofbiz/trunk/framework/common/groovyScripts/FindAutocompleteOptions.groovy

nmalin
Author: nmalin
Date: Thu Jun 30 19:38:13 2016
New Revision: 1750856

URL: http://svn.apache.org/viewvc?rev=1750856&view=rev
Log:
Add new functionnality on auto-complete lookup field do offer the possibility for developper to add condition dates for the search on the lookup screen.

To automatically filter on fromDate thruDate attribute with value now, init a condition map like
     <set field="conditionDates.default" value="Y"/>

To use specific attribute date with value now
      <set field="conditionDates.fromDateName" value="startDate"/>
      <set field="conditionDates.thruDateName" value="endDate"/>

To use an other value than now
      <set field="conditionDates.filterByDateValue" from-field="invoice.invoiceDate"/>
or
      <set field="conditionDates.filterByDateValue" value="2016-01-01 00:00:00" type="Timestamp"/>

You can also set only low border date
      <set field="conditionDates.fromDateName" value="fromDate"/>
Or you can also set only high border date
      <set field="conditionDates.thruDateName" value="endDate"/>

Thanks to Kongrath Suankaewmanee for the proposition follow on issue OFBIZ-7266

Modified:
    ofbiz/trunk/framework/common/groovyScripts/FindAutocompleteOptions.groovy

Modified: ofbiz/trunk/framework/common/groovyScripts/FindAutocompleteOptions.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/groovyScripts/FindAutocompleteOptions.groovy?rev=1750856&r1=1750855&r2=1750856&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/groovyScripts/FindAutocompleteOptions.groovy (original)
+++ ofbiz/trunk/framework/common/groovyScripts/FindAutocompleteOptions.groovy Thu Jun 30 19:38:13 2016
@@ -18,6 +18,7 @@
  */
 
 import org.ofbiz.base.util.StringUtil;
+import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.entity.util.EntityFindOptions;
 import org.ofbiz.entity.condition.EntityCondition;
@@ -47,6 +48,23 @@ if (searchValueFieldName) {
 def searchType = context.searchType;
 def displayFieldsSet = null;
 
+def conditionDates = context.conditionDates;
+def fromDateName = null;
+def thruDateName = null;
+def filterByDateValue = null;
+
+//If conditionDates is present on context, resolve values use add condition date to the condition search
+if (conditionDates) {
+    filterByDateValue = conditionDates.filterByDateValue ?: UtilDateTime.nowTimestamp();
+    fromDateName = conditionDates.fromDateName ?: null;
+    thruDateName = conditionDates.thruDateName ?: null;
+    //if the field filterByDate is present, init default value for fromDate and thruDate
+    if (!fromDateName && !thruDateName) {
+        fromDateName = "fromDate";
+        thruDateName = "thruDate";
+    }
+}
+
 if (searchFields && fieldValue) {
     def searchFieldsList = StringUtil.toList(searchFields);
     displayFieldsSet = StringUtil.toSet(displayFields);
@@ -102,6 +120,24 @@ if (orExprs && entityName && displayFiel
     if (context.andCondition && context.andCondition instanceof EntityCondition) {
         mainAndConds.add(context.andCondition);
     }
+    if (conditionDates) {
+        def condsDateList = [];
+        if (thruDateName) {
+            def condsByThruDate = [];
+            condsByThruDate.add(EntityCondition.makeCondition(EntityFieldValue.makeFieldValue(thruDateName), EntityOperator.GREATER_THAN, filterByDateValue));
+            condsByThruDate.add(EntityCondition.makeCondition(EntityFieldValue.makeFieldValue(thruDateName), EntityOperator.EQUALS, null));
+            condsDateList.add(EntityCondition.makeCondition(condsByThruDate, EntityOperator.OR));
+        }
+
+        if (fromDateName) {
+            def condsByFromDate = [];
+            condsByFromDate.add(EntityCondition.makeCondition(EntityFieldValue.makeFieldValue(fromDateName), EntityOperator.LESS_THAN_EQUAL_TO, filterByDateValue));
+            condsByFromDate.add(EntityCondition.makeCondition(EntityFieldValue.makeFieldValue(fromDateName), EntityOperator.EQUALS, null));
+            condsDateList.add(EntityCondition.makeCondition(condsByFromDate, EntityOperator.OR));
+        }
+
+        mainAndConds.add(EntityCondition.makeCondition(condsDateList, EntityOperator.AND));
+    }
 
     def entityConditionList = EntityCondition.makeCondition(mainAndConds, EntityOperator.AND);