You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by nm...@apache.org on 2021/09/16 07:13:42 UTC

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

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


The following commit(s) were added to refs/heads/trunk by this push:
     new 08f4995  Improved: Convert createPaymentGroupAndMember service from mini-lang to groovy DSL (OFBIZ-11493)
08f4995 is described below

commit 08f4995cc7cf1709964e71aee7ccd18f91f12df2
Author: Nicolas Malin <ni...@nereide.fr>
AuthorDate: Thu Sep 16 09:12:54 2021 +0200

    Improved: Convert createPaymentGroupAndMember service from mini-lang to groovy DSL (OFBIZ-11493)
    
    Thanks to sourabh jain for the patch
---
 .../groovyScripts/payment/PaymentServices.groovy   | 22 ++++++
 .../minilang/payment/PaymentServices.xml           | 91 +---------------------
 .../accounting/servicedef/services_payment.xml     |  4 +-
 3 files changed, 25 insertions(+), 92 deletions(-)

diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
index cfa29b8..b3bade6 100644
--- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
+++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
@@ -444,6 +444,28 @@ def cancelCheckRunPayments() {
     return success()
 }
 
+def createPaymentGroupAndMember() {
+    serviceResult = success()
+    parameters.fromDate = parameters.fromDate ?:  UtilDateTime. nowTimestamp()
+    parameters.paymentGroupName = parameters.paymentGroupName ?: 'Payment Group Name'
+
+    Map result = run service: 'createPaymentGroup', with: parameters
+    if (ServiceUtil.isError(result)) {
+        return result
+    }
+    String paymentGroupId = result.paymentGroupId
+
+    parameters.paymentIds.each { paymentId ->
+        result = run service: 'createPaymentGroupMember', with: [paymentGroupId: paymentGroupId,
+                                                                 fromDate      : parameters.fromDate,
+                                                                 paymentId     : paymentId]
+        if (ServiceUtil.isError(result)) {
+            return result
+        }
+    }
+    return success(paymentGroupId: paymentGroupId)
+}
+
 def createPaymentAndPaymentGroupForInvoices() {
     Map result
     GenericValue paymentMethod = from("PaymentMethod").where("paymentMethodId", parameters.paymentMethodId).queryOne()
diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml
index d7f112b..b5d27d2 100644
--- a/applications/accounting/minilang/payment/PaymentServices.xml
+++ b/applications/accounting/minilang/payment/PaymentServices.xml
@@ -19,77 +19,8 @@ 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="updatePayment" short-description="Update a Payment">
-        <make-value entity-name="Payment" value-field="lookupPayment"/>
-        <set-pk-fields value-field="lookupPayment" map="parameters"/>
-
-        <find-by-primary-key entity-name="Payment" map="lookupPayment" value-field="payment"/>
-        <if>
-            <condition>
-                <and>
-                    <not><if-has-permission permission="ACCOUNTING" action="_UPDATE"/></not>
-                    <not><if-has-permission permission="PAY_INFO" action="_UPDATE"/></not>
-                    <not><if-compare-field field="userLogin.partyId" to-field="payment.partyIdFrom" operator="equals"/></not>
-                    <not><if-compare-field field="userLogin.partyId" to-field="payment.partyIdTo" operator="equals"/></not>
-                </and>
-            </condition>
-            <then>
-                <add-error>
-                    <fail-property resource="AccountingUiLabels" property="AccountingUpdatePaymentPermissionError"/>
-                </add-error>
-            </then>
-        </if>
-        <check-errors/>
-
-        <if-compare field="payment.statusId" value="PMNT_NOT_PAID" operator="not-equals">
-            <!-- check if only status change -->
-            <make-value entity-name="Payment" value-field="newPayment"/>
-            <make-value entity-name="Payment" value-field="oldPayment"/>
-            <set-nonpk-fields map="payment" value-field="newPayment"/>
-            <set-nonpk-fields map="payment" value-field="oldPayment"/>
-            <set-nonpk-fields map="parameters" value-field="newPayment"/>
-            <!-- fields :- comments, paymentRefNum, finAccountTransId, statusId can editable for Payment -->
-            <set field="oldPayment.statusId" from-field="newPayment.statusId"/>
-            <set field="oldPayment.comments" from-field="newPayment.comments"/>
-            <set field="oldPayment.paymentRefNum" from-field="newPayment.paymentRefNum" set-if-null="true"/>
-            <set field="oldPayment.finAccountTransId" from-field="newPayment.finAccountTransId" set-if-null="true"/>
-            <if-compare-field field="oldPayment" to-field="newPayment" operator="not-equals">
-                <add-error>
-                    <fail-property resource="AccountingUiLabels" property="AccountingPSUpdateNotAllowedBecauseOfStatus"/>
-                </add-error>
-            </if-compare-field>
-        </if-compare>
-        <check-errors/>
-
-        <set field="statusIdSave" from-field="payment.statusId"/><!-- do not allow status change here -->
-        <set-nonpk-fields map="parameters" value-field="payment"/>
-        <set field="payment.statusId" from-field="statusIdSave"/><!-- do not allow status change here -->
-
-        <if-empty field="payment.effectiveDate">
-            <now-timestamp field="payment.effectiveDate"/>
-        </if-empty>
-        <if-not-empty field="payment.paymentMethodId">
-            <entity-one entity-name="PaymentMethod" value-field="paymentMethod">
-                <field-map field-name="paymentMethodId" from-field="payment.paymentMethodId"/>
-            </entity-one>
-            <if-compare-field field="payment.paymentMethodTypeId" to-field="paymentMethod.paymentMethodTypeId" operator="not-equals">
-                <log level="info" message="Replacing passed payment method type [${payment.paymentMethodTypeId}] with payment method type [${paymentMethod.paymentMethodTypeId}] for payment method [${payment.paymentMethodId}]"/>
-            </if-compare-field>
-            <set field="payment.paymentMethodTypeId" from-field="paymentMethod.paymentMethodTypeId"/>
-        </if-not-empty>
-        <store-value value-field="payment"/>
-
-        <if-not-empty field="parameters.statusId">
-            <if-compare-field field="parameters.statusId" to-field="statusIdSave" operator="not-equals">
-                <set-service-fields service-name="setPaymentStatus" map="parameters" to-map="param"/>
-                <call-service service-name="setPaymentStatus" in-map-name="param"/>
-                <check-errors/>
-            </if-compare-field>
-        </if-not-empty>
-    </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"/>
@@ -136,26 +67,6 @@ under the License.
         </iterate>
     </simple-method>
 
-    <simple-method method-name="createPaymentGroupAndMember" short-description="creates PaymentGroup and PaymentGroupMembers">
-        <if-empty field="parameters.fromDate">
-            <now-timestamp field="parameters.fromDate"/>
-        </if-empty>
-        <set-service-fields service-name="createPaymentGroup" map="parameters" to-map="createPaymentGroupMap"/>
-        <if-empty field="parameters.paymentGroupName">
-            <set field="createPaymentGroupMap.paymentGroupName" value="Payment Group Name"/>
-        </if-empty>
-        <call-service service-name="createPaymentGroup" in-map-name="createPaymentGroupMap">
-            <result-to-field result-name="paymentGroupId"/>
-            <result-to-result result-name="paymentGroupId"/>
-        </call-service>
-        <set field="createPaymentGroupMemberMap.paymentGroupId" from-field="paymentGroupId"/>
-        <set field="createPaymentGroupMemberMap.fromDate" from-field="parameters.fromDate"/>
-        <iterate list="parameters.paymentIds" entry="paymentId">
-            <set field="createPaymentGroupMemberMap.paymentId" from-field="paymentId"/>
-            <call-service service-name="createPaymentGroupMember" in-map-name="createPaymentGroupMemberMap"/>
-        </iterate>
-    </simple-method>
-
     <simple-method method-name="checkAndCreateBatchForValidPayments" short-description="Check the valid(unbatched) payment and create batch for same">
         <set field="paymentIds" from-field="parameters.paymentIds"/>
         <entity-condition entity-name="Payment" list="payments">
diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml
index c244812..96c79fe 100644
--- a/applications/accounting/servicedef/services_payment.xml
+++ b/applications/accounting/servicedef/services_payment.xml
@@ -187,8 +187,8 @@ under the License.
         <attribute name="invoiceIds" type="List" mode="OUT" optional="true"/>
         <attribute name="amount" type="BigDecimal" mode="OUT" optional="true"/>
     </service>
-    <service name="createPaymentGroupAndMember" engine="simple"
-            location="component://accounting/minilang/payment/PaymentServices.xml" invoke="createPaymentGroupAndMember" auth="true">
+    <service name="createPaymentGroupAndMember" engine="groovy"
+            location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="createPaymentGroupAndMember" auth="true">
         <attribute name="paymentIds" type="List" mode="IN" optional="false"/>
         <attribute name="paymentGroupTypeId" type="String" mode="IN" optional="false"/>
         <attribute name="fromDate" type="Timestamp" mode="IN" optional="true"/>