Fixeded: Convert createInvoiceItemPayrol service from mini-lang to groovy DSL (OFBIZ-11503)

Correct previous commit with remove empty file InvoiceEvents.xml, reoriented the function createInvoiceItemPayrol from InvoiceServices.groovy to new file InvoiceEvents.groovy
This commit is contained in:
Nicolas Malin
2021-09-17 17:08:26 +02:00
parent 4112f1cb4b
commit aa9caa1a2d
4 changed files with 56 additions and 58 deletions
@@ -0,0 +1,55 @@
package invoice
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.ofbiz.entity.GenericValue
import org.apache.ofbiz.service.ServiceUtil
//Create a new Invoice Item with Payrol Item Type
def createInvoiceItemPayrol() {
List<GenericValue> payRolList = from("InvoiceItemType").queryList()
from("InvoiceItemType")
.where("parentTypeId", "PAYROL")
.queryList()
.each { payRolGroup ->
payRolList.each { payRol ->
if (payRol.parentTypeId == payRolGroup.invoiceItemTypeId) {
Map createInvoiceItem = [invoiceId : parameters.invoiceId,
invoiceItemTypeId: payRol.invoiceItemTypeId,
description : "${payRolGroup.description}: ${payRol.description}",
quantity : parameters."${payRol.invoiceItemTypeId}_Quantity" ?: 1d,
amount : parameters."${payRol.invoiceItemTypeId}_Amount" ?: 0d]
if (parameters."${payRol.invoiceItemTypeId}_Quantity" ||
parameters."${payRol.invoiceItemTypeId}_Amount") {
if ("PAYROL_EARN_HOURS" != payRolGroup.invoiceItemTypeId) {
createInvoiceItem.amount = createInvoiceItem.amount.negate()
}
Map serviceResult = run service: 'createInvoiceItem', with: createInvoiceItem
if (ServiceUtil.isError(serviceResult)) {
return serviceResult
}
}
}
}
}
return success()
}
@@ -128,35 +128,3 @@ def invoiceSequenceRestart() {
return success(invoiceId: "${curYearString}-${partyAcctgPreference.lastInvoiceNumber}")
}
//Create a new Invoice Item with Payrol Item Type
def createInvoiceItemPayrol() {
List<GenericValue> payRolList = from("InvoiceItemType").queryList()
from("InvoiceItemType")
.where("parentTypeId", "PAYROL")
.queryList()
.each { payRolGroup ->
payRolList.each { payRol ->
if (payRol.parentTypeId == payRolGroup.invoiceItemTypeId) {
Map createInvoiceItem = [invoiceId : parameters.invoiceId,
invoiceItemTypeId: payRol.invoiceItemTypeId,
description : "${payRolGroup.description}: ${payRol.description}",
quantity : parameters."${payRol.invoiceItemTypeId}_Quantity" ?: 1d,
amount : parameters."${payRol.invoiceItemTypeId}_Amount" ?: 0d]
if (parameters."${payRol.invoiceItemTypeId}_Quantity" ||
parameters."${payRol.invoiceItemTypeId}_Amount") {
if ("PAYROL_EARN_HOURS" != payRolGroup.invoiceItemTypeId) {
createInvoiceItem.amount = createInvoiceItem.amount.negate()
}
Map serviceResult = run service: 'createInvoiceItem', with: createInvoiceItem
if (ServiceUtil.isError(serviceResult)) {
return serviceResult
}
}
}
}
}
return success()
}
@@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
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-methods>
@@ -187,7 +187,7 @@ under the License.
</request-map>
<request-map uri="createInvoiceItemPayrol">
<security https="true" auth="true"/>
<event type="groovy" invoke="createInvoiceItemPayrol" path="component://accounting/groovyScripts/invoice/InvoiceServices.groovy"/>
<event type="groovy" invoke="createInvoiceItemPayrol" path="component://accounting/groovyScripts/invoice/InvoiceEvents.groovy"/>
<response name="success" type="view" value="listInvoiceItems"/>
<response name="error" type="view" value="listInvoiceItems"/>
</request-map>