You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2020/05/31 06:52:29 UTC
[ofbiz-framework] 17/28: Improved: Converted updatePayment service
from mini-lang to groovy. (OFBIZ-11480) Thanks Devanshu Vyas for reporting
and Priya Sharma for the patch.
This is an automated email from the ASF dual-hosted git repository.
jleroux pushed a commit to branch ecomify-OFBIZ-11468_Convert_ShipmentReceiptServices-squashed
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit 835de7089a4a23925f5346bf58eaf9450e1173ef
Author: Suraj Khurana <su...@apache.org>
AuthorDate: Sat May 23 17:48:54 2020 +0530
Improved: Converted updatePayment service from mini-lang to groovy.
(OFBIZ-11480)
Thanks Devanshu Vyas for reporting and Priya Sharma for the patch.
---
.../groovyScripts/payment/PaymentServices.groovy | 50 ++++++++++++++++
.../minilang/payment/PaymentServices.xml | 68 ----------------------
.../accounting/servicedef/services_payment.xml | 4 +-
3 files changed, 52 insertions(+), 70 deletions(-)
diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
index 5e2749b..4032017 100644
--- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
+++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
@@ -63,6 +63,55 @@ def createPayment() {
result.paymentId = paymentId
return result
}
+def updatePayment() {
+ Map lookupPayment = delegator.makeValue("Payment")
+ lookupPayment.setPKFields(parameters)
+ GenericValue payment = from("Payment").where("paymentId", lookupPayment.paymentId).queryOne()
+ if (!security.hasEntityPermission("ACCOUNTING", "_UPDATE", parameters.userLogin) &&
+ (!security.hasEntityPermission("PAY_INFO", "_UPDATE", parameters.userLogin) &&
+ userLogin.partyId != payment.partyIdFrom && userLogin.partyId != payment.partyIdTo)) {
+ return error(UtilProperties.getResourceBundleMap("AccountingUiLabels", locale)?.AccountingUpdatePaymentPermissionError)
+ }
+ if ("PMNT_NOT_PAID" != payment.statusId) {
+ // check if only status change
+ GenericValue newPayment = delegator.makeValue("Payment")
+ GenericValue oldPayment = delegator.makeValue("Payment")
+ newPayment.setNonPKFields(payment)
+ oldPayment.setNonPKFields(payment)
+ newPayment.setNonPKFields(parameters)
+
+ // fields :- comments, paymentRefNum, finAccountTransId, statusIhStatus does not allow an update of the information are editable for Payment
+ oldPayment.statusId = newPayment.statusId
+ oldPayment.comments = newPayment.comments
+ oldPayment.paymentRefNum = newPayment.paymentRefNum ?: null
+ oldPayment.finAccountTransId = newPayment.finAccountTransId ?: null
+ if (!oldPayment.equals(newPayment)) {
+ return error(UtilProperties.getResourceBundleMap("AccountingUiLabels", locale)?.AccountingPSUpdateNotAllowedBecauseOfStatus)
+ }
+ }
+ statusIdSave = payment.statusId // do not allow status change here
+ payment.setNonPKFields(parameters)
+ payment.statusId = statusIdSave // do not allow status change here
+ payment.effectiveDate = payment.effectiveDate ?: UtilDateTime.nowTimestamp()
+ if (payment.paymentMethodId) {
+ paymentMethod = from("PaymentMethod").where("paymentMethodId", payment.paymentMethodId).queryOne()
+ if (payment.paymentMethodTypeId != paymentMethod.paymentMethodTypeId) {
+ Debug.logInfo("Replacing passed payment method type [" + parameters.paymentMethodTypeId + "] with payment method type [" +
+ paymentMethod.paymentMethodTypeId + "] for payment method [" + parameters.paymentMethodId +"]", MODULE)
+ }
+ payment.paymentMethodTypeId = paymentMethod.paymentMethodTypeId
+ }
+ payment.store()
+ if (parameters.statusId) {
+ if (parameters.statusId != statusIdSave) {
+ Map param = dispatcher.getDispatchContext().makeValidContext('setPaymentStatus', ModelService.IN_PARAM, parameters)
+ param.paymentId = payment.paymentId
+ serviceResult = run service: 'setPaymentStatus', with: param
+ if (!ServiceUtil.isSuccess(serviceResult)) return error(serviceResult)
+ }
+ }
+ return success()
+}
def createPaymentAndApplicationForParty() {
paymentAmount = 0
List invoiceIds = []
@@ -206,3 +255,4 @@ def massChangePaymentStatus() {
return serviceResult
}
+
diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml
index 9ce7e3b..3d8b2cc 100644
--- a/applications/accounting/minilang/payment/PaymentServices.xml
+++ b/applications/accounting/minilang/payment/PaymentServices.xml
@@ -20,74 +20,6 @@ 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="updatePayment" short-description="Update a Payment">
- <make-value entity-name="Payment" value-field="lookupPayment"/>
- <set-pk-fields value-field="lookupPayment" map="parameters"/>
-
- <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="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/>
-
- <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-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>
- <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.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>
- </simple-method>
<simple-method method-name="createPaymentApplication" short-description="Create a Payment Application">
<if-empty field="parameters.invoiceId">
<if-empty field="parameters.billingAccountId">
diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml
index 00099dd..0207643 100644
--- a/applications/accounting/servicedef/services_payment.xml
+++ b/applications/accounting/servicedef/services_payment.xml
@@ -37,8 +37,8 @@ under the License.
<override name="amount" optional="false"/>
</service>
- <service name="updatePayment" engine="simple" default-entity-name="Payment"
- location="component://accounting/minilang/payment/PaymentServices.xml" invoke="updatePayment" auth="true">
+ <service name="updatePayment" engine="groovy" default-entity-name="Payment"
+ location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="updatePayment" auth="true">
<description>Update a Payment</description>
<auto-attributes include="pk" mode="IN" optional="false"/>
<auto-attributes include="nonpk" mode="IN" optional="true"/>