You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by pa...@apache.org on 2020/07/01 10:20:41 UTC
[ofbiz-framework] branch trunk updated: Improved: Convert
cancelPaymentBatch service from mini-lang to groovy DSL(OFBIZ-11489)
This is an automated email from the ASF dual-hosted git repository.
pawan 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 20ba868 Improved: Convert cancelPaymentBatch service from mini-lang to groovy DSL(OFBIZ-11489)
20ba868 is described below
commit 20ba868b7d59770d261ceeeac9f669a847f87dac
Author: Pawan Verma <pa...@hotwaxsystems.com>
AuthorDate: Wed Jul 1 15:48:49 2020 +0530
Improved: Convert cancelPaymentBatch service from mini-lang to groovy DSL(OFBIZ-11489)
Thanks: Devanshu for report, Kirti for patch and Jacques for the review.
---
.../groovyScripts/payment/PaymentServices.groovy | 30 ++++++++++++++++++++++
.../minilang/payment/PaymentServices.xml | 27 -------------------
.../accounting/servicedef/services_payment.xml | 4 +--
3 files changed, 32 insertions(+), 29 deletions(-)
diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
index ecd5851..7375a59 100644
--- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
+++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
@@ -22,6 +22,7 @@ import org.apache.ofbiz.base.util.UtilProperties
import org.apache.ofbiz.entity.condition.EntityCondition
import org.apache.ofbiz.entity.condition.EntityOperator
import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.entity.util.EntityUtil
import org.apache.ofbiz.service.ModelService
import org.apache.ofbiz.service.ServiceUtil
import java.sql.Timestamp
@@ -253,6 +254,7 @@ def massChangePaymentStatus() {
return serviceResult
}
+
def createFinAccoutnTransFromPayment() {
serviceResult = success()
Map createFinAccountTransMap = dispatcher.getDispatchContext().makeValidContext('setPaymentStatus', ModelService.IN_PARAM, parameters)
@@ -291,4 +293,32 @@ def quickSendPayment() {
return result
+}
+
+/**
+ * Service to cancel payment batch
+ */
+def cancelPaymentBatch() {
+ List<GenericValue> paymentGroupMemberAndTransList = from("PmtGrpMembrPaymentAndFinAcctTrans").where("paymentGroupId", parameters.paymentGroupId).queryList()
+
+ if (paymentGroupMemberAndTransList) {
+ GenericValue paymentGroupMemberAndTrans = EntityUtil.getFirst(paymentGroupMemberAndTransList)
+ if ("FINACT_TRNS_APPROVED" == paymentGroupMemberAndTrans.finAccountTransStatusId) {
+ return error(UtilProperties.getMessage('AccountingErrorUiLabels', 'AccountingTransactionIsAlreadyReconciled', locale))
+ }
+
+ for (GenericValue paymentGroupMember : paymentGroupMemberAndTransList) {
+ Map expirePaymentGroupMemberMap = dispatcher.getDispatchContext().makeValidContext("expirePaymentGroupMember", "IN", paymentGroupMember)
+ result = runService("expirePaymentGroupMember", expirePaymentGroupMemberMap)
+ if (ServiceUtil.isError(result)) return result
+
+ GenericValue finAccountTrans = from("FinAccountTrans").where("finAccountTransId", paymentGroupMember.finAccountTransId).queryOne()
+ if (finAccountTrans) {
+ Map setFinAccountTransStatusMap = dispatcher.getDispatchContext().makeValidContext("setFinAccountTransStatus", "IN", finAccountTrans)
+ setFinAccountTransStatusMap.statusId = "FINACT_TRNS_CANCELED"
+ result = runService("setFinAccountTransStatus", setFinAccountTransStatusMap)
+ if (ServiceUtil.isError(result)) return result
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml
index d5895eb..d30eaa3 100644
--- a/applications/accounting/minilang/payment/PaymentServices.xml
+++ b/applications/accounting/minilang/payment/PaymentServices.xml
@@ -437,33 +437,6 @@ under the License.
</iterate>
</simple-method>
- <simple-method method-name="cancelPaymentBatch" short-description="cancel payment batch">
- <entity-and entity-name="PmtGrpMembrPaymentAndFinAcctTrans" list="paymentGroupMemberAndTransList">
- <field-map field-name="paymentGroupId" from-field="parameters.paymentGroupId"/>
- </entity-and>
- <if-not-empty field="paymentGroupMemberAndTransList">
- <first-from-list list="paymentGroupMemberAndTransList" entry="paymentGroupMemberAndTrans"/>
- <if-compare field="paymentGroupMemberAndTrans.finAccountTransStatusId" operator="equals" value="FINACT_TRNS_APPROVED">
- <add-error>
- <fail-property resource="AccountingUiLabels" property="AccountingTransactionIsAlreadyReconciled"/>
- </add-error>
- <check-errors/>
- </if-compare>
- <iterate list="paymentGroupMemberAndTransList" entry="paymentGroupMemberAndTrans">
- <set-service-fields service-name="expirePaymentGroupMember" map="paymentGroupMemberAndTrans" to-map="expirePaymentGroupMemberMap"/>
- <call-service service-name="expirePaymentGroupMember" in-map-name="expirePaymentGroupMemberMap"/>
- <entity-one entity-name="FinAccountTrans" value-field="finAccountTrans">
- <field-map field-name="finAccountTransId" from-field="paymentGroupMemberAndTrans.finAccountTransId"/>
- </entity-one>
- <if-not-empty field="finAccountTrans">
- <set-service-fields service-name="setFinAccountTransStatus" map="finAccountTrans" to-map="setFinAccountTransStatusMap"/>
- <set field="setFinAccountTransStatusMap.statusId" value="FINACT_TRNS_CANCELED"/>
- <call-service service-name="setFinAccountTransStatus" in-map-name="setFinAccountTransStatusMap"/>
- </if-not-empty>
- </iterate>
- </if-not-empty>
- </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 6d3f878..77f80df 100644
--- a/applications/accounting/servicedef/services_payment.xml
+++ b/applications/accounting/servicedef/services_payment.xml
@@ -158,8 +158,8 @@ under the License.
<attribute name="organizationPartyId" type="String" mode="IN" optional="true"/>
<attribute name="paymentRunningTotal" type="String" mode="OUT" optional="false"/>
</service>
- <service name="cancelPaymentBatch" engine="simple"
- location="component://accounting/minilang/payment/PaymentServices.xml" invoke="cancelPaymentBatch" auth="true">
+ <service name="cancelPaymentBatch" engine="groovy"
+ location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="cancelPaymentBatch" auth="true">
<description>cancel payment batch</description>
<attribute name="paymentGroupId" type="String" mode="IN" optional="false"/>
</service>