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 b2d1161 Improved: Convert checkAndCreateBatchForValidPayments service from mini-lang to groovy DSL (OFBIZ-11497) b2d1161 is described below commit b2d1161582fd3bab95381bd1ecfdc5f74c69c2f1 Author: Nicolas Malin <nicolas.ma...@nereide.fr> AuthorDate: Thu Sep 16 10:06:42 2021 +0200 Improved: Convert checkAndCreateBatchForValidPayments service from mini-lang to groovy DSL (OFBIZ-11497) Thanks to sourabh jain I started a solution with your patch --- .../groovyScripts/payment/PaymentServices.groovy | 24 +++++++++++++++ .../minilang/payment/PaymentServices.xml | 35 ---------------------- .../accounting/servicedef/services_payment.xml | 4 +-- 3 files changed, 26 insertions(+), 37 deletions(-) diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy index b3bade6..4d346aa 100644 --- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy +++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy @@ -31,6 +31,7 @@ import org.apache.ofbiz.entity.util.EntityUtilProperties import org.apache.ofbiz.service.ServiceUtil import java.sql.Timestamp +import org.apache.ofbiz.accounting.util.UtilAccounting def createPayment() { if (!security.hasEntityPermission("ACCOUNTING", "_CREATE", parameters.userLogin) && @@ -218,6 +219,29 @@ def createPaymentAndApplicationForParty() { amount : paymentAmount]) } +def checkAndCreateBatchForValidPayments() { + List disbursementPaymentIds = from("Payment") + .where(EntityCondition.makeCondition("paymentId", EntityOperator.IN, parameters.paymentIds)) + .queryList() + .stream() + .filter {!UtilAccounting.isReceipt(it)} + .map {it.paymentId} + .collect() + .toList() + if (disbursementPaymentIds) { + return error(label("AccountingUiLabels", "AccountingCannotIncludeApPaymentError", [disbursementPaymentIds: disbursementPaymentIds])) + } + List batchPaymentIds = from("PaymentGroupMember") + .where(EntityCondition.makeCondition("paymentId", EntityOperator.IN, parameters.paymentIds)) + .distinct() + .getFieldList('paymentId') + if (batchPaymentIds) { + return error(label("AccountingUiLabels", "AccountingPaymentsAreAlreadyBatchedError", [batchPaymentIds: batchPaymentIds])) + } + Map result = run service: 'createPaymentGroupAndMember', with: parameters + return result +} + def getPaymentRunningTotal(){ String currencyUomId List paymentIds = parameters.paymentIds diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml index b5d27d2..480dc67 100644 --- a/applications/accounting/minilang/payment/PaymentServices.xml +++ b/applications/accounting/minilang/payment/PaymentServices.xml @@ -66,39 +66,4 @@ under the License. <clear-field field="postAcctgTransMap"/> </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"> - <condition-expr field-name="paymentId" operator="in" from-field="paymentIds"/> - </entity-condition> - <iterate list="payments" entry="payment"> - <set field="isReceipt" value="${groovy:org.apache.ofbiz.accounting.util.UtilAccounting.isReceipt(payment)}" type="Boolean"/> - <if-compare field="isReceipt" operator="equals" value="false" type="Boolean"> - <field-to-list field="payment.paymentId" list="disbursementPaymentIds"/> - </if-compare> - </iterate> - <if-not-empty field="disbursementPaymentIds"> - <add-error> - <fail-property resource="AccountingUiLabels" property="AccountingCannotIncludeApPaymentError"/> - </add-error> - <check-errors/> - </if-not-empty> - <entity-condition entity-name="PaymentGroupMember" list="paymentGroupMembers" filter-by-date="true"> - <condition-expr field-name="paymentId" operator="in" from-field="paymentIds"/> - </entity-condition> - <if-not-empty field="paymentGroupMembers"> - <set field="batchPaymentIds" value="${groovy:org.apache.ofbiz.entity.util.EntityUtil.getFieldListFromEntityList(paymentGroupMembers, 'paymentId', true);}" type="List"/> - <add-error> - <fail-property resource="AccountingUiLabels" property="AccountingPaymentsAreAlreadyBatchedError"/> - </add-error> - <check-errors/> - <else> - <set-service-fields service-name="createPaymentGroupAndMember" map="parameters" to-map="createPaymentGroupAndMemberMap"/> - <call-service service-name="createPaymentGroupAndMember" in-map-name="createPaymentGroupAndMemberMap"> - <result-to-result result-name="paymentGroupId"/> - </call-service> - </else> - </if-not-empty> - </simple-method> </simple-methods> diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml index 96c79fe..666c53b 100644 --- a/applications/accounting/servicedef/services_payment.xml +++ b/applications/accounting/servicedef/services_payment.xml @@ -220,8 +220,8 @@ under the License. <attribute name="glReconciliationId" type="String" mode="OUT" optional="true"/> </service> - <service name="checkAndCreateBatchForValidPayments" engine="simple" - location="component://accounting/minilang/payment/PaymentServices.xml" invoke="checkAndCreateBatchForValidPayments" auth="true"> + <service name="checkAndCreateBatchForValidPayments" engine="groovy" + location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="checkAndCreateBatchForValidPayments" auth="true"> <description>Check the valid(unbatched) payment and create batch for same</description> <implements service="createPaymentGroupAndMember"/> </service>