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 06:52:32 UTC
[ofbiz-framework] branch trunk updated: Improved: Convert
createPaymentApplication service from mini-lang to groovy DSL (OFBIZ-11481)
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 7f0c5a7 Improved: Convert createPaymentApplication service from mini-lang to groovy DSL (OFBIZ-11481)
7f0c5a7 is described below
commit 7f0c5a78e1e2454d4831983d045a29d3ee9dc174
Author: Priya Sharma <pr...@example.com>
AuthorDate: Sat May 23 15:57:19 2020 +0530
Improved: Convert createPaymentApplication service from mini-lang to groovy DSL (OFBIZ-11481)
Done the following:
- removed mini-lang version of the service, added groovy version and updated the service definition
---
.../groovyScripts/payment/PaymentServices.groovy | 64 ++++++++
.../minilang/payment/PaymentServices.xml | 182 +++++++--------------
.../accounting/servicedef/services_payment.xml | 4 +-
3 files changed, 125 insertions(+), 125 deletions(-)
diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
index 6de101a..2b72fdc 100644
--- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
+++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
@@ -17,6 +17,8 @@
* under the License.
*/
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.UtilProperties
@@ -625,3 +627,65 @@ def createPaymentFromOrder() {
return result
}
}
+def createPaymentApplication() {
+ // Create a Payment Application
+ if (!parameters.invoiceId && !parameters.billingAccountId && !parameters.taxAuthGeoId && !parameters.toPaymentId) {
+ return error(UtilProperties.getMessage("AccountingUiLabels", "AccountingPaymentApplicationParameterMissing", locale))
+ }
+ GenericValue paymentAppl = delegator.makeValue("PaymentApplication")
+ paymentAppl.setNonPKFields(parameters)
+
+ GenericValue payment = from("Payment").where("paymentId", parameters.paymentId).queryOne()
+ if (!payment) {
+ return error(UtilProperties.getMessage("AccountingUiLabels", "AccountingPaymentApplicationParameterMissing", locale))
+ }
+
+ BigDecimal notAppliedPayment = PaymentWorker.getPaymentNotApplied(payment)
+
+ if (parameters.invoiceId) {
+ // get the invoice and do some further validation against it
+ GenericValue invoice = from("Invoice").where("invoiceId", parameters.invoiceId).queryOne()
+ // check the currencies if they are compatible
+ if (invoice.currencyUomId != payment.currencyUomId && invoice.currencyUomId != payment.actualCurrencyUomId) {
+ return error(UtilProperties.getMessage("AccountingUiLabels", "AccountingCurrenciesOfInvoiceAndPaymentNotCompatible", locale))
+ }
+ if (invoice.currencyUomId != payment.currencyUomId && invoice.currencyUomId == payment.actualCurrencyUomId) {
+ // if required get the payment amount in foreign currency (local we already have)
+ notAppliedPayment = PaymentWorker.getPaymentNotApplied(payment, true)
+ }
+ // get the amount that has not been applied yet for the invoice (outstanding amount)
+ BigDecimal notAppliedInvoice = InvoiceWorker.getInvoiceNotApplied(invoice)
+ paymentAppl.amountApplied = notAppliedInvoice <= notAppliedPayment
+ ? notAppliedInvoice : notAppliedPayment
+
+ if (invoice.billingAccountId) {
+ paymentAppl.billingAccountId = invoice.billingAccountId
+ }
+ }
+
+ if (parameters.toPaymentId) {
+ // get the to payment and check the parent types are compatible
+ GenericValue toPayment = from("Payment").where("paymentId", parameters.toPaymentId).queryOne()
+ // when amount not provided use the the lowest value available
+ if (!parameters.amountApplied) {
+ notAppliedPayment = PaymentWorker.getPaymentNotApplied(payment)
+ BigDecimal notAppliedToPayment = PaymentWorker.getPaymentNotApplied(toPayment)
+ paymentAppl.amountApplied = notAppliedPayment < notAppliedToPayment
+ ? notAppliedPayment : notAppliedToPayment
+ }
+ }
+
+ if (!paymentAppl.amountApplied) {
+ if (parameters.billingAccountId || parameters.taxAuthGeoId) {
+ paymentAppl.amountApplied = notAppliedPayment
+ }
+ }
+ paymentAppl.paymentApplicationId = delegator.getNextSeqId("PaymentApplication")
+ paymentAppl.create()
+
+ Map serviceResult = success()
+ serviceResult.amountApplied = paymentAppl.amountApplied
+ serviceResult.paymentApplicationId = paymentAppl.paymentApplicationId
+ serviceResult.paymentTypeId = payment.paymentTypeId
+ return serviceResult
+}
\ No newline at end of file
diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml
index 297e440..642e9a0 100644
--- a/applications/accounting/minilang/payment/PaymentServices.xml
+++ b/applications/accounting/minilang/payment/PaymentServices.xml
@@ -20,137 +20,73 @@ 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="createPaymentApplication" short-description="Create a Payment Application">
- <if-empty field="parameters.invoiceId">
- <if-empty field="parameters.billingAccountId">
- <if-empty field="parameters.taxAuthGeoId">
- <if-empty field="parameters.toPaymentId">
- <add-error>
- <fail-property resource="AccountingUiLabels" property="AccountingPaymentApplicationParameterMissing"/>
- </add-error>
- <check-errors/>
- </if-empty>
- </if-empty>
- </if-empty>
- </if-empty>
-
- <make-value entity-name="PaymentApplication" value-field="paymentAppl"/>
- <set-nonpk-fields map="parameters" value-field="paymentAppl"/>
-
- <entity-one entity-name="Payment" value-field="payment"/>
- <if-empty field="payment">
- <add-error>
- <fail-property resource="AccountingUiLabels" property="AccountingPaymentApplicationParameterMissing"/>
- </add-error>
- <check-errors/>
- </if-empty>
-
- <call-class-method method-name="getPaymentNotApplied" class-name="org.apache.ofbiz.accounting.payment.PaymentWorker" ret-field="notAppliedPayment">
- <field field="payment" type="GenericValue"/>
- </call-class-method>
-
- <if-not-empty field="parameters.invoiceId">
- <!-- get the invoice and do some further validation against it -->
- <entity-one entity-name="Invoice" value-field="invoice"/>
- <!-- check the currencies if they are compatible -->
- <if>
- <condition>
- <and>
- <if-compare-field field="invoice.currencyUomId" operator="not-equals" to-field="payment.currencyUomId"/>
- <if-compare-field field="invoice.currencyUomId" operator="not-equals" to-field="payment.actualCurrencyUomId"/>
- </and>
- </condition>
- <then>
- <add-error>
- <fail-property resource="AccountingUiLabels" property="AccountingCurrenciesOfInvoiceAndPaymentNotCompatible"/>
- </add-error>
- </then>
- </if>
- <check-errors/>
- <if>
- <condition>
- <and>
- <if-compare-field field="invoice.currencyUomId" operator="not-equals" to-field="payment.currencyUomId"/>
- <if-compare-field field="invoice.currencyUomId" operator="equals" to-field="payment.actualCurrencyUomId"/>
- </and>
- </condition>
- <then><!-- if required get the payment amount in foreign currency (local we already have) -->
- <set field="actual" value="true" type="Boolean"/>
- <call-class-method method-name="getPaymentNotApplied" class-name="org.apache.ofbiz.accounting.payment.PaymentWorker" ret-field="notAppliedPayment">
- <field field="payment" type="GenericValue"/>
- <field field="actual" type="Boolean"/>
- </call-class-method>
- </then>
- </if>
+ <simple-method method-name="updatePayment" short-description="Update a Payment">
+ <make-value entity-name="Payment" value-field="lookupPayment"/>
+ <set-pk-fields value-field="lookupPayment" map="parameters"/>
- <!-- get the amount that has not been applied yet for the invoice (outstanding amount) -->
- <call-class-method method-name="getInvoiceNotApplied" class-name="org.apache.ofbiz.accounting.invoice.InvoiceWorker" ret-field="notAppliedInvoice">
- <field field="invoice" type="GenericValue"/>
- </call-class-method>
+ <find-by-primary-key entity-name="Payment" map="lookupPayment" value-field="payment"/>
+ <if>
+ <condition>
+ <and>
+ <not><if-has-permission permission="ACCOUNTING" action="_UPDATE"/></not>
+ <not><if-has-permission permission="PAY_INFO" action="_UPDATE"/></not>
+ <not><if-compare-field field="userLogin.partyId" to-field="payment.partyIdFrom" operator="equals"/></not>
+ <not><if-compare-field field="userLogin.partyId" to-field="payment.partyIdTo" operator="equals"/></not>
+ </and>
+ </condition>
+ <then>
+ <add-error>
+ <fail-property resource="AccountingUiLabels" property="AccountingUpdatePaymentPermissionError"/>
+ </add-error>
+ </then>
+ </if>
+ <check-errors/>
- <if-compare-field field="notAppliedInvoice" operator="less-equals" to-field="notAppliedPayment" type="BigDecimal">
- <set field="paymentAppl.amountApplied" from-field="notAppliedInvoice"/>
- <else>
- <set field="paymentAppl.amountApplied" from-field="notAppliedPayment"/>
- </else>
- </if-compare-field>
+ <if-compare field="payment.statusId" value="PMNT_NOT_PAID" operator="not-equals">
+ <!-- check if only status change -->
+ <make-value entity-name="Payment" value-field="newPayment"/>
+ <make-value entity-name="Payment" value-field="oldPayment"/>
+ <set-nonpk-fields map="payment" value-field="newPayment"/>
+ <set-nonpk-fields map="payment" value-field="oldPayment"/>
+ <set-nonpk-fields map="parameters" value-field="newPayment"/>
+ <!-- fields :- comments, paymentRefNum, finAccountTransId, statusId can editable for Payment -->
+ <set field="oldPayment.statusId" from-field="newPayment.statusId"/>
+ <set field="oldPayment.comments" from-field="newPayment.comments"/>
+ <set field="oldPayment.paymentRefNum" from-field="newPayment.paymentRefNum" set-if-null="true"/>
+ <set field="oldPayment.finAccountTransId" from-field="newPayment.finAccountTransId" set-if-null="true"/>
+ <if-compare-field field="oldPayment" to-field="newPayment" operator="not-equals">
+ <add-error>
+ <fail-property resource="AccountingUiLabels" property="AccountingPSUpdateNotAllowedBecauseOfStatus"/>
+ </add-error>
+ </if-compare-field>
+ </if-compare>
+ <check-errors/>
- <if-not-empty field="invoice.billingAccountId">
- <set field="paymentAppl.billingAccountId" from-field="invoice.billingAccountId"/>
- </if-not-empty>
- </if-not-empty>
+ <set field="statusIdSave" from-field="payment.statusId"/><!-- do not allow status change here -->
+ <set-nonpk-fields map="parameters" value-field="payment"/>
+ <set field="payment.statusId" from-field="statusIdSave"/><!-- do not allow status change here -->
- <if-not-empty field="parameters.toPaymentId">
- <!-- get the to payment and check the parent types are compatible -->
- <entity-one entity-name="Payment" value-field="toPayment">
- <field-map field-name="paymentId" from-field="parameters.toPaymentId"/>
- </entity-one>
- <entity-one entity-name="PaymentType" value-field="toPaymentType">
- <field-map field-name="paymentTypeId" from-field="toPayment.paymentTypeId"/>
- </entity-one>
- <entity-one entity-name="Payment" value-field="payment">
- <field-map field-name="paymentId" from-field="parameters.paymentId"/>
- </entity-one>
- <entity-one entity-name="PaymentType" value-field="paymentType">
- <field-map field-name="paymentTypeId" from-field="payment.paymentTypeId"/>
+ <if-empty field="payment.effectiveDate">
+ <now-timestamp field="payment.effectiveDate"/>
+ </if-empty>
+ <if-not-empty field="payment.paymentMethodId">
+ <entity-one entity-name="PaymentMethod" value-field="paymentMethod">
+ <field-map field-name="paymentMethodId" from-field="payment.paymentMethodId"/>
</entity-one>
-
- <!-- when amount not provided use the the lowest value available -->
- <if-empty field="parameters.amountApplied">
- <call-class-method method-name="getPaymentNotApplied" class-name="org.apache.ofbiz.accounting.payment.PaymentWorker" ret-field="notAppliedPayment">
- <field field="payment" type="GenericValue"/>
- </call-class-method>
- <call-class-method method-name="getPaymentNotApplied" class-name="org.apache.ofbiz.accounting.payment.PaymentWorker" ret-field="notAppliedToPayment">
- <field field="toPayment" type="GenericValue"/>
- </call-class-method>
- <if-compare-field field="notAppliedPayment" operator="less" to-field="notAppliedToPayment">
- <set field="paymentAppl.amountApplied" from-field="notAppliedPayment"/>
- <else>
- <set field="paymentAppl.amountApplied" from-field="notAppliedToPayment"/>
- </else>
- </if-compare-field>
- </if-empty>
- </if-not-empty>
-
- <if-not-empty field="parameters.billingAccountId">
- <if-empty field="paymentAppl.amountApplied">
- <set field="paymentAppl.amountApplied" from-field="notAppliedPayment"/>
- </if-empty>
+ <if-compare-field field="payment.paymentMethodTypeId" to-field="paymentMethod.paymentMethodTypeId" operator="not-equals">
+ <log level="info" message="Replacing passed payment method type [${payment.paymentMethodTypeId}] with payment method type [${paymentMethod.paymentMethodTypeId}] for payment method [${payment.paymentMethodId}]"/>
+ </if-compare-field>
+ <set field="payment.paymentMethodTypeId" from-field="paymentMethod.paymentMethodTypeId"/>
</if-not-empty>
+ <store-value value-field="payment"/>
- <if-not-empty field="parameters.taxAuthGeoId">
- <if-empty field="paymentAppl.amountApplied">
- <set field="paymentAppl.amountApplied" from-field="notAppliedPayment"/>
- </if-empty>
+ <if-not-empty field="parameters.statusId">
+ <if-compare-field field="parameters.statusId" to-field="statusIdSave" operator="not-equals">
+ <set-service-fields service-name="setPaymentStatus" map="parameters" to-map="param"/>
+ <call-service service-name="setPaymentStatus" in-map-name="param"/>
+ <check-errors/>
+ </if-compare-field>
</if-not-empty>
-
- <sequenced-id sequence-name="PaymentApplication" field="paymentAppl.paymentApplicationId"/>
- <field-to-result field="paymentAppl.amountApplied" result-name="amountApplied"/>
- <field-to-result field="paymentAppl.paymentApplicationId" result-name="paymentApplicationId"/>
-
- <create-value value-field="paymentAppl"/>
- <entity-one entity-name="Payment" value-field="payment"/>
- <field-to-result field="payment.paymentTypeId" result-name="paymentTypeId"/>
</simple-method>
<simple-method method-name="setPaymentStatus" short-description="Set The Payment Status">
diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml
index e95be9d..233dff2 100644
--- a/applications/accounting/servicedef/services_payment.xml
+++ b/applications/accounting/servicedef/services_payment.xml
@@ -66,8 +66,8 @@ under the License.
<auto-attributes include="nonpk" mode="IN" optional="true"/>
</service>
- <service name="createPaymentApplication" engine="simple"
- location="component://accounting/minilang/payment/PaymentServices.xml" invoke="createPaymentApplication" auth="true">
+ <service name="createPaymentApplication" engine="groovy"
+ location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="createPaymentApplication" auth="true">
<description>Create a payment application</description>
<attribute name="paymentId" type="String" mode="IN" optional="false"/>
<attribute name="toPaymentId" type="String" mode="IN" optional="true"/>