[ofbiz-framework] branch trunk updated (803f7fa -> a6cfaf8)

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

[ofbiz-framework] branch trunk updated (803f7fa -> a6cfaf8)

nmalin
This is an automated email from the ASF dual-hosted git repository.

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


    from 803f7fa  Improved: <script-template> widget tag (OFBIZ-11686)
     new 4ebdcdd  Improved: Convert PriceServices.xml mini lang to groovy
     new b9b8c14  Improved: Convert PriceServices.xml mini lang to groovy
     new a6cfaf8  Improved: getAssociatedPriceRulesConds service return huge result

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../product/price/PriceServices.groovy             | 272 +++++++++++++++++
 .../minilang/product/price/PriceServices.xml       | 327 ---------------------
 applications/product/servicedef/services.xml       |  26 +-
 .../product/servicedef/services_pricepromo.xml     |  12 +-
 4 files changed, 293 insertions(+), 344 deletions(-)
 create mode 100644 applications/product/groovyScripts/product/price/PriceServices.groovy
 delete mode 100644 applications/product/minilang/product/price/PriceServices.xml

Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] 01/03: Improved: Convert PriceServices.xml mini lang to groovy

nmalin
This is an automated email from the ASF dual-hosted git repository.

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

commit 4ebdcdd9d03b6682f9f00397ef5d61d2f0bee08b
Author: Sebastian Berg <[hidden email]>
AuthorDate: Tue Apr 14 13:24:51 2020 +0200

    Improved: Convert PriceServices.xml mini lang to groovy
   
    (OFBIZ-11578)
---
 .../product/price/PriceServices.groovy             | 306 +++++++++++++++++++
 .../minilang/product/price/PriceServices.xml       | 327 ---------------------
 applications/product/servicedef/services.xml       |  22 +-
 .../product/servicedef/services_pricepromo.xml     |  12 +-
 4 files changed, 326 insertions(+), 341 deletions(-)

diff --git a/applications/product/groovyScripts/product/price/PriceServices.groovy b/applications/product/groovyScripts/product/price/PriceServices.groovy
new file mode 100644
index 0000000..a9eb056
--- /dev/null
+++ b/applications/product/groovyScripts/product/price/PriceServices.groovy
@@ -0,0 +1,306 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.math.RoundingMode
+import java.sql.Timestamp
+
+import org.apache.ofbiz.base.util.UtilDateTime
+import org.apache.ofbiz.base.util.UtilProperties
+import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.entity.condition.EntityCondition
+import org.apache.ofbiz.entity.condition.EntityOperator
+import org.apache.ofbiz.product.product.ProductServices
+import org.apache.ofbiz.service.ServiceUtil
+
+
+
+
+/**
+ * Create a Product Price
+ * @return
+ */
+def createProductPrice() {
+    Map result = success()
+    if (!security.hasPermission("CATALOG_PRICE_MAINT", userLogin)) {
+        return error(UtilProperties.getMessage("ProductUiLabels", "ProductPriceMaintPermissionError", locale))
+    }
+    inlineHandlePriceWithTaxIncluded()
+
+    GenericValue newEntity = makeValue("ProductPrice", parameters)
+
+    Timestamp nowTimestamp = UtilDateTime.nowTimestamp()
+    if (!newEntity.fromDate) {
+        newEntity.fromDate = nowTimestamp
+    }
+    result.fromDate = newEntity.fromDate
+    newEntity.lastModifiedDate = nowTimestamp
+    newEntity.createdDate = nowTimestamp
+    newEntity.lastModifiedByUserLogin = userLogin.userLoginId
+    newEntity.createdByUserLogin = userLogin.userLoginId
+    newEntity.create()
+
+    return result
+}
+
+/**
+ * Update an ProductPrice
+ * @return
+ */
+def updateProductPrice() {
+    Map result = success()
+    if (!security.hasPermission("CATALOG_PRICE_MAINT", userLogin)) {
+        return error(UtilProperties.getMessage("ProductUiLabels", "ProductPriceMaintPermissionError", locale))
+    }
+    inlineHandlePriceWithTaxIncluded()
+
+    GenericValue lookedUpValue = from("ProductPrice").where(parameters).queryOne()
+    // grab the old price value before setting nonpk parameter fields
+    result.oldPrice = lookedUpValue.price
+    lookedUpValue.setNonPKFields(parameters)
+    lookedUpValue.lastModifiedDate = UtilDateTime.nowTimestamp()
+    lookedUpValue.lastModifiedByUserLogin = userLogin.userLoginId
+    lookedUpValue.store()
+
+    return result
+}
+
+/**
+ * Delete an ProductPrice
+ * @return
+ */
+def deleteProductPrice() {
+    Map result = success()
+    if (!security.hasPermission("CATALOG_PRICE_MAINT", userLogin)) {
+        return error(UtilProperties.getMessage("ProductUiLabels", "ProductPriceMaintPermissionError", locale))
+    }
+    GenericValue lookedUpValue = from("ProductPrice").where(parameters).queryOne()
+    // grab the old price value before setting nonpk parameter fields
+    result.oldPrice = lookedUpValue.price
+    lookedUpValue.remove()
+    return result
+}
+
+/**
+ * Inline Handle Price with Tax Included
+ * @return
+ */
+def inlineHandlePriceWithTaxIncluded() {
+    // handle price with tax included related fields (priceWithTax, taxAmount, taxPercentage, taxAuthPartyId, taxAuthGeoId)
+    if (parameters.taxAuthPartyId && parameters.taxAuthGeoId) {
+        parameters.priceWithTax = parameters.price
+
+        // if taxPercentage not passed in look it up based on taxAuthGeoId and taxAuthPartyId
+        if (!parameters.taxPercentage) {
+            // we only have basic data to constrain by here, so assume that if it is a VAT tax setup it should be pretty simple
+            EntityCondition condition = EntityCondition.makeCondition([
+                EntityCondition.makeCondition("taxAuthGeoId", parameters.taxAuthGeoId),
+                EntityCondition.makeCondition("taxAuthPartyId", parameters.taxAuthPartyId),
+                EntityCondition.makeCondition([
+                    EntityCondition.makeCondition("taxAuthorityRateTypeId", "SALES_TAX"),
+                    EntityCondition.makeCondition("taxAuthorityRateTypeId", "VAT_TAX")
+                ], EntityOperator.OR)
+            ])
+            GenericValue taxAuthorityRateProduct = from("TaxAuthorityRateProduct").where(condition).filterByDate().queryFirst()
+            parameters.taxPercentage = taxAuthorityRateProduct?.taxPercentage
+        }
+        if (!parameters.taxPercentage) {
+            String errorMessage = UtilProperties.getMessage("ProductUiLabels", "ProductPriceTaxPercentageNotFound", locale)
+            logError(errorMessage)
+            return error(errorMessage)
+        }
+        // in short the formula is: taxAmount = priceWithTax - (priceWithTax/(1+taxPercentage/100))
+        BigDecimal taxAmount = parameters.priceWithTax - (parameters.priceWithTax/(1 + parameters.taxPercentage/100))
+        parameters.taxAmount = taxAmount.setScale(3, RoundingMode.HALF_UP)
+
+        BigDecimal priceWithoutTax = parameters.priceWithTax - parameters.taxAmount
+        parameters.priceWithoutTax = priceWithoutTax.setScale(3, RoundingMode.HALF_UP)
+
+        if (parameters.taxInPrice == "Y") {
+            // the price passed in has tax included, and we want to store it with tax included
+            parameters.price = parameters.priceWithTax
+        } else {
+            // the price passed in has tax included, but we want to store it without tax included
+            parameters.price = parameters.priceWithoutTax
+        }
+
+    }
+    return success()
+}
+
+// TODO NMA convert to entity auto when changed fileds are managed
+
+/**
+ * Save History of ProductPrice Change
+ * @return
+ */
+def saveProductPriceChange() {
+    // Note that this is kept pretty simple: if a price is specific but no oldPrice, then it is generally a create,
+    // if both are specified it is generally an update, if only the oldPrice is specified it is generally a delete
+    GenericValue newEntity = makeValue("ProductPriceChange")
+    newEntity.setNonPKFields(parameters)
+    newEntity.productPriceChangeId = delegator.getNextSeqId("ProductPriceChange")
+    newEntity.changedDate = UtilDateTime.nowTimestamp()
+    newEntity.changedByUserLogin = userLogin.userLoginId
+    newEntity.create()
+    return success()
+}
+
+// ProductPriceCond methods
+
+/**
+ * Create an ProductPriceCond
+ * @return
+ */
+def createProductPriceCond() {
+    Map result = success()
+    if (!security.hasEntityPermission("CATALOG", "_CREATE", userLogin)) {
+        return error(UtilProperties.getMessage("ProductUiLabels", "ProductCatalogCreatePermissionError", locale))
+    }
+    if (!security.hasPermission("CATALOG_PRICE_MAINT", userLogin)) {
+        return error(UtilProperties.getMessage("ProductUiLabels", "ProductPriceMaintPermissionError", locale))
+    }
+    if (parameters.condValueInput) {
+        parameters.condValue = parameters.condValueInput
+    }
+    GenericValue newEntity = makeValue("ProductPriceCond", parameters)
+    delegator.setNextSubSeqId(newEntity, "productPriceCondSeqId", 2, 1)
+    result.productPriceCondSeqId = newEntity.productPriceCondSeqId
+    newEntity.create()
+    return result
+}
+
+/**
+ * Update an ProductPriceCond
+ * @return
+ */
+def updateProductPriceCond() {
+    if (!security.hasEntityPermission("CATALOG", "_UPDATE", userLogin)) {
+        return error(UtilProperties.getMessage("ProductUiLabels", "ProductCatalogUpdatePermissionError", locale))
+    }
+    if (!security.hasPermission("CATALOG_PRICE_MAINT", userLogin)) {
+        return error(UtilProperties.getMessage("ProductUiLabels", "ProductPriceMaintPermissionError", locale))
+    }
+    if (parameters.inputParamEnumId == "PRIP_QUANTITY") {
+        parameters.condValue = parameters.condValueInput
+    }
+    if (parameters.inputParamEnumId == "PRIP_LIST_PRICE") {
+        parameters.condValue = parameters.condValueInput
+    }
+    GenericValue lookedUpValue = from("ProductPriceCond").where(parameters).queryOne()
+    lookedUpValue.setNonPKFields(parameters)
+    lookedUpValue.store()
+    return success()
+}
+
+/**
+ * Set the Value options for selected Price Rule Condition Input
+ * @return
+ */
+def getAssociatedPriceRulesConds() {
+    Map result = success()
+    List productPriceRulesCondValues = []
+    if ((parameters.inputParamEnumId == "PRIP_QUANTITY") || (parameters.inputParamEnumId == "PRIP_LIST_PRICE")) {
+        return success()
+    }
+    if (parameters.inputParamEnumId == "PRIP_PRODUCT_ID") {
+        List condValues = from("Product").queryList()
+        // May prove more useful rather than an entity-and in custom cases
+        for (GenericValue condValue : condValues) {
+            String option = (condValue.internalName ? "${condValue.internalName}: " : ": ") + (condValue.productId ? "${condValue.productId}" : "")
+            productPriceRulesCondValues << option
+        }
+    }
+    if (parameters.inputParamEnumId == "PRIP_PROD_CAT_ID") {
+        List condValues = from("ProductCategory").queryList()
+        // May prove more useful rather than an entity-and in custom cases
+        for (GenericValue condValue : condValues) {
+            String option = (condValue.categoryName ? "${condValue.categoryName} " : " ") + (condValue.description ? "${condValue.description} " : " ") +
+                    (condValue.longDescription ? condValue.longDescription.substring(0,10) : "") + (condValue.productCategoryId ? " [${condValue.productCategoryId}]: " : " []: ") +
+                    (condValue.productCategoryId ? "${condValue.productCategoryId}" : "")
+            productPriceRulesCondValues << option
+        }
+    }
+    if (parameters.inputParamEnumId == "PRIP_PROD_FEAT_ID") {
+        List condValues = from("ProductFeatureType").queryList()
+        // May prove more useful rather than an entity-and in custom cases
+        for (GenericValue condValue : condValues) {
+            String option = (condValue.description ? "${condValue.description} " : " ") + (condValue.productFeatureTypeId ? " ${condValue.productFeatureTypeId}" : "")
+            productPriceRulesCondValues << option
+        }
+    }
+    if ((parameters.inputParamEnumId == "PRIP_PARTY_ID") || (parameters.inputParamEnumId == "PRIP_PARTY_GRP_MEM")) {
+        List condValues = from("PartyNameView").queryList()
+        for (GenericValue condValue : condValues) {
+            String option = (condValue.firstName ? "${condValue.firstName} " : " ") + (condValue.lastName ? "${condValue.lastName}" : "") +
+                    (condValue.groupName ? "${condValue.groupName}: " : ": ") + (condValue.partyId ? "${condValue.partyId}" : "")
+            productPriceRulesCondValues << option
+        }
+    }
+    if (parameters.inputParamEnumId == "PRIP_PARTY_CLASS") {
+        List condValues = from("PartyClassificationGroup").queryList()
+        // May prove more useful rather than an entity-and in custom cases
+        for (GenericValue condValue : condValues) {
+            String option = (condValue.description ? "${condValue.description}: " : ": ") + (condValue.partyClassificationGroupId ? "${condValue.partyClassificationGroupId}" : "")
+            productPriceRulesCondValues << option
+        }
+    }
+    if (parameters.inputParamEnumId == "PRIP_ROLE_TYPE") {
+        List condValues = from("RoleType").queryList()
+        // May prove more useful rather than an entity-and in custom cases
+        for (GenericValue condValue : condValues) {
+            String option = (condValue.description ? "${condValue.description}: " : ": ") + (condValue.roleTypeId ? "${condValue.roleTypeId}" : "")
+            productPriceRulesCondValues << option
+        }
+    }
+    if (parameters.inputParamEnumId == "PRIP_WEBSITE_ID") {
+        List condValues = from("WebSite").queryList()
+        for (GenericValue condValue : condValues) {
+            String option = (condValue.siteName ? "${condValue.siteName}: " : ": ") + (condValue.webSiteId ? "${condValue.webSiteId}" : "")
+            productPriceRulesCondValues << option
+        }
+    }
+    if (parameters.inputParamEnumId == "PRIP_PROD_SGRP_ID") {
+        List condValues = from("ProductStoreGroup").queryList()
+        for (GenericValue condValue : condValues) {
+            String option = (condValue.productStoreGroupName ? "${condValue.productStoreGroupName} " : " ") + (condValue.description ? "(${condValue.description}): " : "(): ") + (condValue.productStoreGroupId ? "${condValue.productStoreGroupId}" : "")
+            productPriceRulesCondValues << option
+        }
+    }
+    if (parameters.inputParamEnumId == "PRIP_PROD_CLG_ID") {
+        List condValues = from("ProdCatalog").queryList()
+        for (GenericValue condValue : condValues) {
+            String option = (condValue.catalogName ? "${condValue.catalogName}: " : ": ") + (condValue.prodCatalogId ? "${condValue.prodCatalogId}" : "")
+            productPriceRulesCondValues << option
+        }
+    }
+    if (parameters.inputParamEnumId == "PRIP_CURRENCY_UOMID") {
+        List condValues = from("Uom").where(uomTypeId: "CURRENCY_MEASURE").queryList()
+        for (GenericValue condValue : condValues) {
+            String option = (condValue.description ? "${condValue.description}: " : ": ") + (condValue.uomId ? "${condValue.uomId}" : "")
+            productPriceRulesCondValues << option
+        }
+    }
+    if (!productPriceRulesCondValues) {
+        String noOptions = UtilProperties.getMessage("CommonUiLabels", "CommonNoOptions", locale)
+        productPriceRulesCondValues << noOptions
+    }
+    result.productPriceRulesCondValues = productPriceRulesCondValues
+    return result
+}
diff --git a/applications/product/minilang/product/price/PriceServices.xml b/applications/product/minilang/product/price/PriceServices.xml
deleted file mode 100644
index cf67c4a..0000000
--- a/applications/product/minilang/product/price/PriceServices.xml
+++ /dev/null
@@ -1,327 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied.  See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-
-<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-        xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd">
-    <!-- ProductPrice methods -->
-    <simple-method method-name="createProductPrice" short-description="Create a Product Price">
-        <check-permission permission="CATALOG_PRICE_MAINT">
-            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
-        </check-permission>
-        <check-errors/>
-
-        <call-simple-method method-name="inlineHandlePriceWithTaxIncluded"/>
-
-        <make-value entity-name="ProductPrice" value-field="newEntity"/>
-        <set-nonpk-fields map="parameters" value-field="newEntity"/>
-        <set-pk-fields map="parameters" value-field="newEntity"/>
-
-        <now-timestamp field="nowTimestamp"/>
-
-        <if-empty field="newEntity.fromDate">
-            <set field="newEntity.fromDate" from-field="nowTimestamp"/>
-        </if-empty>
-        <field-to-result field="newEntity.fromDate" result-name="fromDate"/>
-
-        <set field="newEntity.lastModifiedDate" from-field="nowTimestamp"/>
-        <set field="newEntity.createdDate" from-field="nowTimestamp"/>
-        <set field="newEntity.lastModifiedByUserLogin" from-field="userLogin.userLoginId"/>
-        <set field="newEntity.createdByUserLogin" from-field="userLogin.userLoginId"/>
-
-        <create-value value-field="newEntity"/>
-    </simple-method>
-    <simple-method method-name="updateProductPrice" short-description="Update an ProductPrice">
-        <check-permission permission="CATALOG_PRICE_MAINT">
-            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
-        </check-permission>
-        <check-errors/>
-
-        <call-simple-method method-name="inlineHandlePriceWithTaxIncluded"/>
-
-        <entity-one entity-name="ProductPrice" value-field="lookedUpValue"/>
-
-        <!-- grab the old price value before setting nonpk parameter fields -->
-        <field-to-result field="lookedUpValue.price" result-name="oldPrice"/>
-
-        <set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
-
-        <now-timestamp field="nowTimestamp"/>
-        <set field="lookedUpValue.lastModifiedDate" from-field="nowTimestamp"/>
-        <set field="lookedUpValue.lastModifiedByUserLogin" from-field="userLogin.userLoginId"/>
-
-        <store-value value-field="lookedUpValue"/>
-    </simple-method>
-    <simple-method method-name="deleteProductPrice" short-description="Delete an ProductPrice">
-        <check-permission permission="CATALOG_PRICE_MAINT">
-            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
-        </check-permission>
-        <check-errors/>
-
-        <make-value entity-name="ProductPrice" value-field="lookupPKMap"/>
-        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
-        <find-by-primary-key entity-name="ProductPrice" map="lookupPKMap" value-field="lookedUpValue"/>
-
-        <!-- grab the old price value before setting nonpk parameter fields -->
-        <field-to-result field="lookedUpValue.price" result-name="oldPrice"/>
-
-        <remove-value value-field="lookedUpValue"/>
-    </simple-method>
-    <simple-method method-name="inlineHandlePriceWithTaxIncluded" short-description="Inline Handle Price with Tax Included">
-        <!-- handle price with tax included related fields (priceWithTax, taxAmount, taxPercentage, taxAuthPartyId, taxAuthGeoId) -->
-        <if>
-            <condition>
-                <and>
-                    <not><if-empty field="parameters.taxAuthPartyId"></if-empty></not>
-                    <not><if-empty field="parameters.taxAuthGeoId"></if-empty></not>
-                </and>
-            </condition>
-            <then>
-                <set field="parameters.priceWithTax" from-field="parameters.price"/>
-
-                <!-- if taxPercentage not passed in look it up based on taxAuthGeoId and taxAuthPartyId -->
-                <if-empty field="parameters.taxPercentage">
-                    <!-- we only have basic data to constrain by here, so assume that if it is a VAT tax setup it should be pretty simple -->
-                    <entity-condition entity-name="TaxAuthorityRateProduct" list="taxAuthorityRateProductList" filter-by-date="true">
-                        <condition-list combine="and">
-                            <condition-expr field-name="taxAuthGeoId" from-field="parameters.taxAuthGeoId"/>
-                            <condition-expr field-name="taxAuthPartyId" from-field="parameters.taxAuthPartyId"/>
-                            <condition-list combine="or">
-                                <condition-expr field-name="taxAuthorityRateTypeId" value="SALES_TAX"/>
-                                <condition-expr field-name="taxAuthorityRateTypeId" value="VAT_TAX"/>
-                            </condition-list>
-                        </condition-list>
-                    </entity-condition>
-                    <set field="parameters.taxPercentage" from-field="taxAuthorityRateProductList[0].taxPercentage" type="BigDecimal"/>
-                </if-empty>
-
-                <if-empty field="parameters.taxPercentage">
-                    <add-error>
-                        <fail-property resource="ProductUiLabels" property="ProductPriceTaxPercentageNotFound"/>
-                    </add-error>
-                    <check-errors/>
-                </if-empty>
-
-                <!-- in short the formula is: taxAmount = priceWithTax - (priceWithTax/(1+taxPercentage/100)) -->
-                <calculate field="parameters.taxAmount" type="BigDecimal" decimal-scale="3" rounding-mode="HalfUp">
-                    <calcop operator="subtract">
-                        <calcop operator="get" field="parameters.priceWithTax"/>
-                        <calcop operator="divide">
-                            <calcop operator="get" field="parameters.priceWithTax"/>
-                            <calcop operator="add">
-                                <number value="1"/>
-                                <calcop operator="divide">
-                                    <calcop operator="get" field="parameters.taxPercentage"/>
-                                    <number value="100"/>
-                                </calcop>
-                            </calcop>
-                        </calcop>
-                    </calcop>
-                </calculate>
-
-                <calculate field="parameters.priceWithoutTax" type="BigDecimal" decimal-scale="3" rounding-mode="HalfUp">
-                    <calcop operator="subtract">
-                        <calcop operator="get" field="parameters.priceWithTax"/>
-                        <calcop operator="get" field="parameters.taxAmount"></calcop>
-                    </calcop>
-                </calculate>
-
-                <if-compare field="parameters.taxInPrice" operator="equals" value="Y">
-                    <!-- the price passed in has tax included, and we want to store it with tax included -->
-                    <set field="parameters.price" from-field="parameters.priceWithTax"/>
-
-                    <else>
-                        <!-- the price passed in has tax included, but we want to store it without tax included -->
-                        <set field="parameters.price" from-field="parameters.priceWithoutTax"/>
-                    </else>
-                </if-compare>
-            </then>
-        </if>
-    </simple-method>
-
-    <!-- TODO NMA convert to entity auto when changed fileds are managed -->
-    <simple-method method-name="saveProductPriceChange" short-description="Save History of ProductPrice Change">
-        <!-- Note that this is kept pretty simple: if a price is specific but no oldPrice, then it is generally a create, if both are specified it is generally an update, if only the oldPrice is specified it is generally a delete -->
-        <make-value entity-name="ProductPriceChange" value-field="newEntity"/>
-        <set-nonpk-fields map="parameters" value-field="newEntity"/>
-
-        <sequenced-id sequence-name="ProductPriceChange" field="productPriceChangeId"/>
-        <set field="newEntity.productPriceChangeId" from-field="productPriceChangeId"/>
-        <now-timestamp field="nowTimestamp"/>
-        <set field="newEntity.changedDate" from-field="nowTimestamp"/>
-        <set field="newEntity.changedByUserLogin" from-field="userLogin.userLoginId"/>
-
-        <create-value value-field="newEntity"/>
-    </simple-method>
-
-    <!-- ProductPriceCond methods -->
-    <simple-method method-name="createProductPriceCond" short-description="Create an ProductPriceCond">
-        <check-permission permission="CATALOG" action="_CREATE">
-            <fail-property resource="ProductUiLabels" property="ProductCatalogCreatePermissionError"/>
-        </check-permission>
-        <check-permission permission="CATALOG_PRICE_MAINT">
-            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
-        </check-permission>
-        <check-errors/>
-
-        <if-not-empty field="parameters.condValueInput">
-            <set field="parameters.condValue" from-field="parameters.condValueInput"/>
-        </if-not-empty>
-        <make-value entity-name="ProductPriceCond" value-field="newEntity"/>
-        <set-nonpk-fields map="parameters" value-field="newEntity"/>
-        <set-pk-fields map="parameters" value-field="newEntity"/>
-        <make-next-seq-id value-field="newEntity" seq-field-name="productPriceCondSeqId" numeric-padding="2"/>
-        <field-to-result field="newEntity.productPriceCondSeqId" result-name="productPriceCondSeqId"/>
-
-        <create-value value-field="newEntity"/>
-    </simple-method>
-    <simple-method method-name="updateProductPriceCond" short-description="Update an ProductPriceCond">
-        <check-permission permission="CATALOG" action="_UPDATE">
-            <fail-property resource="ProductUiLabels" property="ProductCatalogUpdatePermissionError"/>
-        </check-permission>
-        <check-permission permission="CATALOG_PRICE_MAINT">
-            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
-        </check-permission>
-        <check-errors/>
-
-        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_QUANTITY">
-            <set field="parameters.condValue" from-field="parameters.condValueInput"/>
-        </if-compare>
-        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_LIST_PRICE">
-            <set field="parameters.condValue" from-field="parameters.condValueInput"/>
-        </if-compare>
-        <make-value entity-name="ProductPriceCond" value-field="lookupPKMap"/>
-        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
-        <find-by-primary-key entity-name="ProductPriceCond" map="lookupPKMap" value-field="lookedUpValue"/>
-        <set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
-        <store-value value-field="lookedUpValue"/>
-    </simple-method>
-
-    <simple-method method-name="getAssociatedPriceRulesConds" short-description="Set the Value options for selected Price Rule Condition Input" login-required="false">
-        <if>
-            <condition>
-                <or>
-                    <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_QUANTITY"/>
-                    <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_LIST_PRICE"/>
-                </or>
-            </condition>
-            <then>
-                <return/>
-            </then>
-        </if>
-
-        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PRODUCT_ID">
-            <entity-condition entity-name="Product" list="condValues">
-                <!-- May prove more useful rather than an entity-and in custom cases-->
-            </entity-condition>
-            <iterate list="condValues" entry="condValue">
-                <set field="option" value="${condValue.internalName}: ${condValue.productId}"/>
-                <field-to-list list="productPriceRulesCondValues" field="option"/>
-            </iterate>
-        </if-compare>
-        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PROD_CAT_ID">
-            <entity-condition entity-name="ProductCategory" list="condValues">
-                <!-- May prove more useful rather than an entity-and in custom cases-->
-            </entity-condition>
-            <iterate list="condValues" entry="condValue">
-                <set field="option" value="${condValue.categoryName} ${condValue.description} ${groovy: condValue?.longDescription?.substring(0,10)} [${condValue.productCategoryId}]: ${condValue.productCategoryId}"/>
-                <field-to-list list="productPriceRulesCondValues" field="option"/>
-            </iterate>
-        </if-compare>
-        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PROD_FEAT_ID">
-            <entity-condition entity-name="ProductFeatureType" list="condValues">
-                <!-- May prove more useful rather than an entity-and in custom cases-->
-            </entity-condition>
-            <iterate list="condValues" entry="condValue">
-                <set field="option" value="${condValue.description}: ${condValue.productFeatureTypeId}"/>
-                <field-to-list list="productPriceRulesCondValues" field="option"/>
-            </iterate>
-        </if-compare>
-        <if>
-            <condition>
-                <or>
-                    <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PARTY_ID"/>
-                    <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PARTY_GRP_MEM"/>
-                </or>
-            </condition>
-            <then>
-                <entity-condition entity-name="PartyNameView" list="condValues"/>
-                <iterate list="condValues" entry="condValue">
-                    <set field="option" value="${condValue.firstName} ${condValue.lastName}${condValue.groupName}: ${condValue.partyId}"/>
-                    <field-to-list list="productPriceRulesCondValues" field="option"/>
-                </iterate>
-            </then>
-        </if>
-        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PARTY_CLASS">
-            <entity-condition entity-name="PartyClassificationGroup" list="condValues">
-                <!-- May prove more useful rather than an entity-and in custom cases-->
-            </entity-condition>
-            <iterate list="condValues" entry="condValue">
-                <set field="option" value="${condValue.description}: ${condValue.partyClassificationGroupId}"/>
-                <field-to-list list="productPriceRulesCondValues" field="option"/>
-            </iterate>
-        </if-compare>
-        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_ROLE_TYPE">
-            <entity-condition entity-name="RoleType" list="condValues">
-                <!-- May prove more useful rather than an entity-and in custom cases-->
-            </entity-condition>
-            <iterate list="condValues" entry="condValue">
-                <set field="option" value="${condValue.description}: ${condValue.roleTypeId}"/>
-                <field-to-list list="productPriceRulesCondValues" field="option"/>
-            </iterate>
-        </if-compare>
-        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_WEBSITE_ID">
-            <entity-condition entity-name="WebSite" list="condValues"/>
-            <iterate list="condValues" entry="condValue">
-                <set field="option" value="${condValue.siteName}: ${condValue.webSiteId}"/>
-                <field-to-list list="productPriceRulesCondValues" field="option"/>
-            </iterate>
-        </if-compare>
-        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PROD_SGRP_ID">
-            <entity-condition entity-name="ProductStoreGroup" list="condValues"/>
-            <iterate list="condValues" entry="condValue">
-                <set field="option" value="${condValue.productStoreGroupName} (${condValue.description}): ${condValue.productStoreGroupId}"/>
-                <field-to-list list="productPriceRulesCondValues" field="option"/>
-            </iterate>
-        </if-compare>
-        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PROD_CLG_ID">
-            <entity-condition entity-name="ProdCatalog" list="condValues"/>
-            <iterate list="condValues" entry="condValue">
-                <set field="option" value="${condValue.catalogName}: ${condValue.prodCatalogId}"/>
-                <field-to-list list="productPriceRulesCondValues" field="option"/>
-            </iterate>
-        </if-compare>
-        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_CURRENCY_UOMID">
-            <entity-condition entity-name="Uom" list="condValues">
-                <condition-expr field-name="uomTypeId" value="CURRENCY_MEASURE"/>
-            </entity-condition>
-            <iterate list="condValues" entry="condValue">
-                <set field="option" value="${condValue.description}: ${condValue.uomId}"/>
-                <field-to-list list="productPriceRulesCondValues" field="option"/>
-            </iterate>
-        </if-compare>
-
-        <if-empty field="productPriceRulesCondValues">
-            <property-to-field resource="CommonUiLabels" property="CommonNoOptions" field="noOptions"/>
-            <field-to-list list="productPriceRulesCondValues" field="noOptions"/>
-        </if-empty>
-        <field-to-result field="productPriceRulesCondValues"/>
-    </simple-method>
-
-</simple-methods>
diff --git a/applications/product/servicedef/services.xml b/applications/product/servicedef/services.xml
index 46a8f7c..b30195c 100644
--- a/applications/product/servicedef/services.xml
+++ b/applications/product/servicedef/services.xml
@@ -242,8 +242,8 @@ under the License.
     </service>
 
     <!-- Product Price Services -->
-    <service name="createProductPrice" default-entity-name="ProductPrice" engine="simple"
-                location="component://product/minilang/product/price/PriceServices.xml" invoke="createProductPrice" auth="true">
+    <service name="createProductPrice" default-entity-name="ProductPrice" engine="groovy"
+                location="component://product/groovyScripts/product/price/PriceServices.groovy" invoke="createProductPrice" auth="true">
         <description>
             Create a Product Price.
 
@@ -269,8 +269,8 @@ under the License.
         <override name="fromDate" mode="INOUT" optional="true"/>
         <override name="price" optional="false"/>
     </service>
-    <service name="updateProductPrice" default-entity-name="ProductPrice" engine="simple"
-                location="component://product/minilang/product/price/PriceServices.xml" invoke="updateProductPrice" auth="true">
+    <service name="updateProductPrice" default-entity-name="ProductPrice" engine="groovy"
+                location="component://product/groovyScripts/product/price/PriceServices.groovy" invoke="updateProductPrice" auth="true">
         <description>Update an ProductPrice</description>
         <permission-service service-name="checkProductRelatedPermission" main-action="UPDATE"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>
@@ -286,8 +286,8 @@ under the License.
         <attribute name="oldPrice" type="BigDecimal" mode="OUT" optional="false"/>
         <override name="price" optional="false"/>
     </service>
-    <service name="deleteProductPrice" default-entity-name="ProductPrice" engine="simple"
-                location="component://product/minilang/product/price/PriceServices.xml" invoke="deleteProductPrice" auth="true">
+    <service name="deleteProductPrice" default-entity-name="ProductPrice" engine="groovy"
+                location="component://product/groovyScripts/product/price/PriceServices.groovy" invoke="deleteProductPrice" auth="true">
         <description>Delete an ProductPrice</description>
         <permission-service service-name="checkProductRelatedPermission" main-action="DELETE"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>
@@ -295,8 +295,8 @@ under the License.
     </service>
 
     <!-- called by ECAs on ProductPrice service call events -->
-    <service name="saveProductPriceChange" default-entity-name="ProductPrice" engine="simple"
-            location="component://product/minilang/product/price/PriceServices.xml" invoke="saveProductPriceChange" auth="true">
+    <service name="saveProductPriceChange" default-entity-name="ProductPrice" engine="groovy"
+            location="component://product/groovyScripts/product/price/PriceServices.groovy" invoke="saveProductPriceChange" auth="true">
         <description>Save History of a ProductPrice Change</description>
         <permission-service service-name="productPriceGenericPermission" main-action="CREATE"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>
@@ -1246,6 +1246,12 @@ under the License.
         <implements service="permissionInterface"/>
         <attribute type="String" mode="IN" name="productCategoryId" optional="true"/>
     </service>
+    <service name="checkProductRelatedPermission" engine="groovy"
+        location="component://product/groovyScripts/product/product/ProductServices.groovy" invoke="checkProductRelatedPermissionCall">
+        <attribute name="callingMethodName" mode="IN" type="String"/>
+        <attribute name="checkAction" mode="IN" type="String"/>
+        <attribute name="productId" mode="IN" type="String"/>
+    </service>
     <!-- Product Attribute Services -->
     <service name="createProductAttribute" default-entity-name="ProductAttribute" engine="entity-auto" invoke="create" auth="true">
         <description>Create a ProductAttribute</description>
diff --git a/applications/product/servicedef/services_pricepromo.xml b/applications/product/servicedef/services_pricepromo.xml
index df0ee3d..3233f3f 100644
--- a/applications/product/servicedef/services_pricepromo.xml
+++ b/applications/product/servicedef/services_pricepromo.xml
@@ -86,8 +86,8 @@ under the License.
         <auto-attributes include="pk" mode="IN" optional="false"/>
     </service>
 
-    <service name="createProductPriceCond" default-entity-name="ProductPriceCond" engine="simple"
-                location="component://product/minilang/product/price/PriceServices.xml" invoke="createProductPriceCond" auth="true">
+    <service name="createProductPriceCond" default-entity-name="ProductPriceCond" engine="groovy"
+                location="component://product/groovyScripts/product/price/PriceServices.groovy" invoke="createProductPriceCond" auth="true">
         <description>Create a ProductPriceCond</description>
         <permission-service service-name="productPriceGenericPermission" main-action="CREATE"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>
@@ -95,8 +95,8 @@ under the License.
         <attribute name="condValueInput" type="String" mode="IN" optional="true"></attribute>
         <override name="productPriceCondSeqId" mode="OUT"/>
     </service>
-    <service name="updateProductPriceCond" default-entity-name="ProductPriceCond" engine="simple"
-                location="component://product/minilang/product/price/PriceServices.xml" invoke="updateProductPriceCond" auth="true">
+    <service name="updateProductPriceCond" default-entity-name="ProductPriceCond" engine="groovy"
+                location="component://product/groovyScripts/product/price/PriceServices.groovy" invoke="updateProductPriceCond" auth="true">
         <description>Update a ProductPriceCond</description>
         <permission-service service-name="productPriceGenericPermission" main-action="UPDATE"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>
@@ -330,8 +330,8 @@ under the License.
         <attribute name="orderItemPriceInfos" type="java.util.List" mode="OUT" optional="false"/>
     </service>
 
-    <service name="getAssociatedPriceRulesConds" engine="simple" auth="false"
-        location="component://product/minilang/product/price/PriceServices.xml" invoke="getAssociatedPriceRulesConds">
+    <service name="getAssociatedPriceRulesConds" engine="groovy" auth="false"
+        location="component://product/groovyScripts/product/price/PriceServices.groovy" invoke="getAssociatedPriceRulesConds">
         <description>Set the Value options for selected Price Rule Condition Input</description>
         <attribute name="inputParamEnumId" mode="IN" type="String"/>
         <attribute name="productPriceRulesCondValues" mode="OUT" type="java.util.List" optional="true"/><!-- optional="true" because of quantity or other kind of fiels needing an input -->

Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] 02/03: Improved: Convert PriceServices.xml mini lang to groovy

nmalin
In reply to this post by nmalin
This is an automated email from the ASF dual-hosted git repository.

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

commit b9b8c1405b847a262ea866f0844ed05da33744c8
Author: Nicolas Malin <[hidden email]>
AuthorDate: Wed May 13 15:48:00 2020 +0200

    Improved: Convert PriceServices.xml mini lang to groovy
   
    (OFBIZ-11578)
   
    Second pass:
     * slimdown code
     * move saveProductPriceChange to entity-auto
---
 .../product/price/PriceServices.groovy             | 46 ++++------------------
 applications/product/servicedef/services.xml       |  8 ++--
 2 files changed, 10 insertions(+), 44 deletions(-)

diff --git a/applications/product/groovyScripts/product/price/PriceServices.groovy b/applications/product/groovyScripts/product/price/PriceServices.groovy
index a9eb056..e5cef7d 100644
--- a/applications/product/groovyScripts/product/price/PriceServices.groovy
+++ b/applications/product/groovyScripts/product/price/PriceServices.groovy
@@ -17,7 +17,6 @@
  * under the License.
  */
 
-
 import java.math.RoundingMode
 import java.sql.Timestamp
 
@@ -112,56 +111,28 @@ def inlineHandlePriceWithTaxIncluded() {
             EntityCondition condition = EntityCondition.makeCondition([
                 EntityCondition.makeCondition("taxAuthGeoId", parameters.taxAuthGeoId),
                 EntityCondition.makeCondition("taxAuthPartyId", parameters.taxAuthPartyId),
-                EntityCondition.makeCondition([
-                    EntityCondition.makeCondition("taxAuthorityRateTypeId", "SALES_TAX"),
-                    EntityCondition.makeCondition("taxAuthorityRateTypeId", "VAT_TAX")
-                ], EntityOperator.OR)
+                EntityCondition.makeCondition("taxAuthorityRateTypeId", EntityOperator.IN, ["SALES_TAX", "VAT_TAX"])
             ])
             GenericValue taxAuthorityRateProduct = from("TaxAuthorityRateProduct").where(condition).filterByDate().queryFirst()
             parameters.taxPercentage = taxAuthorityRateProduct?.taxPercentage
         }
         if (!parameters.taxPercentage) {
-            String errorMessage = UtilProperties.getMessage("ProductUiLabels", "ProductPriceTaxPercentageNotFound", locale)
-            logError(errorMessage)
-            return error(errorMessage)
+            return error(UtilProperties.getMessage("ProductUiLabels", "ProductPriceTaxPercentageNotFound", locale))
         }
         // in short the formula is: taxAmount = priceWithTax - (priceWithTax/(1+taxPercentage/100))
-        BigDecimal taxAmount = parameters.priceWithTax - (parameters.priceWithTax/(1 + parameters.taxPercentage/100))
+        BigDecimal taxAmount = parameters.priceWithTax - (parameters.priceWithTax / (1 + parameters.taxPercentage/100))
         parameters.taxAmount = taxAmount.setScale(3, RoundingMode.HALF_UP)
 
         BigDecimal priceWithoutTax = parameters.priceWithTax - parameters.taxAmount
         parameters.priceWithoutTax = priceWithoutTax.setScale(3, RoundingMode.HALF_UP)
 
-        if (parameters.taxInPrice == "Y") {
-            // the price passed in has tax included, and we want to store it with tax included
-            parameters.price = parameters.priceWithTax
-        } else {
-            // the price passed in has tax included, but we want to store it without tax included
-            parameters.price = parameters.priceWithoutTax
-        }
-
+        parameters.price = parameters.taxInPrice == "Y" ?
+                parameters.priceWithTax: // the price passed in has tax included, and we want to store it with tax included
+                parameters.priceWithoutTax // the price passed in has tax included, but we want to store it without tax included
     }
     return success()
 }
 
-// TODO NMA convert to entity auto when changed fileds are managed
-
-/**
- * Save History of ProductPrice Change
- * @return
- */
-def saveProductPriceChange() {
-    // Note that this is kept pretty simple: if a price is specific but no oldPrice, then it is generally a create,
-    // if both are specified it is generally an update, if only the oldPrice is specified it is generally a delete
-    GenericValue newEntity = makeValue("ProductPriceChange")
-    newEntity.setNonPKFields(parameters)
-    newEntity.productPriceChangeId = delegator.getNextSeqId("ProductPriceChange")
-    newEntity.changedDate = UtilDateTime.nowTimestamp()
-    newEntity.changedByUserLogin = userLogin.userLoginId
-    newEntity.create()
-    return success()
-}
-
 // ProductPriceCond methods
 
 /**
@@ -197,10 +168,7 @@ def updateProductPriceCond() {
     if (!security.hasPermission("CATALOG_PRICE_MAINT", userLogin)) {
         return error(UtilProperties.getMessage("ProductUiLabels", "ProductPriceMaintPermissionError", locale))
     }
-    if (parameters.inputParamEnumId == "PRIP_QUANTITY") {
-        parameters.condValue = parameters.condValueInput
-    }
-    if (parameters.inputParamEnumId == "PRIP_LIST_PRICE") {
+    if (["PRIP_QUANTITY", "PRIP_LIST_PRICE"].contains(parameters.inputParamEnumId)) {
         parameters.condValue = parameters.condValueInput
     }
     GenericValue lookedUpValue = from("ProductPriceCond").where(parameters).queryOne()
diff --git a/applications/product/servicedef/services.xml b/applications/product/servicedef/services.xml
index b30195c..203a971 100644
--- a/applications/product/servicedef/services.xml
+++ b/applications/product/servicedef/services.xml
@@ -295,14 +295,12 @@ under the License.
     </service>
 
     <!-- called by ECAs on ProductPrice service call events -->
-    <service name="saveProductPriceChange" default-entity-name="ProductPrice" engine="groovy"
-            location="component://product/groovyScripts/product/price/PriceServices.groovy" invoke="saveProductPriceChange" auth="true">
+    <service name="saveProductPriceChange" default-entity-name="ProductPriceChange" engine="entity-auto" invoke="create" auth="true">
         <description>Save History of a ProductPrice Change</description>
         <permission-service service-name="productPriceGenericPermission" main-action="CREATE"/>
-        <auto-attributes include="pk" mode="IN" optional="false"/>
+        <auto-attributes include="pk" mode="IN" optional="false" entity-name="ProductPrice"/>
         <auto-attributes include="nonpk" mode="IN" optional="true"/>
-        <attribute name="oldPrice" type="BigDecimal" mode="IN" optional="true"/>
-        <attribute name="productPriceChangeId" type="String" mode="OUT" optional="true"/>
+        <attribute name="productPriceChangeId" type="String" mode="OUT"/>
     </service>
 
     <!-- Product PaymentMethodType Services -->

Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] 03/03: Improved: getAssociatedPriceRulesConds service return huge result

nmalin
In reply to this post by nmalin
This is an automated email from the ASF dual-hosted git repository.

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

commit a6cfaf87320dab2492502bc27d2c4007aab62b94
Author: Nicolas Malin <[hidden email]>
AuthorDate: Wed May 13 16:06:56 2020 +0200

    Improved: getAssociatedPriceRulesConds service return huge result
   
    (OFBIZ-11701)
   
    The service getAssociatedPriceRulesConds return some element to help the selection on product prise rule condition screen.
    The problem: all query to resolve element are realized without filter :
         from("Product").queryList()
   
    On big database, a call on this service generate a server saturation (load 1 Million product to a dropdown, isn't logical)
    To keep the benefit of this service as example to implement a custom service with filter, I introduce a limit range to 200. For much more it's better to improve the screen with a lookup.
   
    I also simplify the list generation to homogenize and help the reader.
---
 .../product/price/PriceServices.groovy             | 174 ++++++++++-----------
 1 file changed, 86 insertions(+), 88 deletions(-)

diff --git a/applications/product/groovyScripts/product/price/PriceServices.groovy b/applications/product/groovyScripts/product/price/PriceServices.groovy
index e5cef7d..54cc432 100644
--- a/applications/product/groovyScripts/product/price/PriceServices.groovy
+++ b/applications/product/groovyScripts/product/price/PriceServices.groovy
@@ -25,11 +25,7 @@ import org.apache.ofbiz.base.util.UtilProperties
 import org.apache.ofbiz.entity.GenericValue
 import org.apache.ofbiz.entity.condition.EntityCondition
 import org.apache.ofbiz.entity.condition.EntityOperator
-import org.apache.ofbiz.product.product.ProductServices
-import org.apache.ofbiz.service.ServiceUtil
-
-
-
+import org.apache.ofbiz.party.party.PartyHelper
 
 /**
  * Create a Product Price
@@ -184,91 +180,93 @@ def updateProductPriceCond() {
 def getAssociatedPriceRulesConds() {
     Map result = success()
     List productPriceRulesCondValues = []
-    if ((parameters.inputParamEnumId == "PRIP_QUANTITY") || (parameters.inputParamEnumId == "PRIP_LIST_PRICE")) {
-        return success()
-    }
-    if (parameters.inputParamEnumId == "PRIP_PRODUCT_ID") {
-        List condValues = from("Product").queryList()
-        // May prove more useful rather than an entity-and in custom cases
-        for (GenericValue condValue : condValues) {
-            String option = (condValue.internalName ? "${condValue.internalName}: " : ": ") + (condValue.productId ? "${condValue.productId}" : "")
-            productPriceRulesCondValues << option
-        }
-    }
-    if (parameters.inputParamEnumId == "PRIP_PROD_CAT_ID") {
-        List condValues = from("ProductCategory").queryList()
-        // May prove more useful rather than an entity-and in custom cases
-        for (GenericValue condValue : condValues) {
-            String option = (condValue.categoryName ? "${condValue.categoryName} " : " ") + (condValue.description ? "${condValue.description} " : " ") +
-                    (condValue.longDescription ? condValue.longDescription.substring(0,10) : "") + (condValue.productCategoryId ? " [${condValue.productCategoryId}]: " : " []: ") +
-                    (condValue.productCategoryId ? "${condValue.productCategoryId}" : "")
-            productPriceRulesCondValues << option
-        }
-    }
-    if (parameters.inputParamEnumId == "PRIP_PROD_FEAT_ID") {
-        List condValues = from("ProductFeatureType").queryList()
-        // May prove more useful rather than an entity-and in custom cases
-        for (GenericValue condValue : condValues) {
-            String option = (condValue.description ? "${condValue.description} " : " ") + (condValue.productFeatureTypeId ? " ${condValue.productFeatureTypeId}" : "")
-            productPriceRulesCondValues << option
-        }
-    }
-    if ((parameters.inputParamEnumId == "PRIP_PARTY_ID") || (parameters.inputParamEnumId == "PRIP_PARTY_GRP_MEM")) {
-        List condValues = from("PartyNameView").queryList()
-        for (GenericValue condValue : condValues) {
-            String option = (condValue.firstName ? "${condValue.firstName} " : " ") + (condValue.lastName ? "${condValue.lastName}" : "") +
-                    (condValue.groupName ? "${condValue.groupName}: " : ": ") + (condValue.partyId ? "${condValue.partyId}" : "")
-            productPriceRulesCondValues << option
-        }
-    }
-    if (parameters.inputParamEnumId == "PRIP_PARTY_CLASS") {
-        List condValues = from("PartyClassificationGroup").queryList()
-        // May prove more useful rather than an entity-and in custom cases
-        for (GenericValue condValue : condValues) {
-            String option = (condValue.description ? "${condValue.description}: " : ": ") + (condValue.partyClassificationGroupId ? "${condValue.partyClassificationGroupId}" : "")
-            productPriceRulesCondValues << option
-        }
-    }
-    if (parameters.inputParamEnumId == "PRIP_ROLE_TYPE") {
-        List condValues = from("RoleType").queryList()
-        // May prove more useful rather than an entity-and in custom cases
-        for (GenericValue condValue : condValues) {
-            String option = (condValue.description ? "${condValue.description}: " : ": ") + (condValue.roleTypeId ? "${condValue.roleTypeId}" : "")
-            productPriceRulesCondValues << option
-        }
-    }
-    if (parameters.inputParamEnumId == "PRIP_WEBSITE_ID") {
-        List condValues = from("WebSite").queryList()
-        for (GenericValue condValue : condValues) {
-            String option = (condValue.siteName ? "${condValue.siteName}: " : ": ") + (condValue.webSiteId ? "${condValue.webSiteId}" : "")
-            productPriceRulesCondValues << option
-        }
-    }
-    if (parameters.inputParamEnumId == "PRIP_PROD_SGRP_ID") {
-        List condValues = from("ProductStoreGroup").queryList()
-        for (GenericValue condValue : condValues) {
-            String option = (condValue.productStoreGroupName ? "${condValue.productStoreGroupName} " : " ") + (condValue.description ? "(${condValue.description}): " : "(): ") + (condValue.productStoreGroupId ? "${condValue.productStoreGroupId}" : "")
-            productPriceRulesCondValues << option
-        }
-    }
-    if (parameters.inputParamEnumId == "PRIP_PROD_CLG_ID") {
-        List condValues = from("ProdCatalog").queryList()
-        for (GenericValue condValue : condValues) {
-            String option = (condValue.catalogName ? "${condValue.catalogName}: " : ": ") + (condValue.prodCatalogId ? "${condValue.prodCatalogId}" : "")
-            productPriceRulesCondValues << option
-        }
-    }
-    if (parameters.inputParamEnumId == "PRIP_CURRENCY_UOMID") {
-        List condValues = from("Uom").where(uomTypeId: "CURRENCY_MEASURE").queryList()
-        for (GenericValue condValue : condValues) {
-            String option = (condValue.description ? "${condValue.description}: " : ": ") + (condValue.uomId ? "${condValue.uomId}" : "")
-            productPriceRulesCondValues << option
-        }
+
+    // May prove more useful rather than an entity-and in custom cases, set limit to not return too huge element
+    int sizeLimit = 200
+    switch (parameters.inputParamEnumId) {
+        case "PRIP_PRODUCT_ID":
+            from("Product").limit(sizeLimit).queryList()?.each {
+                productPriceRulesCondValues << [key: it.productId,
+                                                description: it.internalName ?: '[' + it.productId + ']']
+            }
+            break
+
+        case "PRIP_PROD_CAT_ID":
+            from("ProductCategory").limit(sizeLimit).queryList()?.each {
+                productPriceRulesCondValues << [key: it.productCategoryId,
+                                                description: it.categoryName ?: '[' + it.productCategoryId + ']']
+            }
+            break
+
+        case "PRIP_PROD_FEAT_ID":
+            from("ProductFeatureType").limit(sizeLimit).queryList()?.each {
+                productPriceRulesCondValues << [key: it.productFeatureTypeId,
+                                                description: it.description ?: '[' + it.productFeatureTypeId + ']']
+            }
+            break
+
+        case "PRIP_PARTY_ID":
+        case "PRIP_PARTY_GRP_MEM":
+            from("PartyNameView").limit(sizeLimit).queryList()?.each {
+                productPriceRulesCondValues << [key: it.partyId,
+                                                description: PartyHelper.getPartyName(it)]
+            }
+            break
+
+        case "PRIP_PARTY_CLASS":
+            from("PartyClassificationGroup").limit(sizeLimit).queryList()?.each {
+                productPriceRulesCondValues << [key: it.partyClassificationGroupId,
+                                                description: it.description ?: '[' + it.partyClassificationGroupId + ']']
+            }
+            break
+
+        case "PRIP_ROLE_TYPE":
+            from("RoleType").limit(sizeLimit).queryList()?.each {
+                productPriceRulesCondValues << [key: it.roleTypeId,
+                                                description: it.description ?: '[' + it.roleTypeId + ']']
+            }
+            break
+
+        case "PRIP_WEBSITE_ID":
+            from("WebSite").limit(sizeLimit).queryList()?.each {
+                productPriceRulesCondValues << [key: it.webSiteId,
+                                                description: it.siteName ?: '[' + it.webSiteId + ']']
+            }
+            break
+
+        case "PRIP_PROD_SGRP_ID":
+            from("ProductStoreGroup").limit(sizeLimit).queryList()?.each {
+                productPriceRulesCondValues << [key: it.productStoreGroupId,
+                                                description: it.productStoreGroupName ?: '[' + it.productStoreGroupId + ']']
+            }
+            break
+
+        case "PRIP_PROD_CLG_ID":
+            from("ProdCatalog").limit(sizeLimit).queryList()?.each {
+                productPriceRulesCondValues << [key: it.prodCatalogId,
+                                                description: it.catalogName ?: '[' + it.prodCatalogId + ']']
+            }
+            break
+
+        case "PRIP_CURRENCY_UOMID":
+            from("Uom").limit(sizeLimit).queryList()?.each {
+                productPriceRulesCondValues << [key: it.uomId,
+                                                description: it.abbreviation ?: '[' + it.uomId + ']']
+            }
+            break
+
+        default:
+            return success()
+            break
     }
+
+    result.productPriceRulesCondValues = []
     if (!productPriceRulesCondValues) {
-        String noOptions = UtilProperties.getMessage("CommonUiLabels", "CommonNoOptions", locale)
-        productPriceRulesCondValues << noOptions
+        result.productPriceRulesCondValues << UtilProperties.getMessage("CommonUiLabels", "CommonNoOptions", locale)
+    } else {
+        productPriceRulesCondValues.each {
+            result.productPriceRulesCondValues << it.description + ": " + it.key
+        }
     }
-    result.productPriceRulesCondValues = productPriceRulesCondValues
     return result
 }