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 faa59b3 Improved: Convert voidPayment service from mini-lang to
groovy DSL (OFBIZ-11487)
faa59b3 is described below
commit faa59b325fc50fc58b578c2b5d9b6d50d21b2478
Author: Jacques Le Roux <[email protected]>
AuthorDate: Sat Jul 25 10:30:47 2020 +0200
Improved: Convert voidPayment service from mini-lang to groovy DSL
(OFBIZ-11487)
Thanks: Sourabh Punyani
---
.../groovyScripts/payment/PaymentServices.groovy | 42 +++++++++++++++++++
.../minilang/payment/PaymentServices.xml | 47 ----------------------
.../accounting/servicedef/services_payment.xml | 4 +-
3 files changed, 44 insertions(+), 49 deletions(-)
diff --git
a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
index b3b6b6a..50e44e1 100644
--- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
+++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
@@ -319,6 +319,48 @@ 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 eb05f11..157ee84 100644
--- a/applications/accounting/minilang/payment/PaymentServices.xml
+++ b/applications/accounting/minilang/payment/PaymentServices.xml
@@ -267,53 +267,6 @@ 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 5a4d03a..a34ff87 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"/>