[ofbiz-framework] branch trunk updated: Fixed: Cant search ViewEntity InventoryItemDetailForSum (OFBIZ-12193)

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

[ofbiz-framework] branch trunk updated: Fixed: Cant search ViewEntity InventoryItemDetailForSum (OFBIZ-12193)

jleroux@apache.org
This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 59a6f460 Fixed: Cant search ViewEntity InventoryItemDetailForSum (OFBIZ-12193)
59a6f460 is described below

commit 59a6f460838d4ec3f5fcae3e855196a9c22ded16
Author: Jacques Le Roux <[hidden email]>
AuthorDate: Mon Mar 8 09:38:14 2021 +0100

    Fixed: Cant search ViewEntity InventoryItemDetailForSum (OFBIZ-12193)
   
    Go to Entity Engine - >
    search entity InventoryItemDetailForSum (view entity) ->
    search for entries -> an error message is shown.
   
    A SQL exception occurred running the service executeFind
   
    Thanks: Sebastian Berg
---
 .../groovyScripts/entity/FindGeneric.groovy        | 42 ++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/framework/webtools/groovyScripts/entity/FindGeneric.groovy b/framework/webtools/groovyScripts/entity/FindGeneric.groovy
index edbb4a4..196f1f7 100644
--- a/framework/webtools/groovyScripts/entity/FindGeneric.groovy
+++ b/framework/webtools/groovyScripts/entity/FindGeneric.groovy
@@ -22,6 +22,8 @@ import org.apache.ofbiz.entity.GenericEntityException
 import org.apache.ofbiz.entity.model.ModelEntity
 import org.apache.ofbiz.entity.model.ModelFieldType
 import org.apache.ofbiz.entity.model.ModelReader
+import org.apache.ofbiz.entity.model.ModelViewEntity
+import org.apache.ofbiz.entity.model.ModelViewEntity.ModelAlias
 import org.apache.ofbiz.widget.model.FormFactory
 import org.apache.ofbiz.widget.model.ModelForm
 import org.apache.ofbiz.widget.renderer.FormRenderer
@@ -36,6 +38,8 @@ try {
 }
 
 if (modelEntity) {
+    List<String> fieldsToSelect = getFieldsToSelect(modelEntity)
+
     entityName = modelEntity.entityName
     context.entityName = entityName
     ModelReader entityModelReader = delegator.getModelReader()
@@ -90,7 +94,12 @@ if (modelEntity) {
             <actions>
                 <service service-name="performFind">
                     <field-map field-name="inputFields" from-field="parameters"/>
-                    <field-map field-name="entityName" value="${entityName}"/>
+                    <field-map field-name="entityName" value="${entityName}"/>"""
+    if (fieldsToSelect) {
+    dynamicAutoEntityFieldListForm += """
+                    <field-map field-name="fieldList" value="${fieldsToSelect}"/>"""
+    }
+    dynamicAutoEntityFieldListForm += """
                     <field-map field-name="orderBy" from-field="parameters.sortField"/>
                 </service>
             </actions>
@@ -119,4 +128,33 @@ if (modelEntity) {
     Writer writerList = new StringWriter()
     dynamicAutoEntityListFormRenderer.render(writerList, context)
     context.dynamicAutoEntityListForm = writerList
-}
\ No newline at end of file
+}
+
+def getFieldsToSelect(ModelEntity modelEntity) {
+    groupByFields = []
+    functionFields = []
+
+    if (modelEntity instanceof ModelViewEntity) {
+        aliases = modelEntity.getAliasesCopy()
+        for (ModelAlias alias : aliases) {
+            if (alias.getGroupBy()) {
+                groupByFields.add(alias.getName())
+            } else if (alias.getFunction()) {
+                functionFields.add(alias.getName())
+            }
+        }
+    }
+    List<String> fieldsToSelect = []
+
+    if (groupByFields || functionFields) {
+
+        for (String groupByField : groupByFields) {
+            fieldsToSelect.add(groupByField)
+        }
+
+        for (String functionField : functionFields) {
+            fieldsToSelect.add(functionField)
+        }
+    }
+    return fieldsToSelect
+}