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 09:02:34 UTC
[ofbiz-framework] branch trunk updated: Improved: Convert
voidPayment service from mini-lang to groovy DSL (OFBIZ-11487)
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 a8afcff Improved: Convert voidPayment service from mini-lang to groovy DSL (OFBIZ-11487)
a8afcff is described below
commit a8afcff11324a168b84376769dc8ad337a9a288d
Author: Nicolas Malin <nm...@apache.org>
AuthorDate: Sat Jul 25 10:30:47 2020 +0200
Improved: Convert voidPayment service from mini-lang to groovy DSL (OFBIZ-11487)
reload the last commit faa59b325fc50fc58b578c2b5d9b6d50d21b2478 reverted with improve the groovy syntax and remove the empty fiels PaymentServices.xml
Thanks: Sourabh Punyani
---
.../groovyScripts/payment/PaymentServices.groovy | 37 ++++++++++++
.../minilang/payment/PaymentServices.xml | 69 ----------------------
.../accounting/servicedef/services_payment.xml | 4 +-
3 files changed, 39 insertions(+), 71 deletions(-)
diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
index 4d346aa..45b93c1 100644
--- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
+++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
@@ -337,6 +337,43 @@ def getInvoicePaymentInfoListByDueDateOffset() {
return success(invoicePaymentInfoList: filteredInvoicePaymentInfoList)
}
+def voidPayment() {
+ GenericValue payment = from("Payment").where(parameters).queryOne()
+ if (!payment) {
+ return error(UtilProperties.getResourceBundleMap("AccountingUiLabels", locale)?.AccountingNoPaymentsfound)
+ }
+ String paymentId = payment.paymentId
+ Map paymentStatusCtx = [paymentId: paymentId,
+ statusId : 'PMNT_VOID']
+ run service: 'setPaymentStatus', with: paymentStatusCtx
+ from("PaymentApplication")
+ .where(paymentId: paymentId)
+ .queryList()
+ .each { it ->
+ Map invoice = from("Invoice").where(invoiceId: it.invoiceId).queryOne()
+ if (invoice.statusId == 'INVOICE_PAID') {
+ run service: 'setInvoiceStatus', with: [* : invoice.getAllFields(),
+ paidDate: null,
+ statusId: 'INVOICE_READY']
+ }
+ run service: 'removePaymentApplication', with: [paymentApplicationId: it.paymentApplicationId]
+ }
+
+ from('AcctgTrans')
+ .where(invoiceId: null,
+ paymentId: paymentId)
+ .queryList()
+ .each { it ->
+ Map result = run service: 'copyAcctgTransAndEntries', with: [fromAcctgTransId: it.acctgTransId,
+ revert : 'Y']
+ if (it.isPosted == 'Y') {
+ run service: 'postAcctgTrans', with: [acctgTransId: result.acctgTransId]
+ }
+ }
+ return success([finAccountTransId: payment.finAccountTransId,
+ statusId : 'FINACT_TRNS_CANCELED'])
+}
+
def getPaymentGroupReconciliationId() {
GenericValue paymentGroupMember = from("PaymentGroupMember")
.where("paymentGroupId", parameters.paymentGroupId)
diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml
deleted file mode 100644
index 480dc67..0000000
--- a/applications/accounting/minilang/payment/PaymentServices.xml
+++ /dev/null
@@ -1,69 +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">
- <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-methods>
diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml
index 666c53b..3c3125e 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="simple"
- location="component://accounting/minilang/payment/PaymentServices.xml" invoke="voidPayment" auth="true">
+ <service name="voidPayment" engine="groovy"
+ location="component://accounting/groovyScripts/payment/PaymentServices.groovy" 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"/>