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 <nicolas.ma...@nereide.fr>
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 via email to