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/14 18:00:23 UTC
[ofbiz-framework] 03/03: Improved: Convert
createPaymentAndPaymentGroupForInvoices service from mini-lang to groovy
DSL (OFBIZ-11490)
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
commit 9c538612f56381d647d5f2b4588249b3e4ee48dd
Author: Nicolas Malin <ni...@nereide.fr>
AuthorDate: Tue Sep 14 19:59:31 2021 +0200
Improved: Convert createPaymentAndPaymentGroupForInvoices service from mini-lang to groovy DSL (OFBIZ-11490)
Thanks to Sourabh Punyani for initiate the patch
---
.../groovyScripts/payment/PaymentServices.groovy | 43 ++++++++++++++++-
.../minilang/payment/PaymentServices.xml | 54 ----------------------
.../accounting/servicedef/services_payment.xml | 5 +-
3 files changed, 44 insertions(+), 58 deletions(-)
diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
index 795713b..f559df0 100644
--- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
+++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
@@ -18,9 +18,9 @@
*/
import org.apache.ofbiz.accounting.invoice.InvoiceWorker
import org.apache.ofbiz.accounting.payment.PaymentWorker
-import org.apache.ofbiz.base.util.Debug
import org.apache.ofbiz.base.util.UtilDateTime
import org.apache.ofbiz.base.util.UtilFormatOut
+import org.apache.ofbiz.base.util.UtilMisc
import org.apache.ofbiz.base.util.UtilProperties
import org.apache.ofbiz.entity.condition.EntityCondition
import org.apache.ofbiz.entity.condition.EntityOperator
@@ -507,6 +507,47 @@ def cancelCheckRunPayments() {
return success()
}
+def createPaymentAndPaymentGroupForInvoices() {
+ Map result
+ GenericValue paymentMethod = from("PaymentMethod").where("paymentMethodId", parameters.paymentMethodId).queryOne()
+
+ if (paymentMethod) {
+ GenericValue finAccount = from("FinAccount").where("finAccountId", paymentMethod.finAccountId).queryOne()
+ if (finAccount.statusId == "FNACT_MANFROZEN") {
+ return error(UtilProperties.getMessage('AccountingErrorUiLabels', 'AccountingFinAccountInactiveStatusError', locale))
+ } else if (finAccount.statusId == "FNACT_CANCELLED") {
+ return error(UtilProperties.getMessage('AccountingErrorUiLabels', 'AccountingFinAccountStatusNotValidError', locale))
+ }
+ }
+ Map partyInvoices = [:]
+ parameters.invoiceIds.each {invoiceId ->
+ GenericValue invoice = from("Invoice").where("invoiceId", invoiceId).queryOne()
+ UtilMisc.addToListInMap(invoice, partyInvoices, invoice.partyIdFrom)
+ }
+ List paymentIds = []
+ partyInvoices.each { partyId, invoice ->
+ if (parameters.checkStartNumber) {
+ parameters.checkStartNumber = parameters.checkStartNumber + 1
+ }
+ result = run service: 'createPaymentAndApplicationForParty', with: [* : parameters,
+ paymentMethodTypeId: paymentMethod.paymentMethodTypeId,
+ finAccountId : paymentMethod.finAccountId,
+ partyId : partyId,
+ invoices : invoice]
+ paymentIds << result.paymentId
+ }
+ if (paymentIds) {
+ result = run service: 'createPaymentGroupAndMember', with: [paymentIds : paymentIds,
+ paymentGroupTypeId: 'CHECK_RUN',
+ paymentGroupName : "Payment group for Check Run(InvoiceIds-${parameters.invoiceIds})"]
+ paymentGroupId = result.paymentGroupId
+ }
+ if (!result.paymentGroupId) {
+ return error(UtilProperties.getMessage("AccountingUiLabels", "AccountingNoInvoicesReadyOrOutstandingAmountZero", parameters.locale))
+ }
+ return result
+}
+
def createPaymentFromOrder() {
Map serviceResult = success()
diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml
index 642e9a0..c91e74f 100644
--- a/applications/accounting/minilang/payment/PaymentServices.xml
+++ b/applications/accounting/minilang/payment/PaymentServices.xml
@@ -211,60 +211,6 @@ under the License.
</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">
- <field-map field-name="finAccountId" from-field="paymentMethod.finAccountId"/>
- </entity-one>
- <if-compare field="finAccount.statusId" operator="equals" value="FNACT_MANFROZEN">
- <add-error>
- <fail-property resource="AccountingErrorUiLabels.xml" property="AccountingFinAccountInactiveStatusError"/>
- </add-error>
- </if-compare>
- <if-compare field="finAccount.statusId" operator="equals" value="FNACT_CANCELLED">
- <add-error>
- <fail-property resource="AccountingErrorUiLabels.xml" property="AccountingFinAccountStatusNotValidError"/>
- </add-error>
- </if-compare>
- <check-errors/>
- <set field="invoices" type="List"/>
- <iterate list="parameters.invoiceIds" entry="invoiceId">
- <entity-one entity-name="Invoice" value-field="invoice" auto-field-map="true"/>
- <clear-field field="invoices"/>
- <set field="invoices" from-field="partyInvoices.${invoice.partyIdFrom}"/>
- <field-to-list field="invoice" list="invoices"/>
- <set field="partyInvoices.${invoice.partyIdFrom}" from-field="invoices"/>
- </iterate>
- <clear-field field="invoices"/>
- <iterate-map map="partyInvoices" key="partyId" value="invoices">
- <set-service-fields service-name="createPaymentAndApplicationForParty" map="parameters" to-map="createPaymentAndApplicationForPartyMap"/>
- <set field="createPaymentAndApplicationForPartyMap.paymentMethodTypeId" from-field="paymentMethod.paymentMethodTypeId"/>
- <set field="createPaymentAndApplicationForPartyMap.finAccountId" from-field="paymentMethod.finAccountId"/>
- <set field="createPaymentAndApplicationForPartyMap.partyId" from-field="partyId"/>
- <set field="createPaymentAndApplicationForPartyMap.invoices" from-field="invoices"/>
- <if-not-empty field="parameters.checkStartNumber">
- <set field="parameters.checkStartNumber" value="${parameters.checkStartNumber + 1}" type="Long"/>
- </if-not-empty>
- <call-service service-name="createPaymentAndApplicationForParty" in-map-name="createPaymentAndApplicationForPartyMap">
- <result-to-field result-name="paymentId" field="paymentId"/>
- </call-service>
- <field-to-list field="paymentId" list="paymentIds"/>
- </iterate-map>
- <if-not-empty field="paymentIds">
- <set field="createPaymentGroupAndMemberMap.paymentIds" from-field="paymentIds"/>
- <set field="createPaymentGroupAndMemberMap.paymentGroupTypeId" value="CHECK_RUN"/>
- <set field="createPaymentGroupAndMemberMap.paymentGroupName" value="Payment group for Check Run(InvoiceIds-${parameters.invoiceIds})"/>
- <call-service service-name="createPaymentGroupAndMember" in-map-name="createPaymentGroupAndMemberMap">
- <result-to-field result-name="paymentGroupId"/>
- <result-to-result result-name="paymentGroupId"/>
- </call-service>
- </if-not-empty>
- <if-empty field="paymentGroupId">
- <property-to-field property="AccountingNoInvoicesReadyOrOutstandingAmountZero" resource="AccountingUiLabels" field="errorMessage"/>
- <field-to-result field="errorMessage" result-name="errorMessage"/>
- </if-empty>
- </simple-method>
-
<simple-method method-name="createPaymentGroupAndMember" short-description="creates PaymentGroup and PaymentGroupMembers">
<if-empty field="parameters.fromDate">
<now-timestamp field="parameters.fromDate"/>
diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml
index 233dff2..3941c9d 100644
--- a/applications/accounting/servicedef/services_payment.xml
+++ b/applications/accounting/servicedef/services_payment.xml
@@ -163,8 +163,8 @@ under the License.
<description>cancel payment batch</description>
<attribute name="paymentGroupId" type="String" mode="IN" optional="false"/>
</service>
- <service name="createPaymentAndPaymentGroupForInvoices" engine="simple"
- location="component://accounting/minilang/payment/PaymentServices.xml" invoke="createPaymentAndPaymentGroupForInvoices" auth="true">
+ <service name="createPaymentAndPaymentGroupForInvoices" engine="groovy"
+ location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="createPaymentAndPaymentGroupForInvoices" auth="true">
<description>Creates Payments, Payment Application and Payment Group for the same</description>
<attribute name="organizationPartyId" type="String" mode="IN" optional="false"/>
<attribute name="checkStartNumber" type="Long" mode="IN" optional="true"/>
@@ -172,7 +172,6 @@ under the License.
<attribute name="paymentMethodTypeId" type="String" mode="IN" optional="true"/>
<attribute name="paymentMethodId" type="String" mode="IN" optional="false"/>
<attribute name="paymentGroupId" type="String" mode="OUT" optional="true"/>
- <attribute name="errorMessage" type="String" optional="true" mode="OUT"/>
</service>
<service name="createPaymentAndApplicationForParty" engine="groovy"
location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="createPaymentAndApplicationForParty" auth="true">