Skip to content

Commit

Permalink
Fixeded: Convert createInvoiceItemPayrol service from mini-lang to gr…
Browse files Browse the repository at this point in the history
…oovy DSL (OFBIZ-11503)

Correct previous commit with remove empty file InvoiceEvents.xml, reoriented the function createInvoiceItemPayrol from InvoiceServices.groovy to new file InvoiceEvents.groovy
  • Loading branch information
nmalin committed Sep 17, 2021
1 parent 4112f1c commit aa9caa1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 58 deletions.
55 changes: 55 additions & 0 deletions applications/accounting/groovyScripts/invoice/InvoiceEvents.groovy
@@ -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()
}

Expand Up @@ -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()
}

25 changes: 0 additions & 25 deletions applications/accounting/minilang/invoice/InvoiceEvents.xml

This file was deleted.

Expand Up @@ -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>
Expand Down

0 comments on commit aa9caa1

Please sign in to comment.