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/06/27 10:06:38 UTC

[ofbiz-framework] branch trunk updated: Improved: Convert createFinAccoutnTransFromPayment service from mini-lang to groovy DSL (OFBIZ-11492)

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 f421af3  Improved: Convert createFinAccoutnTransFromPayment service from mini-lang to groovy DSL (OFBIZ-11492)
f421af3 is described below

commit f421af33a35f2c5087ab4a0e1fa292991af3ecb0
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Sat Jun 27 12:06:46 2020 +0200

    Improved: Convert createFinAccoutnTransFromPayment service from mini-lang to groovy DSL (OFBIZ-11492)
    
    Thanks: Devanshu Vyas  for report, Anushi Gupta for the patch
---
 .../groovyScripts/payment/PaymentServices.groovy   | 23 ++++++++++++++++++++++
 .../minilang/payment/PaymentServices.xml           | 16 ---------------
 .../accounting/servicedef/services_payment.xml     |  4 ++--
 3 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
index 3317ccd..4479bb8 100644
--- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
+++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
@@ -253,4 +253,27 @@ def massChangePaymentStatus() {
     return serviceResult
 }
 
+def createFinAccoutnTransFromPayment() {
+    serviceResult = success()
+    Map createFinAccountTransMap = dispatcher.getDispatchContext().makeValidContext('setPaymentStatus', ModelService.IN_PARAM, parameters)
+    createFinAccountTransMap.finAccountTransTypeId = 'WITHDRAWAL'
+    createFinAccountTransMap.partyId  = parameters.organizationPartyId
+    createFinAccountTransMap.transactionDate = UtilDateTime.nowTimestamp()
+    createFinAccountTransMap.entryDate = UtilDateTime.nowTimestamp()
+    createFinAccountTransMap.statusId = 'FINACT_TRNS_CREATED'
+    createFinAccountTransMap.comments = "Pay to ${parameters.partyId} for invoice Ids - ${parameters.invoiceIds}"
+    result = run service: 'createFinAccountTrans', with: createFinAccountTransMap
+    if (ServiceUtil.isError(result)) {
+        return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result))
+    }
+    Map updatePaymentMap = [:]
+    updatePaymentMap.finAccountTransId = result.finAccountTransId
+    updatePaymentMap.paymentId = parameters.paymentId
+    result = run service: 'updatePayment', with: updatePaymentMap
+    if (ServiceUtil.isError(result)) {
+        return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result))
+    }
+    return serviceResult
+}
+
 
diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml
index 3d8b2cc..59be652 100644
--- a/applications/accounting/minilang/payment/PaymentServices.xml
+++ b/applications/accounting/minilang/payment/PaymentServices.xml
@@ -525,22 +525,6 @@ under the License.
         </if-empty>
     </simple-method>
 
-    <simple-method method-name="createFinAccoutnTransFromPayment" short-description="Creates a record for FinAccountTrans on creation of payment.">
-        <set-service-fields service-name="createFinAccountTrans" map="parameters" to-map="createFinAccountTransMap"/>
-        <set field="createFinAccountTransMap.finAccountTransTypeId" value="WITHDRAWAL"/>
-        <set field="createFinAccountTransMap.partyId" from-field="parameters.organizationPartyId"/>
-        <now-timestamp field="createFinAccountTransMap.transactionDate"/>
-        <now-timestamp field="createFinAccountTransMap.entryDate"/>
-        <set field="createFinAccountTransMap.statusId" value="FINACT_TRNS_CREATED"/>
-        <set field="createFinAccountTransMap.comments" value="Pay to ${parameters.partyId} for invoice Ids - ${parameters.invoiceIds}"/>
-        <call-service service-name="createFinAccountTrans" in-map-name="createFinAccountTransMap">
-            <result-to-field result-name="finAccountTransId"/>
-        </call-service>
-        <set field="updatePaymentMap.finAccountTransId" from-field="finAccountTransId"/>
-        <set field="updatePaymentMap.paymentId" from-field="parameters.paymentId"/>
-        <call-service service-name="updatePayment" in-map-name="updatePaymentMap"/>
-    </simple-method>
-
     <simple-method method-name="createPaymentGroupAndMember" short-description="creates PaymentGroup and PaymentGroupMembers">
         <if-empty field="parameters.fromDate">
             <now-timestamp field="parameters.fromDate"/>
diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml
index 0207643..ad9e4a9 100644
--- a/applications/accounting/servicedef/services_payment.xml
+++ b/applications/accounting/servicedef/services_payment.xml
@@ -201,8 +201,8 @@ under the License.
         <description>Cancel all payments for payment group</description>
         <attribute name="paymentGroupId" type="String" mode="IN" optional="false"/>
     </service>
-    <service name="createFinAccoutnTransFromPayment" engine="simple"
-            location="component://accounting/minilang/payment/PaymentServices.xml" invoke="createFinAccoutnTransFromPayment" auth="true">
+    <service name="createFinAccoutnTransFromPayment" engine="groovy"
+            location="component://accounting/groovyScripts/payment/PaymentServices.xml" invoke="createFinAccoutnTransFromPayment" auth="true">
         <auto-attributes entity-name="FinAccountTrans" include="nonpk" mode="IN" optional="true"/>
         <auto-attributes entity-name="FinAccountTrans" include="pk" mode="INOUT" optional="true"/>
         <attribute name="invoiceIds" type="List" mode="IN" optional="true"/>