You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2020/07/25 14:06:59 UTC

[ofbiz-framework] branch trunk updated: Revert "Improved: Convert voidPayment service from mini-lang to groovy DSL (OFBIZ-11487)"

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 2b04118  Revert "Improved: Convert voidPayment service from mini-lang to groovy DSL (OFBIZ-11487)"
2b04118 is described below

commit 2b041186909982f37b6a32688fe910d65b6d0fad
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Sat Jul 25 16:05:53 2020 +0200

    Revert "Improved: Convert voidPayment service from mini-lang to groovy DSL (OFBIZ-11487)"
    
    This reverts commit faa59b325fc50fc58b578c2b5d9b6d50d21b2478.
    
    It introduced 3 errors in testIntegration, in:
    testGlPostingOnCancelCheckRun
    testGlPostingsOnVoidPayment
    testVoidPayment
---
 .../groovyScripts/payment/PaymentServices.groovy   | 42 ----------
 .../minilang/payment/PaymentServices.xml           | 47 +++++++++++
 .../accounting/servicedef/services_payment.xml     |  4 +-
 .../product/minilang/product/test/CostTests.xml    | 90 ++++++++++++++++++++++
 .../minilang/product/test/ProductPriceTests.xml    | 66 ++++++++++++++++
 5 files changed, 205 insertions(+), 44 deletions(-)

diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
index 50e44e1..b3b6b6a 100644
--- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
+++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
@@ -319,48 +319,6 @@ def massChangePaymentStatus() {
     }
     return serviceResult
 }
-def voidPayment() {
-    GenericValue payment = from("Payment").where("paymentId", parameters.paymentId).queryOne()
-    finAccountTransId = payment.finAccountTransId
-    transStatusId = 'FINACT_TRNS_CANCELED'
-    statusId = transStatusId
-    if (!payment) {
-        return error(UtilProperties.getResourceBundleMap("AccountingUiLabels", locale)?.AccountingNoPaymentsfound)
-    }
-    paymentId = parameters.paymentId
-    Map paymentStatusCtx = [:]
-    paymentStatusCtx.paymentId = paymentId
-    paymentStatusCtx.statusId = 'PMNT_VOID'
-    run service: 'setPaymentStatus', with: paymentStatusCtx
-    paymentApplications = from("PaymentApplication").where('paymentId', paymentId).queryList()
-    if (paymentApplications) {
-        paymentApplications.each{ paymentApplication ->
-            updateInvoiceCtx = from("Invoice").where('invoiceId', paymentApplication.invoiceId).queryOne()
-            if (updateInvoiceCtx.statusId == 'INVOICE_PAID') {
-                Map invoiceStatusCtx = dispatcher.getDispatchContext().makeValidContext('setInvoiceStatus', ModelService.IN_PARAM, updateInvoiceCtx)
-                invoiceStatusCtx.paidDate = ''
-                invoiceStatusCtx.statusId = 'INVOICE_READY'
-                run service: 'setInvoiceStatus', with: invoiceStatusCtx
-            }
-            Map removePaymentApplicationCtx = [:]
-            removePaymentApplicationCtx.paymentApplicationId = paymentApplication.paymentApplicationId
-            run service: 'removePaymentApplication', with: removePaymentApplicationCtx
-        }
-        acctgTransPaymentList = from('AcctgTrans').where('invoiceId', '', 'paymentId', paymentId).queryList()
-        acctgTransPaymentList.each{ acctgTransPayment ->
-            Map copyAcctgTransCtx = [:]
-            copyAcctgTransCtx.fromAcctgTransId = acctgTransPayment.acctgTransId
-            copyAcctgTransCtx.revert = 'Y'
-            acctgTransId = run service: 'copyAcctgTransAndEntries', with: copyAcctgTransCtx
-            if (acctgTransPayment.isPosted == 'Y') {
-                Map postAcctgTransMap = [:]
-                postAcctgTransMap.acctgTransId = acctgTransId
-                run service: 'postAcctgTrans', with: postAcctgTransMap
-            }
-        }
-    }
-    return success()
-}
 
 def getPaymentGroupReconciliationId() {
     paymentGroupMember = from("PaymentGroupMember").where("paymentGroupId", parameters.paymentGroupId).queryFirst()
diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml
index 157ee84..eb05f11 100644
--- a/applications/accounting/minilang/payment/PaymentServices.xml
+++ b/applications/accounting/minilang/payment/PaymentServices.xml
@@ -267,6 +267,53 @@ under the License.
         <field-to-result field="selectedInvoicePaymentInfoList" result-name="invoicePaymentInfoList"/>
     </simple-method>
 
+    <simple-method method-name="voidPayment" short-description="Service to void a payment">
+        <entity-one entity-name="Payment" value-field="payment"/>
+        <field-to-result field="payment.finAccountTransId" result-name="finAccountTransId"/>
+        <set field="transStatusId" value="FINACT_TRNS_CANCELED"/>
+        <field-to-result field="transStatusId" result-name="statusId"/>
+        <if-empty field="payment">
+            <add-error>
+                <fail-property resource="AccountingUiLabels" property="AccountingNoPaymentsfound"/>
+            </add-error>
+            <check-errors/>
+        </if-empty>
+        <set field="paymentId" from-field="parameters.paymentId"/>
+        <set field="paymentStatusCtx.paymentId" from-field="paymentId"/>
+        <set field="paymentStatusCtx.statusId" value="PMNT_VOID"/>
+        <call-service service-name="setPaymentStatus" in-map-name="paymentStatusCtx"/>
+        <get-related relation-name="PaymentApplication" value-field="payment" list="paymentApplications"/>
+        <iterate list="paymentApplications" entry="paymentApplication">
+            <get-related-one relation-name="Invoice" value-field="paymentApplication" to-value-field="updateInvoiceCtx"/>
+            <if-compare field="updateInvoiceCtx.statusId" operator="equals" value="INVOICE_PAID">
+                <set-service-fields service-name="setInvoiceStatus" map="updateInvoiceCtx" to-map="invoiceStatusCtx"/>
+                <set field="invoiceStatusCtx.paidDate" type="Timestamp" value=""/>
+                <set field="invoiceStatusCtx.statusId" value="INVOICE_READY"/>
+                <call-service service-name="setInvoiceStatus" in-map-name="invoiceStatusCtx"/>
+            </if-compare>
+            <set field="removePaymentApplicationCtx.paymentApplicationId" from-field="paymentApplication.paymentApplicationId"/>
+            <call-service service-name="removePaymentApplication" in-map-name="removePaymentApplicationCtx"/>
+        </iterate>
+        <entity-condition entity-name="AcctgTrans" list="acctgTransPaymentList">
+            <condition-list combine="and">
+                <condition-expr field-name="invoiceId" operator="equals" from-field="nullField"/>
+                <condition-expr field-name="paymentId" from-field="paymentId"/>
+            </condition-list>
+        </entity-condition>
+        <iterate list="acctgTransPaymentList" entry="acctgTransPayment">
+            <clear-field field="copyAcctgTransCtx"/>
+            <set field="copyAcctgTransCtx.fromAcctgTransId" from-field="acctgTransPayment.acctgTransId"/>
+            <set field="copyAcctgTransCtx.revert" value="Y"/>
+            <call-service service-name="copyAcctgTransAndEntries" in-map-name="copyAcctgTransCtx">
+                <result-to-field result-name="acctgTransId" field="postAcctgTransMap.acctgTransId"/>
+            </call-service>
+            <if-compare field="acctgTransPayment.isPosted" operator="equals" value="Y">
+                <call-service service-name="postAcctgTrans" in-map-name="postAcctgTransMap"/>
+            </if-compare>
+            <clear-field field="postAcctgTransMap"/>
+        </iterate>
+    </simple-method>
+
     <simple-method method-name="createPaymentAndPaymentGroupForInvoices" short-description="Creates Payments, PaymentApplications and PaymentGroup for the same">
         <entity-one entity-name="PaymentMethod" value-field="paymentMethod" auto-field-map="true"/>
         <entity-one entity-name="FinAccount" value-field="finAccount" auto-field-map="false">
diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml
index a34ff87..5a4d03a 100644
--- a/applications/accounting/servicedef/services_payment.xml
+++ b/applications/accounting/servicedef/services_payment.xml
@@ -142,8 +142,8 @@ under the License.
         <attribute name="partyIdFrom" type="String" mode="IN" optional="true"/>
         <attribute name="invoicePaymentInfoList" type="List" mode="OUT" optional="true"/>
     </service>
-    <service name="voidPayment" engine="groovy"
-            location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="voidPayment" auth="true">
+    <service name="voidPayment" engine="simple" 
+            location="component://accounting/minilang/payment/PaymentServices.xml" invoke="voidPayment" auth="true">
         <description>Sets payment status to PMNT_VOID, removes all PaymentApplications, changes related invoice statuses to 
             INVOICE_READY if status is INVOICE_PAID, and reverses related AcctgTrans by calling copyAcctgTransAndEntries service</description>
         <permission-service service-name="acctgPaymentPermissionCheck" main-action="UPDATE"/>
diff --git a/applications/product/minilang/product/test/CostTests.xml b/applications/product/minilang/product/test/CostTests.xml
new file mode 100644
index 0000000..f7ddc68
--- /dev/null
+++ b/applications/product/minilang/product/test/CostTests.xml
@@ -0,0 +1,90 @@
+<?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">
+
+    <simple-method method-name="testCalculateProductStandardCosts" short-description="Test case for service calculateProductCosts" login-required="false">
+        <set field="productId" value="PROD_MANUF"/>
+        <entity-one entity-name="UserLogin" value-field="userLogin">
+            <field-map field-name="userLoginId" value="admin"/>
+        </entity-one>
+
+        <set field="serviceCtx.userLogin" from-field="userLogin"/>
+        <set field="serviceCtx.productId" from-field="productId"/>
+        <set field="serviceCtx.currencyUomId" value="USD"/>
+        <set field="serviceCtx.costComponentTypePrefix" value="EST_STD"/>
+        <call-service service-name="calculateProductCosts" in-map-name="serviceCtx"/>
+
+        <entity-and entity-name="CostComponent" list="costComponents">
+            <field-map field-name="productId" from-field="productId"/>
+        </entity-and>
+        <filter-list-by-date list="costComponents"/>
+        <set field="costTotalAmount" value="0.0" type="BigDecimal"/>
+        <iterate list="costComponents" entry="costComponent">
+            <assert>
+                <if-compare field="costComponent.costUomId" operator="equals" value="USD"/>
+                <or>
+                    <and>
+                        <if-compare field="costComponent.costComponentTypeId" operator="equals" value="EST_STD_ROUTE_COST"/>
+                        <if-compare field="costComponent.cost" operator="equals" value="10.00" type="BigDecimal"/>
+                    </and>
+                    <and>
+                        <if-compare field="costComponent.costComponentTypeId" operator="equals" value="EST_STD_MAT_COST"/>
+                        <if-compare field="costComponent.cost" operator="equals" value="39.00" type="BigDecimal"/>
+                    </and>
+                    <and>
+                        <if-compare field="costComponent.costComponentTypeId" operator="equals" value="EST_STD_OTHER_COST"/>
+                        <if-compare field="costComponent.cost" operator="equals" value="31.00" type="BigDecimal"/>
+                    </and>
+                    <and>
+                        <!--<if-compare field="costComponent.costComponentCalcId" operator="equals" value="GEN_COST_CALC"/>-->
+                        <if-compare field="costComponent.costComponentTypeId" operator="equals" value="EST_STD_GEN_COST"/>
+                        <if-compare field="costComponent.cost" operator="equals" value="4.00" type="BigDecimal"/>
+                    </and>
+                </or>
+            </assert>
+            <set field="costTotalAmount" value="${costTotalAmount + costComponent.cost}" type="BigDecimal"/>
+        </iterate>
+        <assert>
+            <if-compare field="costTotalAmount" operator="equals" value="84.00" type="BigDecimal"/>
+        </assert>
+        <check-errors/>
+    </simple-method>
+    <simple-method method-name="testGetProductCost" short-description="Test case for service getProductCost" login-required="false">
+        <set field="productId" value="PROD_MANUF"/>
+        <entity-one entity-name="UserLogin" value-field="userLogin">
+            <field-map field-name="userLoginId" value="admin"/>
+        </entity-one>
+
+        <set field="serviceCtx.userLogin" from-field="userLogin"/>
+        <set field="serviceCtx.productId" from-field="productId"/>
+        <set field="serviceCtx.currencyUomId" value="USD"/>
+        <set field="serviceCtx.costComponentTypePrefix" value="EST_STD"/>
+        <call-service service-name="getProductCost" in-map-name="serviceCtx">
+            <result-to-field result-name="productCost"/>
+        </call-service>
+
+        <assert>
+            <if-compare field="productCost" operator="equals" value="84.00" type="BigDecimal"/>
+        </assert>
+        <check-errors/>
+    </simple-method>
+</simple-methods>
diff --git a/applications/product/minilang/product/test/ProductPriceTests.xml b/applications/product/minilang/product/test/ProductPriceTests.xml
new file mode 100644
index 0000000..335207a
--- /dev/null
+++ b/applications/product/minilang/product/test/ProductPriceTests.xml
@@ -0,0 +1,66 @@
+<?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">
+
+    <simple-method method-name="testCalculateProductPrice" short-description="Test case for service calculateProductPrice" login-required="false">
+        <set field="productId" value="GZ-2002"/>
+        <entity-one entity-name="Product" value-field="product"/>
+        <set field="serviceCtx.product" from-field="product"/>
+        <call-service service-name="calculateProductPrice" in-map-name="serviceCtx">
+            <results-to-map map-name="resultMap"/>
+        </call-service>
+        <assert>
+            <if-compare field="resultMap.defaultPrice" operator="equals" value="47.99" type="BigDecimal"/>
+            <if-compare field="resultMap.listPrice" operator="equals" value="48" type="BigDecimal"/>
+        </assert>
+        <check-errors/>
+    </simple-method>
+
+    <simple-method method-name="testCalculateProductPriceOfVariantProduct" short-description="Test case for service calculateProductPrice, when product is a variant and does not have product price" login-required="false">
+        <!-- If product is a variant and no price is set, then default price of virtual product will be set -->
+        <set field="productId" value="GZ-1006-3"/>
+        <entity-one entity-name="Product" value-field="product"/>
+        <set field="serviceCtx.product" from-field="product"/>
+        <call-service service-name="calculateProductPrice" in-map-name="serviceCtx">
+            <results-to-map map-name="resultMap"/>
+        </call-service>
+        <assert>
+            <if-compare field="resultMap.defaultPrice" operator="equals" value="1.99" type="BigDecimal"/>
+            <if-compare field="resultMap.listPrice" operator="equals" value="5.99" type="BigDecimal"/>
+        </assert>
+        <check-errors/>
+    </simple-method>
+
+    <simple-method method-name="testCalculateProductPriceOfVirtualProduct" short-description="Test case for service calculateProductPrice, when product is virtual and does not have product price set" login-required="false">
+        <!--  If product is a virtual and no price is set then then the service return price of a variant product which have lowest DEFAULT_PRICE. It is also considered whether the product is discontinued for sale before using the lowest price against a variant for a virtual product  -->
+        <set field="productId" value="DemoProduct"/>
+        <entity-one entity-name="Product" value-field="product"/>
+        <set field="serviceCtx.product" from-field="product"/>
+        <call-service service-name="calculateProductPrice" in-map-name="serviceCtx">
+            <results-to-map map-name="resultMap"/>
+        </call-service>
+        <assert>
+            <if-compare field="resultMap.defaultPrice" operator="equals" value="10" type="BigDecimal"/>
+        </assert>
+        <check-errors/>
+    </simple-method>
+</simple-methods>