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 2018/08/31 17:29:55 UTC
svn commit: r1839778 - in
/ofbiz/ofbiz-framework/trunk/applications/accounting:
groovyScripts/invoice/InvoiceServices.groovy
minilang/invoice/InvoiceServices.xml servicedef/services_invoice.xml
Author: nmalin
Date: Fri Aug 31 17:29:55 2018
New Revision: 1839778
URL: http://svn.apache.org/viewvc?rev=1839778&view=rev
Log:
Improved: Convert InvoiceServices.xml mini lang to groovy
(OFBIZ-9986)
Convert services getNextInvoiceId, invoiceSequenceEnforced and invoiceSequenceRestart from minilang to groovy.
This is a subtask of OFBIZ-9350 Deprecate Mini Lang
Thanks to Leila Mekika for this issue
Added:
ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/invoice/InvoiceServices.groovy (with props)
Modified:
ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/invoice/InvoiceServices.xml
ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_invoice.xml
Added: ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/invoice/InvoiceServices.groovy
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/invoice/InvoiceServices.groovy?rev=1839778&view=auto
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/invoice/InvoiceServices.groovy (added)
+++ ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/invoice/InvoiceServices.groovy Fri Aug 31 17:29:55 2018
@@ -0,0 +1,132 @@
+/*
+ * 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.base.util.Debug
+import org.apache.ofbiz.base.util.UtilDateTime
+import org.apache.ofbiz.base.util.UtilValidate
+import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.service.ServiceUtil
+
+import java.sql.Timestamp
+
+def getNextInvoiceId() {
+ result = success()
+
+ // try to find PartyAcctgPreference for parameters.partyId, see if we need any special invoice number sequencing
+ GenericValue partyAcctgPreference = from('PartyAcctgPreference').where(parameters).queryOne()
+ if (Debug.infoOn()) Debug.logInfo("In getNextInvoiceId partyId is [${parameters.partyId}], partyAcctgPreference: ${partyAcctgPreference}", 'InvoiceServices.groovy')
+
+ String customMethodName = null;
+ String invoiceIdPrefix = '';
+ if (partyAcctgPreference) {
+ invoiceIdPrefix = partyAcctgPreference.invoiceIdPrefix
+ //see OFBIZ-3765 beware of OFBIZ-3557
+ GenericValue customMethod = partyAcctgPreference.getRelatedOne('InvoiceCustomMethod', true)
+ if (customMethod) {
+ customMethodName = customMethod.customMethodName
+ } else {
+ //retrieve service from deprecated enumeration see OFBIZ-3765 beware of OFBIZ-3557
+ if ('INVSQ_ENF_SEQ' == partyAcctgPreference.oldInvoiceSequenceEnumId) {
+ customMethodName = 'invoiceSequenceEnforced'
+ }
+ if ('INVSQ_RESTARTYR' == partyAcctgPreference.oldInvoiceSequenceEnumId) {
+ customMethodName = 'invoiceSequenceRestart'
+ }
+ }
+ } else {
+ Debug.logWarning('Acctg preference not defined for partyId [${parameters.partyId}]', 'InvoiceServices.groovy')
+ }
+
+ String invoiceIdTemp = ''
+ if (customMethodName) {
+ parameters.partyAcctgPreference = partyAcctgPreference
+ Map serviceResult = run service: customMethodName, with: parameters
+ if (ServiceUtil.isError(serviceResult)) return serviceResult
+ invoiceIdTemp = serviceResult.invoiceId
+ } else {
+ Debug.logInfo('In createInvoice sequence enum Standard', 'InvoiceServices.groovy')
+ //default to the default sequencing: INVSQ_STANDARD
+ invoiceIdTemp = parameters.invoiceId
+ if (!invoiceIdTemp) {
+ invoiceIdTemp = delegator.getNextSeqId('Invoice', 1)
+ } else {
+ //check the provided ID
+ errorMsg = UtilValidate.checkValidDatabaseId(invoiceIdTemp)
+ if (errorMsg != null) {
+ return error("In getNextInvoiceId ${errorMsg}")
+ }
+ }
+ }
+
+ // use invoiceIdTemp along with the invoiceIdPrefix to create the real ID
+ String invoiceId = invoiceIdPrefix + invoiceIdTemp
+ result.invoiceId = invoiceId
+ return result
+}
+
+def invoiceSequenceEnforced() {
+ result = success()
+
+ Debug.logInfo('In createInvoice sequence enum Enforced', 'InvoiceServices.groovy')
+ GenericValue partyAcctgPreference = parameters.partyAcctgPreference
+ //this is sequential sequencing, we can't skip a number, also it must be a unique sequence per partyIdFrom
+
+ Long lastInvoiceNumber = 1
+ if (partyAcctgPreference.lastInvoiceNumber) {
+ lastInvoiceNumber = partyAcctgPreference.lastInvoiceNumber + 1
+ }
+
+ partyAcctgPreference.lastInvoiceNumber = lastInvoiceNumber
+ delegator.store(partyAcctgPreference)
+ result.invoiceId = lastInvoiceNumber
+ return result
+}
+
+def invoiceSequenceRestart() {
+ result = success()
+
+ Debug.logInfo('In createInvoice sequence enum Enforced', 'InvoiceServices.groovy')
+ GenericValue partyAcctgPreference = parameters.partyAcctgPreference
+ //this is sequential sequencing, we can't skip a number, also it must be a unique sequence per partyIdFrom
+
+ Timestamp nowTimestamp = UtilDateTime.nowTimestamp()
+ if (!partyAcctgPreference.lastInvoiceRestartDate) {
+ //if no lastInvoiceRestartDate then it's easy, just start now with 1
+ partyAcctgPreference.lastInvoiceNumber = 1l
+ partyAcctgPreference.lastInvoiceRestartDate = nowTimestamp
+ } else {
+ //first figure out if we need to reset the lastInvoiceNumber; is the lastInvoiceRestartDate after the fiscalYearStartMonth/Day for this year?
+ curYearFiscalStartDate = UtilDateTime.getYearStart(nowTimestamp, partyAcctgPreference.fiscalYearStartDay, partyAcctgPreference.fiscalYearStartMonth, 0l)
+ if (partyAcctgPreference.lastInvoiceRestartDate < curYearFiscalStartDate && nowTimestamp >= curYearFiscalStartDate) {
+ //less than fiscal year start, we need to reset it
+ partyAcctgPreference.lastInvoiceNumber = 1l
+ partyAcctgPreference.lastInvoiceRestartDate = nowTimestamp
+ } else {
+ //greater than or equal to fiscal year start or nowTimestamp hasn't yet hit the current year fiscal start date, we're okay, just increment
+ partyAcctgPreference.lastInvoiceNumber += 1l
+ }
+ }
+ delegator.store(partyAcctgPreference)
+
+ //get the current year string for prefix, etc; simple 4 digit year date string (using system defaults)
+ Integer curYearString = UtilDateTime.getYear(partyAcctgPreference.lastInvoiceRestartDate, timeZone, locale)
+ result.invoiceId = "${curYearString}-${partyAcctgPreference.lastInvoiceNumber}"
+ return result
+}
+
Propchange: ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/invoice/InvoiceServices.groovy
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/invoice/InvoiceServices.groovy
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange: ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/invoice/InvoiceServices.groovy
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/invoice/InvoiceServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/invoice/InvoiceServices.xml?rev=1839778&r1=1839777&r2=1839778&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/invoice/InvoiceServices.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/invoice/InvoiceServices.xml Fri Aug 31 17:29:55 2018
@@ -21,127 +21,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="getNextInvoiceId" short-description="Get Next invoiceId">
- <!-- try to find PartyAcctgPreference for parameters.partyId, see if we need any special invoice number sequencing -->
- <entity-one entity-name="PartyAcctgPreference" value-field="partyAcctgPreference" auto-field-map="false">
- <field-map field-name="partyId" from-field="parameters.partyId"/>
- </entity-one>
- <log level="info" message="In getNextInvoiceId partyId is [${parameters.partyId}], partyAcctgPreference: ${partyAcctgPreference}"/>
-
- <if-not-empty field="partyAcctgPreference">
- <!-- see OFBIZ-3765 beware of OFBIZ-3557 -->
- <get-related-one relation-name="InvoiceCustomMethod" value-field="partyAcctgPreference" to-value-field="customMethod"/>
- <else>
- <log level="warning" message="Acctg preference not defined for partyId [${parameters.partyId}]"/>
- </else>
- </if-not-empty>
-
- <if-not-empty field="customMethod">
- <set field="customMethodName" from-field="customMethod.customMethodName"/>
- <else><!-- retrieve service from deprecated enumeration see OFBIZ-3765 beware of OFBIZ-3557 -->
- <if-compare operator="equals" value="INVSQ_ENF_SEQ" field="partyAcctgPreference.oldInvoiceSequenceEnumId">
- <set field="customMethodName" value="invoiceSequenceEnforced"/>
- </if-compare>
- <if-compare operator="equals" value="INVSQ_RESTARTYR" field="partyAcctgPreference.oldInvoiceSequenceEnumId">
- <set field="customMethodName" value="invoiceSequenceRestart"/>
- </if-compare>
- </else>
- </if-not-empty>
-
- <if-not-empty field="customMethodName">
- <set-service-fields service-name="${customMethodName}" map="parameters" to-map="customMethodMap"/>
- <set field="customMethodMap.partyAcctgPreference" from-field="partyAcctgPreference"/>
- <call-service service-name="${customMethodName}" in-map-name="customMethodMap">
- <result-to-field result-name="invoiceId" field="invoiceIdTemp"/>
- </call-service>
- <else>
- <log level="info" message="In createInvoice sequence enum Standard"/>
- <!-- default to the default sequencing: INVSQ_STANDARD -->
- <set from-field="parameters.invoiceId" field="invoiceIdTemp"/>
- <if-empty field="invoiceIdTemp">
- <sequenced-id sequence-name="Invoice" field="invoiceIdTemp"/>
- <else>
- <!-- check the provided ID -->
- <check-id field="invoiceIdTemp"/>
- <check-errors/>
- </else>
- </if-empty>
- </else>
- </if-not-empty>
-
- <!-- use invoiceIdTemp along with the invoiceIdPrefix to create the real ID -->
- <set field="invoiceId" value="${partyAcctgPreference.invoiceIdPrefix}${str:toString(invoiceIdTemp)}"/>
- <field-to-result field="invoiceId" result-name="invoiceId"/>
- </simple-method>
-
- <simple-method method-name="invoiceSequenceEnforced" short-description="Enforced Sequence (no gaps, per organization)">
- <log level="info" message="In createInvoice sequence enum Enforced"/>
- <set field="partyAcctgPreference" from-field="parameters.partyAcctgPreference"/>
- <!-- this is sequential sequencing, we can't skip a number, also it must be a unique sequence per partyIdFrom -->
-
- <if-not-empty field="partyAcctgPreference.lastInvoiceNumber">
- <calculate field="partyAcctgPreference.lastInvoiceNumber" type="Long">
- <calcop operator="add" field="partyAcctgPreference.lastInvoiceNumber"/>
- <number value="1"/>
- </calculate>
- <else>
- <calculate field="partyAcctgPreference.lastInvoiceNumber" type="Long"><number value="1"/></calculate>
- </else>
- </if-not-empty>
- <store-value value-field="partyAcctgPreference"/>
- <set from-field="partyAcctgPreference.lastInvoiceNumber" field="invoiceId"/>
- <field-to-result field="invoiceId" result-name="invoiceId"/>
- </simple-method>
-
- <simple-method method-name="invoiceSequenceRestart" short-description="Restart on Fiscal Year (no gaps, per org, reset to 1 each year)">
- <log level="info" message="In createInvoice sequence enum Restart"/>
- <set field="partyAcctgPreference" from-field="parameters.partyAcctgPreference"/>
- <!-- this is sequential sequencing, we can't skip a number; except that it is restarted each fiscal year -->
-
- <now-timestamp field="nowTimestamp"/>
- <if-empty field="partyAcctgPreference.lastInvoiceRestartDate">
- <!-- if no lastInvoiceRestartDate then it's easy, just start now with 1 -->
- <calculate field="partyAcctgPreference.lastInvoiceNumber" type="Long"><number value="1"/></calculate>
- <set from-field="nowTimestamp" field="partyAcctgPreference.lastInvoiceRestartDate"/>
- <else>
- <!-- first figure out if we need to reset the lastInvoiceNumber; is the lastInvoiceRestartDate after the fiscalYearStartMonth/Day for this year? -->
- <calculate field="zeroLong" type="Long"><number value="0"/></calculate>
- <call-class-method class-name="org.apache.ofbiz.base.util.UtilDateTime" method-name="getYearStart" ret-field="curYearFiscalStartDate">
- <field field="nowTimestamp" type="java.sql.Timestamp"/>
- <field field="partyAcctgPreference.fiscalYearStartDay" type="java.lang.Number"/>
- <field field="partyAcctgPreference.fiscalYearStartMonth" type="java.lang.Number"/>
- <field field="zeroLong" type="java.lang.Number"/>
- </call-class-method>
- <if>
- <condition>
- <and>
- <if-compare-field field="partyAcctgPreference.lastInvoiceRestartDate" to-field="curYearFiscalStartDate" operator="less" type="Timestamp"/>
- <if-compare-field field="nowTimestamp" to-field="curYearFiscalStartDate" operator="greater-equals" type="Timestamp"/>
- </and>
- </condition>
- <then>
- <!-- less than fiscal year start, we need to reset it -->
- <calculate field="partyAcctgPreference.lastInvoiceNumber" type="Long"><number value="1"/></calculate>
- <set from-field="nowTimestamp" field="partyAcctgPreference.lastInvoiceRestartDate"/>
- </then>
- <else>
- <!-- greater than or equal to fiscal year start or nowTimestamp hasn't yet hit the current year fiscal start date, we're okay, just increment -->
- <calculate field="partyAcctgPreference.lastInvoiceNumber" type="Long">
- <calcop operator="add" field="partyAcctgPreference.lastInvoiceNumber"/>
- <number value="1"/>
- </calculate>
- </else>
- </if>
- </else>
- </if-empty>
- <store-value value-field="partyAcctgPreference"/>
-
- <!-- get the current year string for prefix, etc; simple 4 digit year date string (using system defaults) -->
- <set field="curYearString" value="${str:toString(date:year(partyAcctgPreference.lastInvoiceRestartDate, util:defaultTimeZone(), util:defaultLocale()))}"/>
- <set field="invoiceId" value="${curYearString}-${str:toString(partyAcctgPreference.lastInvoiceNumber)}"/>
- <field-to-result field="invoiceId" result-name="invoiceId"/>
- </simple-method>
-
<simple-method method-name="createInvoice" short-description="Create a new Invoice">
<now-timestamp field="nowTimestamp"/>
Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_invoice.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_invoice.xml?rev=1839778&r1=1839777&r2=1839778&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_invoice.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_invoice.xml Fri Aug 31 17:29:55 2018
@@ -25,23 +25,23 @@ under the License.
<version>1.0</version>
- <service name="getNextInvoiceId" engine="simple"
- location="component://accounting/minilang/invoice/InvoiceServices.xml" invoke="getNextInvoiceId">
+ <service name="getNextInvoiceId" engine="groovy"
+ location="component://accounting/groovyScripts/invoice/InvoiceServices.groovy" invoke="getNextInvoiceId">
<description>Get the Next Invoice ID According to Settings on the PartyAcctgPreference Entity for the given Party</description>
<implements service="createInvoice"/>
<attribute name="partyId" type="String" mode="IN" optional="false"/>
<attribute name="invoiceId" type="String" mode="OUT" optional="false"/>
</service>
- <service name="invoiceSequenceEnforced" engine="simple"
- location="component://accounting/minilang/invoice/InvoiceServices.xml" invoke="invoiceSequenceEnforced">
+ <service name="invoiceSequenceEnforced" engine="groovy"
+ location="component://accounting/groovyScripts/invoice/InvoiceServices.groovy" invoke="invoiceSequenceEnforced">
<implements service="getNextInvoiceId"/>
<attribute name="partyAcctgPreference" type="org.apache.ofbiz.entity.GenericValue" mode="IN"/>
<override name="invoiceId" type="Long" mode="OUT"/>
</service>
- <service name="invoiceSequenceRestart" engine="simple"
- location="component://accounting/minilang/invoice/InvoiceServices.xml" invoke="invoiceSequenceRestart">
+ <service name="invoiceSequenceRestart" engine="groovy"
+ location="component://accounting/groovyScripts/invoice/InvoiceServices.groovy" invoke="invoiceSequenceRestart">
<implements service="getNextInvoiceId"/>
<attribute name="partyAcctgPreference" type="org.apache.ofbiz.entity.GenericValue" mode="IN"/>
</service>