Hi Nicolas,
just saw that we had some checks and default values set in the original mini lang service for updateRateAmount which I did not find in the new Grrovy version. Don't we need these checks? Thanks and regards, Michael Brohl ecomify GmbH www.ecomify.de Am 27.05.17 um 18:23 schrieb [hidden email]: > Author: nmalin > Date: Sat May 27 16:23:31 2017 > New Revision: 1796428 > > URL: http://svn.apache.org/viewvc?rev=1796428&view=rev > Log: > Fixed: Convert RateServices.xml mini-lang to groovyDSL (OFBIZ-9381) > related to task OFBIZ-9350 Deprecate Mini Lang, convert service updateRateAmount, deleteRateAmount updatePartyRate and deletePartyRate from mini-ang to groovyDSL > Thanks to Deepak for the review > > Added: > ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/ > ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy (with props) > Modified: > ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/rate/RateServices.xml > ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_rate.xml > > Added: ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy > URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy?rev=1796428&view=auto > ============================================================================== > --- ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy (added) > +++ ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy Sat May 27 16:23:31 2017 > @@ -0,0 +1,121 @@ > +/* > + * 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.UtilDateTime > +import org.apache.ofbiz.base.util.UtilProperties > +import org.apache.ofbiz.base.util.UtilValidate > +import org.apache.ofbiz.entity.GenericValue > +import org.apache.ofbiz.entity.util.EntityUtil > +import org.apache.ofbiz.service.ServiceUtil > + > +import java.sql.Timestamp > + > + > +/** > + * Service to create a rate amount value, if a existing value is present expire it before > + */ > +def updateRateAmount() { > + GenericValue newEntity = delegator.makeValidValue('RateAmount', parameters) > + if (!newEntity.rateCurrencyUomId) { > + newEntity.rateCurrencyUomId = UtilProperties.getPropertyValue('general.properties', 'currency.uom.id.default') > + } > + if (!newEntity.fromDate) newEntity.fromDate = UtilDateTime.getDayStart(UtilDateTime.nowTimestamp()) > + newEntity.thruDate = null > + > + //Check if the entry is already exist with a different rate else expire the older to create the new one > + boolean updating = false > + GenericValue rateAmountLookedUpValue = from('RateAmount').where('rateTypeId', newEntity.rateTypeId, > + 'emplPositionTypeId', newEntity.emplPositionTypeId, > + 'rateCurrencyUomId', newEntity.rateCurrencyUomId, > + 'workEffortId', newEntity.workEffortId, > + 'periodTypeId', newEntity.periodTypeId, > + 'partyId', newEntity.partyId).filterByDate().queryFirst() > + if (rateAmountLookedUpValue) { > + updating = (rateAmountLookedUpValue.fromDate.compareTo(newEntity.fromDate) == 0) > + if (rateAmountLookedUpValue.rateAmount != rateAmount) { > + Map deleteRateAmountMap = dispatcher.getDispatchContext().makeValidContext('deleteRateAmount', 'IN', rateAmountLookedUpValue) > + result = run service: 'deleteRateAmount', with: deleteRateAmountMap > + if (ServiceUtil.isError(result)) return result > + } else { > + return error(UtilProperties.getMessage('AccountingErrorUiLabels', 'AccountingUpdateRateAmountAlreadyExist', locale)) > + } > + } > + if (updating) newEntity.store() > + else newEntity.create() > + return success() > +} > + > +/** > + * Service to expire a rate amount value > + */ > +def deleteRateAmount() { > + GenericValue lookedUpValue = delegator.makeValidValue('RateAmount', parameters) > + if (!lookedUpValue.rateCurrencyUomId) { > + lookedUpValue.rateCurrencyUomId = UtilProperties.getPropertyValue('general.properties', 'currency.uom.id.default') > + } > + lookedUpValue = from('RateAmount').where(lookedUpValue.getFields(lookedUpValue.getModelEntity().getPkFieldNames())).queryOne() > + if (lookedUpValue) { > + Timestamp previousDay = UtilDateTime.adjustTimestamp(UtilDateTime.nowTimestamp(), 5, -1) > + lookedUpValue.thruDate = UtilDateTime.getDayEnd(previousDay) > + lookedUpValue.store() > + } else { > + return error(UtilProperties.getMessage('AccountingErrorUiLabels', 'AccountingDeleteRateAmount', locale)) > + } > + return success() > +} > + > +def updatePartyRate() { > + List<GenericValue> partyRates = from('PartyRate').where([partyId: partyId, rateTypeId: rateTypeId]).queryList() > + if (UtilValidate.isNotEmpty(partyRates)) { > + GenericValue partyRate = EntityUtil.getFirst(partyRates) > + partyRate.thruDate = UtilDateTime.nowTimestamp() > + } > + GenericValue newEntity = delegator.makeValidValue('PartyRate', parameters) > + if (!newEntity.fromDate) newEntity.fromDate = UtilDateTime.nowTimestamp() > + newEntity.create() > + > + //check other default rate to desactive them > + if ('Y' == newEntity.defaultRate) { > + partyRates = from('PartyRate').where([partyId: partyId, defaultRate: 'Y']).queryList() > + partyRates.each { partyDefaultRate -> > + partyDefaultRate.defaultRate = 'N' > + partyDefaultRate.store() > + } > + } > + if (parameters.rateAmount) { > + Map createRateAmountMap = dispatcher.getDispatchContext().makeValidContext('updateRateAmount', 'IN', parameters) > + result = run service: 'updateRateAmount', with: createRateAmountMap > + if (ServiceUtil.isError(result)) return result > + } > + return success() > +} > + > +def deletePartyRate() { > + GenericValue lookedUpValue = from('PartyRate').where([partyId: partyId, rateTypeId: rateTypeId, fromDate: fromDate]).queryOne() > + if (lookedUpValue) { > + lookedUpValue.thruDate = UtilDateTime.nowTimestamp() > + lookedUpValue.store() > + > + //expire related rate amount > + Map deleteRateAmountMap = dispatcher.getDispatchContext().makeValidContext('deleteRateAmount', 'IN', parameters) > + result = run service: 'deleteRateAmount', with: deleteRateAmountMap > + if (ServiceUtil.isError(result)) return result > + } > + return success() > +} > > Propchange: ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy > ------------------------------------------------------------------------------ > svn:eol-style = native > > Propchange: ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy > ------------------------------------------------------------------------------ > svn:keywords = Date Rev Author URL Id > > Propchange: ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy > ------------------------------------------------------------------------------ > svn:mime-type = text/plain > > Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/rate/RateServices.xml > URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/rate/RateServices.xml?rev=1796428&r1=1796427&r2=1796428&view=diff > ============================================================================== > --- ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/rate/RateServices.xml (original) > +++ ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/rate/RateServices.xml Sat May 27 16:23:31 2017 > @@ -21,85 +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="updateRateAmount" short-description="update/create a rate amount value"> > - <!-- set defaults --> > - <if-empty field="parameters.rateCurrencyUomId"> > - <property-to-field resource="general.properties" property="currency.uom.id.default" field="parameters.rateCurrencyUomId"/> > - </if-empty> > - <if-empty field="parameters.periodTypeId"> > - <set field="parameters.periodTypeId" value="RATE_HOUR"/> > - </if-empty> > - <if-empty field="parameters.emplPositionTypeId"> > - <set field="parameters.emplPositionTypeId" value="_NA_"/> > - </if-empty> > - <if-empty field="parameters.partyId"> > - <set field="parameters.partyId" value="_NA_"/> > - </if-empty> > - <if-empty field="parameters.workEffortId"> > - <set field="parameters.workEffortId" value="_NA_"/> > - </if-empty> > - > - <!-- try to find existing value --> > - <entity-and entity-name="RateAmount" list="rateAmounts" filter-by-date="true"> > - <field-map field-name="rateTypeId" from-field="parameters.rateTypeId"/> > - <field-map field-name="workEffortId" from-field="parameters.workEffortId"/> > - <field-map field-name="rateCurrencyUomId" from-field="parameters.rateCurrencyUomId"/> > - <field-map field-name="emplPositionTypeId" from-field="parameters.emplPositionTypeId"/> > - <field-map field-name="partyId" from-field="parameters.partyId"/> > - <field-map field-name="periodTypeId" from-field="parameters.periodTypeId"/> > - </entity-and> > - > - <!-- end existing value --> > - <if-not-empty field="rateAmounts"> > - <first-from-list list="rateAmounts" entry="rateAmount"/> > - <if-compare-field field="rateAmount.rateAmount" operator="not-equals" to-field="parameters.rateAmount"> > - <set-service-fields service-name="deleteRateAmount" map="rateAmount" to-map="delRateAmount"/> > - <call-service service-name="deleteRateAmount" in-map-name="delRateAmount"/> > - </if-compare-field> > - </if-not-empty> > - > - <make-value entity-name="RateAmount" value-field="newEntity"/> > - <set-pk-fields map="parameters" value-field="newEntity"/> > - <set-nonpk-fields map="parameters" value-field="newEntity"/> > - <if-empty field="newEntity.fromDate"><now-timestamp field="newEntity.fromDate"/></if-empty> > - <clear-field field="newEntity.thruDate"/> > - <create-value value-field="newEntity"/> > - </simple-method> > - > - <simple-method method-name="deleteRateAmount" short-description="update/create a rate amount value"> > - <!-- set defaults --> > - <if-empty field="parameters.rateCurrencyUomId"> > - <property-to-field resource="general.properties" property="currency.uom.id.default" field="parameters.rateCurrencyUomId"/> > - </if-empty> > - <if-empty field="parameters.periodTypeId"> > - <set field="parameters.periodTypeId" value="RATE_HOUR"/> > - </if-empty> > - <if-empty field="parameters.emplPositionTypeId"> > - <set field="parameters.emplPositionTypeId" value="_NA_"/> > - </if-empty> > - <if-empty field="parameters.partyId"> > - <set field="parameters.partyId" value="_NA_"/> > - </if-empty> > - <if-empty field="parameters.workEffortId"> > - <set field="parameters.workEffortId" value="_NA_"/> > - </if-empty> > - > - <entity-one entity-name="RateAmount" value-field="rateAmount"/> > - > - <if-not-empty field="rateAmount"> > - <now-timestamp field="nowTimestamp"/> > - <set field ="previousDay" value="${groovy: org.apache.ofbiz.base.util.UtilDateTime.adjustTimestamp(nowTimestamp,5,-1)}" type="Timestamp"/> > - <set field="rateAmount.thruDate" value="${groovy: org.apache.ofbiz.base.util.UtilDateTime.getDayEnd(previousDay)}" type="Timestamp"/> > - <store-value value-field="rateAmount"/> > - <else> > - <add-error> > - <fail-property resource="AccountingErrorUiLabels" property="AccountingDeleteRateAmount"/> > - </add-error> > - </else> > - </if-not-empty> > - > - </simple-method> > - > <simple-method method-name="getRateAmount" short-description="Get the applicable rate amount value"> > <!-- > Search for the applicable rate from most specific to most general in the RateAmount entity > @@ -333,57 +254,4 @@ under the License. > <field-to-result field="parameters.ratesList" result-name="filteredRatesList"/> > </simple-method> > > - <!-- party rate services --> > - <simple-method method-name="updatePartyRate" short-description="Update/Create PartyRate"> > - <!-- check if already exist is so expire current record --> > - <entity-and entity-name="PartyRate" list="partyRates" filter-by-date="true"> > - <field-map field-name="partyId" from-field="parameters.partyId"/> > - <field-map field-name="rateTypeId" from-field="parameters.rateTypeId"/> > - </entity-and> > - <if-not-empty field="partyRates"> > - <first-from-list list="partyRates" entry="partyRate"/> > - <now-timestamp field="partyRate.thruDate"/> > - <store-value value-field="partyRate"/> > - </if-not-empty> > - > - <make-value value-field="newEntity" entity-name="PartyRate"/> > - <set-pk-fields map="parameters" value-field="newEntity"/> > - <if-empty field="newEntity.fromDate"><now-timestamp field="newEntity.fromDate"/></if-empty> > - <set-nonpk-fields map="parameters" value-field="newEntity"/> > - <call-simple-method method-name="checkOtherDefaultRate"/> > - <create-value value-field="newEntity"/> > - > - <if-not-empty field="parameters.rateAmount"> > - <set-service-fields service-name="updateRateAmount" map="parameters" to-map="updRate"/> > - <call-service service-name="updateRateAmount" in-map-name="updRate"/> > - </if-not-empty> > - </simple-method> > - > - <simple-method method-name="checkOtherDefaultRate" short-description="remove an other defaultRate flag"> > - <set value="_CREATE" field="securityAction"/> > - <check-permission permission="ACCOUNTING" action="${securityAction}"> > - <fail-property resource="AccountingUiLabels" property="AccountingPermissionError"/> > - </check-permission> > - <check-errors/> > - <if-compare field="newEntity.defaultRate" value="Y" operator="equals"> > - <entity-and entity-name="PartyRate" list="rates" filter-by-date="true"> > - <field-map field-name="partyId" from-field="newEntity.partyId"/> > - <field-map field-name="defaultRate" value="Y"/> > - </entity-and> > - <if-not-empty field="rates"> > - <first-from-list list="rates" entry="rate"/> > - <set field="rate.defaultRate" value="N"/> > - <store-value value-field="rate"/> > - </if-not-empty> > - </if-compare> > - </simple-method> > - <simple-method method-name="deletePartyRate" short-description="Delete PartyRate"> > - <entity-one entity-name="PartyRate" value-field="lookedUpValue"/> > - <now-timestamp field="lookedUpValue.thruDate"/> > - <store-value value-field="lookedUpValue"/> > - > - <set-service-fields service-name="deleteRateAmount" map="parameters" to-map="delRateAmount"/> > - <set field="delRateAmount.fromDate" from-field="parameters.rateAmountFromDate"/> > - <call-service service-name="deleteRateAmount" in-map-name="delRateAmount"/> > - </simple-method> > </simple-methods> > > Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_rate.xml > URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_rate.xml?rev=1796428&r1=1796427&r2=1796428&view=diff > ============================================================================== > --- ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_rate.xml (original) > +++ ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_rate.xml Sat May 27 16:23:31 2017 > @@ -24,21 +24,29 @@ under the License. > <vendor>OFBiz</vendor> > <version>1.0</version> > > - <service name="updateRateAmount" default-entity-name="RateAmount" engine="simple" auth="true" > - location="component://accounting/minilang/rate/RateServices.xml" invoke="updateRateAmount"> > + <service name="updateRateAmount" default-entity-name="RateAmount" engine="groovy" auth="true" > + location="component://accounting/groovyScripts/rate/RateServices.groovy" invoke="updateRateAmount"> > <description>Create/update Rate Amount</description> > <permission-service service-name="acctgBasePermissionCheck" main-action="CREATE"/> > <auto-attributes include="all" mode="IN" optional="true"/> > <override name="rateTypeId" optional="false"/> > <override name="rateAmount" optional="false"/> > - </service> > - <service name="deleteRateAmount" default-entity-name="RateAmount" engine="simple" auth="true" > - location="component://accounting/minilang/rate/RateServices.xml" invoke="deleteRateAmount"> > - <description>Delete (expire) Rate Amount</description> > + <override name="emplPositionTypeId" default-value="_NA_"/> > + <override name="workEffortId" default-value="_NA_"/> > + <override name="periodTypeId" default-value="RATE_HOUR"/> > + <override name="partyId" default-value="_NA_"/> > + </service> > + <service name="deleteRateAmount" default-entity-name="RateAmount" engine="groovy" auth="true" > + location="component://accounting/groovyScripts/rate/RateServices.groovy" invoke="deleteRateAmount"> > + <description>expire Rate Amount</description> > <permission-service service-name="acctgBasePermissionCheck" main-action="CREATE"/> > <auto-attributes include="pk" mode="IN" optional="true"/> > <override name="rateTypeId" optional="false"/> > <override name="fromDate" optional="false"/> > + <override name="emplPositionTypeId" default-value="_NA_"/> > + <override name="workEffortId" default-value="_NA_"/> > + <override name="periodTypeId" default-value="RATE_HOUR"/> > + <override name="partyId" default-value="_NA_"/> > </service> > <service name="getRateAmount" default-entity-name="RateAmount" engine="simple" auth="true" > location="component://accounting/minilang/rate/RateServices.xml" invoke="getRateAmount"> > @@ -96,8 +104,8 @@ under the License. > </service> > > <!-- PartyRate Services --> > - <service name="updatePartyRate" default-entity-name="PartyRate" engine="simple" auth="true" > - location="component://accounting/minilang/rate/RateServices.xml" invoke="updatePartyRate"> > + <service name="updatePartyRate" default-entity-name="PartyRate" engine="groovy" auth="true" > + location="component://accounting/groovyScripts/rate/RateServices.groovy" invoke="updatePartyRate"> > <description>Creates PartyRate</description> > <permission-service service-name="acctgBasePermissionCheck" main-action="CREATE"/> > <auto-attributes include="pk" mode="IN" optional="false"/> > @@ -108,9 +116,9 @@ under the License. > <attribute name="periodTypeId" type="String" mode="IN"/> > <override name="fromDate" optional="true"/> > </service> > - <service name="deletePartyRate" default-entity-name="PartyRate" engine="simple" auth="true" > - location="component://accounting/minilang/rate/RateServices.xml" invoke="deletePartyRate"> > - <description>Deletes PartyRate</description> > + <service name="deletePartyRate" default-entity-name="PartyRate" engine="groovy" auth="true" > + location="component://accounting/groovyScripts/rate/RateServices.groovy" invoke="deletePartyRate"> > + <description>Expire PartyRate and expire related rateAmount</description> > <permission-service service-name="acctgBasePermissionCheck" main-action="UPDATE"/> > <auto-attributes include="pk" mode="IN" optional="false"/> > <attribute name="rateAmountFromDate" type="Timestamp" mode="IN" optional="true"/><!-- to be able to expire rateamount specific to a party records....--> > > smime.p7s (5K) Download Attachment |
Hi Michael,
Those default values moved to service definition instead of implementation. We have feature to pass default value at service definition level. {code} + <override name="emplPositionTypeId" default-value="_NA_"/> + <override name="workEffortId" default-value="_NA_"/> + <override name="periodTypeId" default-value="RATE_HOUR"/> + <override name="partyId" default-value="_NA_"/> {code} Thanks & Regards -- Deepak Dixit www.hotwaxsystems.com On Sun, May 28, 2017 at 4:19 PM, Michael Brohl <[hidden email]> wrote: > Hi Nicolas, > > just saw that we had some checks and default values set in the original > mini lang service for updateRateAmount which I did not find in the new > Grrovy version. > > Don't we need these checks? > > Thanks and regards, > > Michael Brohl > ecomify GmbH > www.ecomify.de > > > Am 27.05.17 um 18:23 schrieb [hidden email]: > > Author: nmalin >> Date: Sat May 27 16:23:31 2017 >> New Revision: 1796428 >> >> URL: http://svn.apache.org/viewvc?rev=1796428&view=rev >> Log: >> Fixed: Convert RateServices.xml mini-lang to groovyDSL (OFBIZ-9381) >> related to task OFBIZ-9350 Deprecate Mini Lang, convert service >> updateRateAmount, deleteRateAmount updatePartyRate and deletePartyRate from >> mini-ang to groovyDSL >> Thanks to Deepak for the review >> >> Added: >> ofbiz/ofbiz-framework/trunk/applications/accounting/groovyS >> cripts/rate/ >> ofbiz/ofbiz-framework/trunk/applications/accounting/groovyS >> cripts/rate/RateServices.groovy (with props) >> Modified: >> ofbiz/ofbiz-framework/trunk/applications/accounting/minilan >> g/rate/RateServices.xml >> ofbiz/ofbiz-framework/trunk/applications/accounting/service >> def/services_rate.xml >> >> Added: ofbiz/ofbiz-framework/trunk/applications/accounting/groovySc >> ripts/rate/RateServices.groovy >> URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/app >> lications/accounting/groovyScripts/rate/RateServices.groovy? >> rev=1796428&view=auto >> ============================================================ >> ================== >> --- ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy >> (added) >> +++ ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy >> Sat May 27 16:23:31 2017 >> @@ -0,0 +1,121 @@ >> +/* >> + * 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.UtilDateTime >> +import org.apache.ofbiz.base.util.UtilProperties >> +import org.apache.ofbiz.base.util.UtilValidate >> +import org.apache.ofbiz.entity.GenericValue >> +import org.apache.ofbiz.entity.util.EntityUtil >> +import org.apache.ofbiz.service.ServiceUtil >> + >> +import java.sql.Timestamp >> + >> + >> +/** >> + * Service to create a rate amount value, if a existing value is present >> expire it before >> + */ >> +def updateRateAmount() { >> + GenericValue newEntity = delegator.makeValidValue('RateAmount', >> parameters) >> + if (!newEntity.rateCurrencyUomId) { >> + newEntity.rateCurrencyUomId = UtilProperties.getPropertyValue('general.properties', >> 'currency.uom.id.default') >> + } >> + if (!newEntity.fromDate) newEntity.fromDate = >> UtilDateTime.getDayStart(UtilDateTime.nowTimestamp()) >> + newEntity.thruDate = null >> + >> + //Check if the entry is already exist with a different rate else >> expire the older to create the new one >> + boolean updating = false >> + GenericValue rateAmountLookedUpValue = from('RateAmount').where('rateTypeId', >> newEntity.rateTypeId, >> + 'emplPositionTypeId', newEntity.emplPositionTypeId, >> + 'rateCurrencyUomId', newEntity.rateCurrencyUomId, >> + 'workEffortId', newEntity.workEffortId, >> + 'periodTypeId', newEntity.periodTypeId, >> + 'partyId', newEntity.partyId).filterByDate().queryFirst() >> + if (rateAmountLookedUpValue) { >> + updating = (rateAmountLookedUpValue.fromD >> ate.compareTo(newEntity.fromDate) == 0) >> + if (rateAmountLookedUpValue.rateAmount != rateAmount) { >> + Map deleteRateAmountMap = dispatcher.getDispatchContext( >> ).makeValidContext('deleteRateAmount', 'IN', rateAmountLookedUpValue) >> + result = run service: 'deleteRateAmount', with: >> deleteRateAmountMap >> + if (ServiceUtil.isError(result)) return result >> + } else { >> + return error(UtilProperties.getMessage('AccountingErrorUiLabels', >> 'AccountingUpdateRateAmountAlreadyExist', locale)) >> + } >> + } >> + if (updating) newEntity.store() >> + else newEntity.create() >> + return success() >> +} >> + >> +/** >> + * Service to expire a rate amount value >> + */ >> +def deleteRateAmount() { >> + GenericValue lookedUpValue = delegator.makeValidValue('RateAmount', >> parameters) >> + if (!lookedUpValue.rateCurrencyUomId) { >> + lookedUpValue.rateCurrencyUomId = UtilProperties.getPropertyValue('general.properties', >> 'currency.uom.id.default') >> + } >> + lookedUpValue = from('RateAmount').where(looke >> dUpValue.getFields(lookedUpValue.getModelEntity(). >> getPkFieldNames())).queryOne() >> + if (lookedUpValue) { >> + Timestamp previousDay = UtilDateTime.adjustTimestamp(UtilDateTime.nowTimestamp(), >> 5, -1) >> + lookedUpValue.thruDate = UtilDateTime.getDayEnd(previousDay) >> + lookedUpValue.store() >> + } else { >> + return error(UtilProperties.getMessage('AccountingErrorUiLabels', >> 'AccountingDeleteRateAmount', locale)) >> + } >> + return success() >> +} >> + >> +def updatePartyRate() { >> + List<GenericValue> partyRates = from('PartyRate').where([partyId: >> partyId, rateTypeId: rateTypeId]).queryList() >> + if (UtilValidate.isNotEmpty(partyRates)) { >> + GenericValue partyRate = EntityUtil.getFirst(partyRates) >> + partyRate.thruDate = UtilDateTime.nowTimestamp() >> + } >> + GenericValue newEntity = delegator.makeValidValue('PartyRate', >> parameters) >> + if (!newEntity.fromDate) newEntity.fromDate = >> UtilDateTime.nowTimestamp() >> + newEntity.create() >> + >> + //check other default rate to desactive them >> + if ('Y' == newEntity.defaultRate) { >> + partyRates = from('PartyRate').where([partyId: partyId, >> defaultRate: 'Y']).queryList() >> + partyRates.each { partyDefaultRate -> >> + partyDefaultRate.defaultRate = 'N' >> + partyDefaultRate.store() >> + } >> + } >> + if (parameters.rateAmount) { >> + Map createRateAmountMap = dispatcher.getDispatchContext( >> ).makeValidContext('updateRateAmount', 'IN', parameters) >> + result = run service: 'updateRateAmount', with: >> createRateAmountMap >> + if (ServiceUtil.isError(result)) return result >> + } >> + return success() >> +} >> + >> +def deletePartyRate() { >> + GenericValue lookedUpValue = from('PartyRate').where([partyId: >> partyId, rateTypeId: rateTypeId, fromDate: fromDate]).queryOne() >> + if (lookedUpValue) { >> + lookedUpValue.thruDate = UtilDateTime.nowTimestamp() >> + lookedUpValue.store() >> + >> + //expire related rate amount >> + Map deleteRateAmountMap = dispatcher.getDispatchContext( >> ).makeValidContext('deleteRateAmount', 'IN', parameters) >> + result = run service: 'deleteRateAmount', with: >> deleteRateAmountMap >> + if (ServiceUtil.isError(result)) return result >> + } >> + return success() >> +} >> >> Propchange: ofbiz/ofbiz-framework/trunk/applications/accounting/groovySc >> ripts/rate/RateServices.groovy >> ------------------------------------------------------------ >> ------------------ >> svn:eol-style = native >> >> Propchange: ofbiz/ofbiz-framework/trunk/applications/accounting/groovySc >> ripts/rate/RateServices.groovy >> ------------------------------------------------------------ >> ------------------ >> svn:keywords = Date Rev Author URL Id >> >> Propchange: ofbiz/ofbiz-framework/trunk/applications/accounting/groovySc >> ripts/rate/RateServices.groovy >> ------------------------------------------------------------ >> ------------------ >> svn:mime-type = text/plain >> >> Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/minilang >> /rate/RateServices.xml >> URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/app >> lications/accounting/minilang/rate/RateServices.xml?rev= >> 1796428&r1=1796427&r2=1796428&view=diff >> ============================================================ >> ================== >> --- ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/rate/RateServices.xml >> (original) >> +++ ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/rate/RateServices.xml >> Sat May 27 16:23:31 2017 >> @@ -21,85 +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="updateRateAmount" >> short-description="update/create a rate amount value"> >> - <!-- set defaults --> >> - <if-empty field="parameters.rateCurrencyUomId"> >> - <property-to-field resource="general.properties" property=" >> currency.uom.id.default" field="parameters.rateCurrencyUomId"/> >> - </if-empty> >> - <if-empty field="parameters.periodTypeId"> >> - <set field="parameters.periodTypeId" value="RATE_HOUR"/> >> - </if-empty> >> - <if-empty field="parameters.emplPositionTypeId"> >> - <set field="parameters.emplPositionTypeId" value="_NA_"/> >> - </if-empty> >> - <if-empty field="parameters.partyId"> >> - <set field="parameters.partyId" value="_NA_"/> >> - </if-empty> >> - <if-empty field="parameters.workEffortId"> >> - <set field="parameters.workEffortId" value="_NA_"/> >> - </if-empty> >> - >> - <!-- try to find existing value --> >> - <entity-and entity-name="RateAmount" list="rateAmounts" >> filter-by-date="true"> >> - <field-map field-name="rateTypeId" >> from-field="parameters.rateTypeId"/> >> - <field-map field-name="workEffortId" >> from-field="parameters.workEffortId"/> >> - <field-map field-name="rateCurrencyUomId" >> from-field="parameters.rateCurrencyUomId"/> >> - <field-map field-name="emplPositionTypeId" >> from-field="parameters.emplPositionTypeId"/> >> - <field-map field-name="partyId" >> from-field="parameters.partyId"/> >> - <field-map field-name="periodTypeId" >> from-field="parameters.periodTypeId"/> >> - </entity-and> >> - >> - <!-- end existing value --> >> - <if-not-empty field="rateAmounts"> >> - <first-from-list list="rateAmounts" entry="rateAmount"/> >> - <if-compare-field field="rateAmount.rateAmount" >> operator="not-equals" to-field="parameters.rateAmount"> >> - <set-service-fields service-name="deleteRateAmount" >> map="rateAmount" to-map="delRateAmount"/> >> - <call-service service-name="deleteRateAmount" >> in-map-name="delRateAmount"/> >> - </if-compare-field> >> - </if-not-empty> >> - >> - <make-value entity-name="RateAmount" value-field="newEntity"/> >> - <set-pk-fields map="parameters" value-field="newEntity"/> >> - <set-nonpk-fields map="parameters" value-field="newEntity"/> >> - <if-empty field="newEntity.fromDate"><now-timestamp >> field="newEntity.fromDate"/></if-empty> >> - <clear-field field="newEntity.thruDate"/> >> - <create-value value-field="newEntity"/> >> - </simple-method> >> - >> - <simple-method method-name="deleteRateAmount" >> short-description="update/create a rate amount value"> >> - <!-- set defaults --> >> - <if-empty field="parameters.rateCurrencyUomId"> >> - <property-to-field resource="general.properties" property=" >> currency.uom.id.default" field="parameters.rateCurrencyUomId"/> >> - </if-empty> >> - <if-empty field="parameters.periodTypeId"> >> - <set field="parameters.periodTypeId" value="RATE_HOUR"/> >> - </if-empty> >> - <if-empty field="parameters.emplPositionTypeId"> >> - <set field="parameters.emplPositionTypeId" value="_NA_"/> >> - </if-empty> >> - <if-empty field="parameters.partyId"> >> - <set field="parameters.partyId" value="_NA_"/> >> - </if-empty> >> - <if-empty field="parameters.workEffortId"> >> - <set field="parameters.workEffortId" value="_NA_"/> >> - </if-empty> >> - >> - <entity-one entity-name="RateAmount" value-field="rateAmount"/> >> - >> - <if-not-empty field="rateAmount"> >> - <now-timestamp field="nowTimestamp"/> >> - <set field ="previousDay" value="${groovy: >> org.apache.ofbiz.base.util.UtilDateTime.adjustTimestamp(nowTimestamp,5,-1)}" >> type="Timestamp"/> >> - <set field="rateAmount.thruDate" value="${groovy: >> org.apache.ofbiz.base.util.UtilDateTime.getDayEnd(previousDay)}" >> type="Timestamp"/> >> - <store-value value-field="rateAmount"/> >> - <else> >> - <add-error> >> - <fail-property resource="AccountingErrorUiLabels" >> property="AccountingDeleteRateAmount"/> >> - </add-error> >> - </else> >> - </if-not-empty> >> - >> - </simple-method> >> - >> <simple-method method-name="getRateAmount" short-description="Get >> the applicable rate amount value"> >> <!-- >> Search for the applicable rate from most specific to most >> general in the RateAmount entity >> @@ -333,57 +254,4 @@ under the License. >> <field-to-result field="parameters.ratesList" >> result-name="filteredRatesList"/> >> </simple-method> >> - <!-- party rate services --> >> - <simple-method method-name="updatePartyRate" >> short-description="Update/Create PartyRate"> >> - <!-- check if already exist is so expire current record --> >> - <entity-and entity-name="PartyRate" list="partyRates" >> filter-by-date="true"> >> - <field-map field-name="partyId" >> from-field="parameters.partyId"/> >> - <field-map field-name="rateTypeId" >> from-field="parameters.rateTypeId"/> >> - </entity-and> >> - <if-not-empty field="partyRates"> >> - <first-from-list list="partyRates" entry="partyRate"/> >> - <now-timestamp field="partyRate.thruDate"/> >> - <store-value value-field="partyRate"/> >> - </if-not-empty> >> - >> - <make-value value-field="newEntity" entity-name="PartyRate"/> >> - <set-pk-fields map="parameters" value-field="newEntity"/> >> - <if-empty field="newEntity.fromDate"><now-timestamp >> field="newEntity.fromDate"/></if-empty> >> - <set-nonpk-fields map="parameters" value-field="newEntity"/> >> - <call-simple-method method-name="checkOtherDefaultRate"/> >> - <create-value value-field="newEntity"/> >> - >> - <if-not-empty field="parameters.rateAmount"> >> - <set-service-fields service-name="updateRateAmount" >> map="parameters" to-map="updRate"/> >> - <call-service service-name="updateRateAmount" >> in-map-name="updRate"/> >> - </if-not-empty> >> - </simple-method> >> - >> - <simple-method method-name="checkOtherDefaultRate" >> short-description="remove an other defaultRate flag"> >> - <set value="_CREATE" field="securityAction"/> >> - <check-permission permission="ACCOUNTING" >> action="${securityAction}"> >> - <fail-property resource="AccountingUiLabels" >> property="AccountingPermissionError"/> >> - </check-permission> >> - <check-errors/> >> - <if-compare field="newEntity.defaultRate" value="Y" >> operator="equals"> >> - <entity-and entity-name="PartyRate" list="rates" >> filter-by-date="true"> >> - <field-map field-name="partyId" >> from-field="newEntity.partyId"/> >> - <field-map field-name="defaultRate" value="Y"/> >> - </entity-and> >> - <if-not-empty field="rates"> >> - <first-from-list list="rates" entry="rate"/> >> - <set field="rate.defaultRate" value="N"/> >> - <store-value value-field="rate"/> >> - </if-not-empty> >> - </if-compare> >> - </simple-method> >> - <simple-method method-name="deletePartyRate" >> short-description="Delete PartyRate"> >> - <entity-one entity-name="PartyRate" value-field="lookedUpValue"/> >> - <now-timestamp field="lookedUpValue.thruDate"/> >> - <store-value value-field="lookedUpValue"/> >> - >> - <set-service-fields service-name="deleteRateAmount" >> map="parameters" to-map="delRateAmount"/> >> - <set field="delRateAmount.fromDate" >> from-field="parameters.rateAmountFromDate"/> >> - <call-service service-name="deleteRateAmount" >> in-map-name="delRateAmount"/> >> - </simple-method> >> </simple-methods> >> >> Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/serviced >> ef/services_rate.xml >> URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/app >> lications/accounting/servicedef/services_rate.xml?rev= >> 1796428&r1=1796427&r2=1796428&view=diff >> ============================================================ >> ================== >> --- ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_rate.xml >> (original) >> +++ ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_rate.xml >> Sat May 27 16:23:31 2017 >> @@ -24,21 +24,29 @@ under the License. >> <vendor>OFBiz</vendor> >> <version>1.0</version> >> - <service name="updateRateAmount" default-entity-name="RateAmount" >> engine="simple" auth="true" >> - location="component://accounting/minilang/rate/RateServices.xml" >> invoke="updateRateAmount"> >> + <service name="updateRateAmount" default-entity-name="RateAmount" >> engine="groovy" auth="true" >> + location="component://accounting/groovyScripts/rate/RateServices.groovy" >> invoke="updateRateAmount"> >> <description>Create/update Rate Amount</description> >> <permission-service service-name="acctgBasePermissionCheck" >> main-action="CREATE"/> >> <auto-attributes include="all" mode="IN" optional="true"/> >> <override name="rateTypeId" optional="false"/> >> <override name="rateAmount" optional="false"/> >> - </service> >> - <service name="deleteRateAmount" default-entity-name="RateAmount" >> engine="simple" auth="true" >> - location="component://accounting/minilang/rate/RateServices.xml" >> invoke="deleteRateAmount"> >> - <description>Delete (expire) Rate Amount</description> >> + <override name="emplPositionTypeId" default-value="_NA_"/> >> + <override name="workEffortId" default-value="_NA_"/> >> + <override name="periodTypeId" default-value="RATE_HOUR"/> >> + <override name="partyId" default-value="_NA_"/> >> + </service> >> + <service name="deleteRateAmount" default-entity-name="RateAmount" >> engine="groovy" auth="true" >> + location="component://accounting/groovyScripts/rate/RateServices.groovy" >> invoke="deleteRateAmount"> >> + <description>expire Rate Amount</description> >> <permission-service service-name="acctgBasePermissionCheck" >> main-action="CREATE"/> >> <auto-attributes include="pk" mode="IN" optional="true"/> >> <override name="rateTypeId" optional="false"/> >> <override name="fromDate" optional="false"/> >> + <override name="emplPositionTypeId" default-value="_NA_"/> >> + <override name="workEffortId" default-value="_NA_"/> >> + <override name="periodTypeId" default-value="RATE_HOUR"/> >> + <override name="partyId" default-value="_NA_"/> >> </service> >> <service name="getRateAmount" default-entity-name="RateAmount" >> engine="simple" auth="true" >> location="component://accounting/minilang/rate/RateServices.xml" >> invoke="getRateAmount"> >> @@ -96,8 +104,8 @@ under the License. >> </service> >> <!-- PartyRate Services --> >> - <service name="updatePartyRate" default-entity-name="PartyRate" >> engine="simple" auth="true" >> - location="component://accounting/minilang/rate/RateServices.xml" >> invoke="updatePartyRate"> >> + <service name="updatePartyRate" default-entity-name="PartyRate" >> engine="groovy" auth="true" >> + location="component://accounting/groovyScripts/rate/RateServices.groovy" >> invoke="updatePartyRate"> >> <description>Creates PartyRate</description> >> <permission-service service-name="acctgBasePermissionCheck" >> main-action="CREATE"/> >> <auto-attributes include="pk" mode="IN" optional="false"/> >> @@ -108,9 +116,9 @@ under the License. >> <attribute name="periodTypeId" type="String" mode="IN"/> >> <override name="fromDate" optional="true"/> >> </service> >> - <service name="deletePartyRate" default-entity-name="PartyRate" >> engine="simple" auth="true" >> - location="component://accounting/minilang/rate/RateServices.xml" >> invoke="deletePartyRate"> >> - <description>Deletes PartyRate</description> >> + <service name="deletePartyRate" default-entity-name="PartyRate" >> engine="groovy" auth="true" >> + location="component://accounting/groovyScripts/rate/RateServices.groovy" >> invoke="deletePartyRate"> >> + <description>Expire PartyRate and expire related >> rateAmount</description> >> <permission-service service-name="acctgBasePermissionCheck" >> main-action="UPDATE"/> >> <auto-attributes include="pk" mode="IN" optional="false"/> >> <attribute name="rateAmountFromDate" type="Timestamp" mode="IN" >> optional="true"/><!-- to be able to expire rateamount specific to a party >> records....--> >> >> >> > > |
Deepak is more faster than me :)
This service have some integration test so don't worries the code work well and thanks for the double check Michael. Nicolas Le 29/05/2017 à 08:43, Deepak Dixit a écrit : > Hi Michael, > > Those default values moved to service definition instead of implementation. > We have feature to pass default value at service definition level. > > {code} > + <override name="emplPositionTypeId" default-value="_NA_"/> > + <override name="workEffortId" default-value="_NA_"/> > + <override name="periodTypeId" default-value="RATE_HOUR"/> > + <override name="partyId" default-value="_NA_"/> > {code} > > > Thanks & Regards > -- > Deepak Dixit > www.hotwaxsystems.com > > On Sun, May 28, 2017 at 4:19 PM, Michael Brohl <[hidden email]> > wrote: > >> Hi Nicolas, >> >> just saw that we had some checks and default values set in the original >> mini lang service for updateRateAmount which I did not find in the new >> Grrovy version. >> >> Don't we need these checks? >> >> Thanks and regards, >> >> Michael Brohl >> ecomify GmbH >> www.ecomify.de >> >> >> Am 27.05.17 um 18:23 schrieb [hidden email]: >> >> Author: nmalin >>> Date: Sat May 27 16:23:31 2017 >>> New Revision: 1796428 >>> >>> URL: http://svn.apache.org/viewvc?rev=1796428&view=rev >>> Log: >>> Fixed: Convert RateServices.xml mini-lang to groovyDSL (OFBIZ-9381) >>> related to task OFBIZ-9350 Deprecate Mini Lang, convert service >>> updateRateAmount, deleteRateAmount updatePartyRate and deletePartyRate from >>> mini-ang to groovyDSL >>> Thanks to Deepak for the review >>> >>> Added: >>> ofbiz/ofbiz-framework/trunk/applications/accounting/groovyS >>> cripts/rate/ >>> ofbiz/ofbiz-framework/trunk/applications/accounting/groovyS >>> cripts/rate/RateServices.groovy (with props) >>> Modified: >>> ofbiz/ofbiz-framework/trunk/applications/accounting/minilan >>> g/rate/RateServices.xml >>> ofbiz/ofbiz-framework/trunk/applications/accounting/service >>> def/services_rate.xml >>> >>> Added: ofbiz/ofbiz-framework/trunk/applications/accounting/groovySc >>> ripts/rate/RateServices.groovy >>> URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/app >>> lications/accounting/groovyScripts/rate/RateServices.groovy? >>> rev=1796428&view=auto >>> ============================================================ >>> ================== >>> --- ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy >>> (added) >>> +++ ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy >>> Sat May 27 16:23:31 2017 >>> @@ -0,0 +1,121 @@ >>> +/* >>> + * 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.UtilDateTime >>> +import org.apache.ofbiz.base.util.UtilProperties >>> +import org.apache.ofbiz.base.util.UtilValidate >>> +import org.apache.ofbiz.entity.GenericValue >>> +import org.apache.ofbiz.entity.util.EntityUtil >>> +import org.apache.ofbiz.service.ServiceUtil >>> + >>> +import java.sql.Timestamp >>> + >>> + >>> +/** >>> + * Service to create a rate amount value, if a existing value is present >>> expire it before >>> + */ >>> +def updateRateAmount() { >>> + GenericValue newEntity = delegator.makeValidValue('RateAmount', >>> parameters) >>> + if (!newEntity.rateCurrencyUomId) { >>> + newEntity.rateCurrencyUomId = UtilProperties.getPropertyValue('general.properties', >>> 'currency.uom.id.default') >>> + } >>> + if (!newEntity.fromDate) newEntity.fromDate = >>> UtilDateTime.getDayStart(UtilDateTime.nowTimestamp()) >>> + newEntity.thruDate = null >>> + >>> + //Check if the entry is already exist with a different rate else >>> expire the older to create the new one >>> + boolean updating = false >>> + GenericValue rateAmountLookedUpValue = from('RateAmount').where('rateTypeId', >>> newEntity.rateTypeId, >>> + 'emplPositionTypeId', newEntity.emplPositionTypeId, >>> + 'rateCurrencyUomId', newEntity.rateCurrencyUomId, >>> + 'workEffortId', newEntity.workEffortId, >>> + 'periodTypeId', newEntity.periodTypeId, >>> + 'partyId', newEntity.partyId).filterByDate().queryFirst() >>> + if (rateAmountLookedUpValue) { >>> + updating = (rateAmountLookedUpValue.fromD >>> ate.compareTo(newEntity.fromDate) == 0) >>> + if (rateAmountLookedUpValue.rateAmount != rateAmount) { >>> + Map deleteRateAmountMap = dispatcher.getDispatchContext( >>> ).makeValidContext('deleteRateAmount', 'IN', rateAmountLookedUpValue) >>> + result = run service: 'deleteRateAmount', with: >>> deleteRateAmountMap >>> + if (ServiceUtil.isError(result)) return result >>> + } else { >>> + return error(UtilProperties.getMessage('AccountingErrorUiLabels', >>> 'AccountingUpdateRateAmountAlreadyExist', locale)) >>> + } >>> + } >>> + if (updating) newEntity.store() >>> + else newEntity.create() >>> + return success() >>> +} >>> + >>> +/** >>> + * Service to expire a rate amount value >>> + */ >>> +def deleteRateAmount() { >>> + GenericValue lookedUpValue = delegator.makeValidValue('RateAmount', >>> parameters) >>> + if (!lookedUpValue.rateCurrencyUomId) { >>> + lookedUpValue.rateCurrencyUomId = UtilProperties.getPropertyValue('general.properties', >>> 'currency.uom.id.default') >>> + } >>> + lookedUpValue = from('RateAmount').where(looke >>> dUpValue.getFields(lookedUpValue.getModelEntity(). >>> getPkFieldNames())).queryOne() >>> + if (lookedUpValue) { >>> + Timestamp previousDay = UtilDateTime.adjustTimestamp(UtilDateTime.nowTimestamp(), >>> 5, -1) >>> + lookedUpValue.thruDate = UtilDateTime.getDayEnd(previousDay) >>> + lookedUpValue.store() >>> + } else { >>> + return error(UtilProperties.getMessage('AccountingErrorUiLabels', >>> 'AccountingDeleteRateAmount', locale)) >>> + } >>> + return success() >>> +} >>> + >>> +def updatePartyRate() { >>> + List<GenericValue> partyRates = from('PartyRate').where([partyId: >>> partyId, rateTypeId: rateTypeId]).queryList() >>> + if (UtilValidate.isNotEmpty(partyRates)) { >>> + GenericValue partyRate = EntityUtil.getFirst(partyRates) >>> + partyRate.thruDate = UtilDateTime.nowTimestamp() >>> + } >>> + GenericValue newEntity = delegator.makeValidValue('PartyRate', >>> parameters) >>> + if (!newEntity.fromDate) newEntity.fromDate = >>> UtilDateTime.nowTimestamp() >>> + newEntity.create() >>> + >>> + //check other default rate to desactive them >>> + if ('Y' == newEntity.defaultRate) { >>> + partyRates = from('PartyRate').where([partyId: partyId, >>> defaultRate: 'Y']).queryList() >>> + partyRates.each { partyDefaultRate -> >>> + partyDefaultRate.defaultRate = 'N' >>> + partyDefaultRate.store() >>> + } >>> + } >>> + if (parameters.rateAmount) { >>> + Map createRateAmountMap = dispatcher.getDispatchContext( >>> ).makeValidContext('updateRateAmount', 'IN', parameters) >>> + result = run service: 'updateRateAmount', with: >>> createRateAmountMap >>> + if (ServiceUtil.isError(result)) return result >>> + } >>> + return success() >>> +} >>> + >>> +def deletePartyRate() { >>> + GenericValue lookedUpValue = from('PartyRate').where([partyId: >>> partyId, rateTypeId: rateTypeId, fromDate: fromDate]).queryOne() >>> + if (lookedUpValue) { >>> + lookedUpValue.thruDate = UtilDateTime.nowTimestamp() >>> + lookedUpValue.store() >>> + >>> + //expire related rate amount >>> + Map deleteRateAmountMap = dispatcher.getDispatchContext( >>> ).makeValidContext('deleteRateAmount', 'IN', parameters) >>> + result = run service: 'deleteRateAmount', with: >>> deleteRateAmountMap >>> + if (ServiceUtil.isError(result)) return result >>> + } >>> + return success() >>> +} >>> >>> Propchange: ofbiz/ofbiz-framework/trunk/applications/accounting/groovySc >>> ripts/rate/RateServices.groovy >>> ------------------------------------------------------------ >>> ------------------ >>> svn:eol-style = native >>> >>> Propchange: ofbiz/ofbiz-framework/trunk/applications/accounting/groovySc >>> ripts/rate/RateServices.groovy >>> ------------------------------------------------------------ >>> ------------------ >>> svn:keywords = Date Rev Author URL Id >>> >>> Propchange: ofbiz/ofbiz-framework/trunk/applications/accounting/groovySc >>> ripts/rate/RateServices.groovy >>> ------------------------------------------------------------ >>> ------------------ >>> svn:mime-type = text/plain >>> >>> Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/minilang >>> /rate/RateServices.xml >>> URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/app >>> lications/accounting/minilang/rate/RateServices.xml?rev= >>> 1796428&r1=1796427&r2=1796428&view=diff >>> ============================================================ >>> ================== >>> --- ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/rate/RateServices.xml >>> (original) >>> +++ ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/rate/RateServices.xml >>> Sat May 27 16:23:31 2017 >>> @@ -21,85 +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="updateRateAmount" >>> short-description="update/create a rate amount value"> >>> - <!-- set defaults --> >>> - <if-empty field="parameters.rateCurrencyUomId"> >>> - <property-to-field resource="general.properties" property=" >>> currency.uom.id.default" field="parameters.rateCurrencyUomId"/> >>> - </if-empty> >>> - <if-empty field="parameters.periodTypeId"> >>> - <set field="parameters.periodTypeId" value="RATE_HOUR"/> >>> - </if-empty> >>> - <if-empty field="parameters.emplPositionTypeId"> >>> - <set field="parameters.emplPositionTypeId" value="_NA_"/> >>> - </if-empty> >>> - <if-empty field="parameters.partyId"> >>> - <set field="parameters.partyId" value="_NA_"/> >>> - </if-empty> >>> - <if-empty field="parameters.workEffortId"> >>> - <set field="parameters.workEffortId" value="_NA_"/> >>> - </if-empty> >>> - >>> - <!-- try to find existing value --> >>> - <entity-and entity-name="RateAmount" list="rateAmounts" >>> filter-by-date="true"> >>> - <field-map field-name="rateTypeId" >>> from-field="parameters.rateTypeId"/> >>> - <field-map field-name="workEffortId" >>> from-field="parameters.workEffortId"/> >>> - <field-map field-name="rateCurrencyUomId" >>> from-field="parameters.rateCurrencyUomId"/> >>> - <field-map field-name="emplPositionTypeId" >>> from-field="parameters.emplPositionTypeId"/> >>> - <field-map field-name="partyId" >>> from-field="parameters.partyId"/> >>> - <field-map field-name="periodTypeId" >>> from-field="parameters.periodTypeId"/> >>> - </entity-and> >>> - >>> - <!-- end existing value --> >>> - <if-not-empty field="rateAmounts"> >>> - <first-from-list list="rateAmounts" entry="rateAmount"/> >>> - <if-compare-field field="rateAmount.rateAmount" >>> operator="not-equals" to-field="parameters.rateAmount"> >>> - <set-service-fields service-name="deleteRateAmount" >>> map="rateAmount" to-map="delRateAmount"/> >>> - <call-service service-name="deleteRateAmount" >>> in-map-name="delRateAmount"/> >>> - </if-compare-field> >>> - </if-not-empty> >>> - >>> - <make-value entity-name="RateAmount" value-field="newEntity"/> >>> - <set-pk-fields map="parameters" value-field="newEntity"/> >>> - <set-nonpk-fields map="parameters" value-field="newEntity"/> >>> - <if-empty field="newEntity.fromDate"><now-timestamp >>> field="newEntity.fromDate"/></if-empty> >>> - <clear-field field="newEntity.thruDate"/> >>> - <create-value value-field="newEntity"/> >>> - </simple-method> >>> - >>> - <simple-method method-name="deleteRateAmount" >>> short-description="update/create a rate amount value"> >>> - <!-- set defaults --> >>> - <if-empty field="parameters.rateCurrencyUomId"> >>> - <property-to-field resource="general.properties" property=" >>> currency.uom.id.default" field="parameters.rateCurrencyUomId"/> >>> - </if-empty> >>> - <if-empty field="parameters.periodTypeId"> >>> - <set field="parameters.periodTypeId" value="RATE_HOUR"/> >>> - </if-empty> >>> - <if-empty field="parameters.emplPositionTypeId"> >>> - <set field="parameters.emplPositionTypeId" value="_NA_"/> >>> - </if-empty> >>> - <if-empty field="parameters.partyId"> >>> - <set field="parameters.partyId" value="_NA_"/> >>> - </if-empty> >>> - <if-empty field="parameters.workEffortId"> >>> - <set field="parameters.workEffortId" value="_NA_"/> >>> - </if-empty> >>> - >>> - <entity-one entity-name="RateAmount" value-field="rateAmount"/> >>> - >>> - <if-not-empty field="rateAmount"> >>> - <now-timestamp field="nowTimestamp"/> >>> - <set field ="previousDay" value="${groovy: >>> org.apache.ofbiz.base.util.UtilDateTime.adjustTimestamp(nowTimestamp,5,-1)}" >>> type="Timestamp"/> >>> - <set field="rateAmount.thruDate" value="${groovy: >>> org.apache.ofbiz.base.util.UtilDateTime.getDayEnd(previousDay)}" >>> type="Timestamp"/> >>> - <store-value value-field="rateAmount"/> >>> - <else> >>> - <add-error> >>> - <fail-property resource="AccountingErrorUiLabels" >>> property="AccountingDeleteRateAmount"/> >>> - </add-error> >>> - </else> >>> - </if-not-empty> >>> - >>> - </simple-method> >>> - >>> <simple-method method-name="getRateAmount" short-description="Get >>> the applicable rate amount value"> >>> <!-- >>> Search for the applicable rate from most specific to most >>> general in the RateAmount entity >>> @@ -333,57 +254,4 @@ under the License. >>> <field-to-result field="parameters.ratesList" >>> result-name="filteredRatesList"/> >>> </simple-method> >>> - <!-- party rate services --> >>> - <simple-method method-name="updatePartyRate" >>> short-description="Update/Create PartyRate"> >>> - <!-- check if already exist is so expire current record --> >>> - <entity-and entity-name="PartyRate" list="partyRates" >>> filter-by-date="true"> >>> - <field-map field-name="partyId" >>> from-field="parameters.partyId"/> >>> - <field-map field-name="rateTypeId" >>> from-field="parameters.rateTypeId"/> >>> - </entity-and> >>> - <if-not-empty field="partyRates"> >>> - <first-from-list list="partyRates" entry="partyRate"/> >>> - <now-timestamp field="partyRate.thruDate"/> >>> - <store-value value-field="partyRate"/> >>> - </if-not-empty> >>> - >>> - <make-value value-field="newEntity" entity-name="PartyRate"/> >>> - <set-pk-fields map="parameters" value-field="newEntity"/> >>> - <if-empty field="newEntity.fromDate"><now-timestamp >>> field="newEntity.fromDate"/></if-empty> >>> - <set-nonpk-fields map="parameters" value-field="newEntity"/> >>> - <call-simple-method method-name="checkOtherDefaultRate"/> >>> - <create-value value-field="newEntity"/> >>> - >>> - <if-not-empty field="parameters.rateAmount"> >>> - <set-service-fields service-name="updateRateAmount" >>> map="parameters" to-map="updRate"/> >>> - <call-service service-name="updateRateAmount" >>> in-map-name="updRate"/> >>> - </if-not-empty> >>> - </simple-method> >>> - >>> - <simple-method method-name="checkOtherDefaultRate" >>> short-description="remove an other defaultRate flag"> >>> - <set value="_CREATE" field="securityAction"/> >>> - <check-permission permission="ACCOUNTING" >>> action="${securityAction}"> >>> - <fail-property resource="AccountingUiLabels" >>> property="AccountingPermissionError"/> >>> - </check-permission> >>> - <check-errors/> >>> - <if-compare field="newEntity.defaultRate" value="Y" >>> operator="equals"> >>> - <entity-and entity-name="PartyRate" list="rates" >>> filter-by-date="true"> >>> - <field-map field-name="partyId" >>> from-field="newEntity.partyId"/> >>> - <field-map field-name="defaultRate" value="Y"/> >>> - </entity-and> >>> - <if-not-empty field="rates"> >>> - <first-from-list list="rates" entry="rate"/> >>> - <set field="rate.defaultRate" value="N"/> >>> - <store-value value-field="rate"/> >>> - </if-not-empty> >>> - </if-compare> >>> - </simple-method> >>> - <simple-method method-name="deletePartyRate" >>> short-description="Delete PartyRate"> >>> - <entity-one entity-name="PartyRate" value-field="lookedUpValue"/> >>> - <now-timestamp field="lookedUpValue.thruDate"/> >>> - <store-value value-field="lookedUpValue"/> >>> - >>> - <set-service-fields service-name="deleteRateAmount" >>> map="parameters" to-map="delRateAmount"/> >>> - <set field="delRateAmount.fromDate" >>> from-field="parameters.rateAmountFromDate"/> >>> - <call-service service-name="deleteRateAmount" >>> in-map-name="delRateAmount"/> >>> - </simple-method> >>> </simple-methods> >>> >>> Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/serviced >>> ef/services_rate.xml >>> URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/app >>> lications/accounting/servicedef/services_rate.xml?rev= >>> 1796428&r1=1796427&r2=1796428&view=diff >>> ============================================================ >>> ================== >>> --- ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_rate.xml >>> (original) >>> +++ ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_rate.xml >>> Sat May 27 16:23:31 2017 >>> @@ -24,21 +24,29 @@ under the License. >>> <vendor>OFBiz</vendor> >>> <version>1.0</version> >>> - <service name="updateRateAmount" default-entity-name="RateAmount" >>> engine="simple" auth="true" >>> - location="component://accounting/minilang/rate/RateServices.xml" >>> invoke="updateRateAmount"> >>> + <service name="updateRateAmount" default-entity-name="RateAmount" >>> engine="groovy" auth="true" >>> + location="component://accounting/groovyScripts/rate/RateServices.groovy" >>> invoke="updateRateAmount"> >>> <description>Create/update Rate Amount</description> >>> <permission-service service-name="acctgBasePermissionCheck" >>> main-action="CREATE"/> >>> <auto-attributes include="all" mode="IN" optional="true"/> >>> <override name="rateTypeId" optional="false"/> >>> <override name="rateAmount" optional="false"/> >>> - </service> >>> - <service name="deleteRateAmount" default-entity-name="RateAmount" >>> engine="simple" auth="true" >>> - location="component://accounting/minilang/rate/RateServices.xml" >>> invoke="deleteRateAmount"> >>> - <description>Delete (expire) Rate Amount</description> >>> + <override name="emplPositionTypeId" default-value="_NA_"/> >>> + <override name="workEffortId" default-value="_NA_"/> >>> + <override name="periodTypeId" default-value="RATE_HOUR"/> >>> + <override name="partyId" default-value="_NA_"/> >>> + </service> >>> + <service name="deleteRateAmount" default-entity-name="RateAmount" >>> engine="groovy" auth="true" >>> + location="component://accounting/groovyScripts/rate/RateServices.groovy" >>> invoke="deleteRateAmount"> >>> + <description>expire Rate Amount</description> >>> <permission-service service-name="acctgBasePermissionCheck" >>> main-action="CREATE"/> >>> <auto-attributes include="pk" mode="IN" optional="true"/> >>> <override name="rateTypeId" optional="false"/> >>> <override name="fromDate" optional="false"/> >>> + <override name="emplPositionTypeId" default-value="_NA_"/> >>> + <override name="workEffortId" default-value="_NA_"/> >>> + <override name="periodTypeId" default-value="RATE_HOUR"/> >>> + <override name="partyId" default-value="_NA_"/> >>> </service> >>> <service name="getRateAmount" default-entity-name="RateAmount" >>> engine="simple" auth="true" >>> location="component://accounting/minilang/rate/RateServices.xml" >>> invoke="getRateAmount"> >>> @@ -96,8 +104,8 @@ under the License. >>> </service> >>> <!-- PartyRate Services --> >>> - <service name="updatePartyRate" default-entity-name="PartyRate" >>> engine="simple" auth="true" >>> - location="component://accounting/minilang/rate/RateServices.xml" >>> invoke="updatePartyRate"> >>> + <service name="updatePartyRate" default-entity-name="PartyRate" >>> engine="groovy" auth="true" >>> + location="component://accounting/groovyScripts/rate/RateServices.groovy" >>> invoke="updatePartyRate"> >>> <description>Creates PartyRate</description> >>> <permission-service service-name="acctgBasePermissionCheck" >>> main-action="CREATE"/> >>> <auto-attributes include="pk" mode="IN" optional="false"/> >>> @@ -108,9 +116,9 @@ under the License. >>> <attribute name="periodTypeId" type="String" mode="IN"/> >>> <override name="fromDate" optional="true"/> >>> </service> >>> - <service name="deletePartyRate" default-entity-name="PartyRate" >>> engine="simple" auth="true" >>> - location="component://accounting/minilang/rate/RateServices.xml" >>> invoke="deletePartyRate"> >>> - <description>Deletes PartyRate</description> >>> + <service name="deletePartyRate" default-entity-name="PartyRate" >>> engine="groovy" auth="true" >>> + location="component://accounting/groovyScripts/rate/RateServices.groovy" >>> invoke="deletePartyRate"> >>> + <description>Expire PartyRate and expire related >>> rateAmount</description> >>> <permission-service service-name="acctgBasePermissionCheck" >>> main-action="UPDATE"/> >>> <auto-attributes include="pk" mode="IN" optional="false"/> >>> <attribute name="rateAmountFromDate" type="Timestamp" mode="IN" >>> optional="true"/><!-- to be able to expire rateamount specific to a party >>> records....--> >>> >>> >>> >> |
Thanks Deepak and Nicolas for the clarification. I overlooked the
service definition change. Perfect, *thumbsup*! Best regards, Michael Brohl ecomify GmbH www.ecomify.de Am 29.05.17 um 09:59 schrieb Nicolas Malin: > Deepak is more faster than me :) > > This service have some integration test so don't worries the code work > well and thanks for the double check Michael. > > Nicolas > > Le 29/05/2017 à 08:43, Deepak Dixit a écrit : >> Hi Michael, >> >> Those default values moved to service definition instead of >> implementation. >> We have feature to pass default value at service definition level. >> >> {code} >> + <override name="emplPositionTypeId" default-value="_NA_"/> >> + <override name="workEffortId" default-value="_NA_"/> >> + <override name="periodTypeId" default-value="RATE_HOUR"/> >> + <override name="partyId" default-value="_NA_"/> >> {code} >> >> >> Thanks & Regards >> -- >> Deepak Dixit >> www.hotwaxsystems.com >> >> On Sun, May 28, 2017 at 4:19 PM, Michael Brohl >> <[hidden email]> >> wrote: >> >>> Hi Nicolas, >>> >>> just saw that we had some checks and default values set in the original >>> mini lang service for updateRateAmount which I did not find in the new >>> Grrovy version. >>> >>> Don't we need these checks? >>> >>> Thanks and regards, >>> >>> Michael Brohl >>> ecomify GmbH >>> www.ecomify.de >>> >>> >>> Am 27.05.17 um 18:23 schrieb [hidden email]: >>> >>> Author: nmalin >>>> Date: Sat May 27 16:23:31 2017 >>>> New Revision: 1796428 >>>> >>>> URL: http://svn.apache.org/viewvc?rev=1796428&view=rev >>>> Log: >>>> Fixed: Convert RateServices.xml mini-lang to groovyDSL (OFBIZ-9381) >>>> related to task OFBIZ-9350 Deprecate Mini Lang, convert service >>>> updateRateAmount, deleteRateAmount updatePartyRate and >>>> deletePartyRate from >>>> mini-ang to groovyDSL >>>> Thanks to Deepak for the review >>>> >>>> Added: >>>> ofbiz/ofbiz-framework/trunk/applications/accounting/groovyS >>>> cripts/rate/ >>>> ofbiz/ofbiz-framework/trunk/applications/accounting/groovyS >>>> cripts/rate/RateServices.groovy (with props) >>>> Modified: >>>> ofbiz/ofbiz-framework/trunk/applications/accounting/minilan >>>> g/rate/RateServices.xml >>>> ofbiz/ofbiz-framework/trunk/applications/accounting/service >>>> def/services_rate.xml >>>> >>>> Added: ofbiz/ofbiz-framework/trunk/applications/accounting/groovySc >>>> ripts/rate/RateServices.groovy >>>> URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/app >>>> lications/accounting/groovyScripts/rate/RateServices.groovy? >>>> rev=1796428&view=auto >>>> ============================================================ >>>> ================== >>>> --- >>>> ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy >>>> (added) >>>> +++ >>>> ofbiz/ofbiz-framework/trunk/applications/accounting/groovyScripts/rate/RateServices.groovy >>>> Sat May 27 16:23:31 2017 >>>> @@ -0,0 +1,121 @@ >>>> +/* >>>> + * 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.UtilDateTime >>>> +import org.apache.ofbiz.base.util.UtilProperties >>>> +import org.apache.ofbiz.base.util.UtilValidate >>>> +import org.apache.ofbiz.entity.GenericValue >>>> +import org.apache.ofbiz.entity.util.EntityUtil >>>> +import org.apache.ofbiz.service.ServiceUtil >>>> + >>>> +import java.sql.Timestamp >>>> + >>>> + >>>> +/** >>>> + * Service to create a rate amount value, if a existing value is >>>> present >>>> expire it before >>>> + */ >>>> +def updateRateAmount() { >>>> + GenericValue newEntity = delegator.makeValidValue('RateAmount', >>>> parameters) >>>> + if (!newEntity.rateCurrencyUomId) { >>>> + newEntity.rateCurrencyUomId = >>>> UtilProperties.getPropertyValue('general.properties', >>>> 'currency.uom.id.default') >>>> + } >>>> + if (!newEntity.fromDate) newEntity.fromDate = >>>> UtilDateTime.getDayStart(UtilDateTime.nowTimestamp()) >>>> + newEntity.thruDate = null >>>> + >>>> + //Check if the entry is already exist with a different rate else >>>> expire the older to create the new one >>>> + boolean updating = false >>>> + GenericValue rateAmountLookedUpValue = >>>> from('RateAmount').where('rateTypeId', >>>> newEntity.rateTypeId, >>>> + 'emplPositionTypeId', newEntity.emplPositionTypeId, >>>> + 'rateCurrencyUomId', newEntity.rateCurrencyUomId, >>>> + 'workEffortId', newEntity.workEffortId, >>>> + 'periodTypeId', newEntity.periodTypeId, >>>> + 'partyId', newEntity.partyId).filterByDate().queryFirst() >>>> + if (rateAmountLookedUpValue) { >>>> + updating = (rateAmountLookedUpValue.fromD >>>> ate.compareTo(newEntity.fromDate) == 0) >>>> + if (rateAmountLookedUpValue.rateAmount != rateAmount) { >>>> + Map deleteRateAmountMap = dispatcher.getDispatchContext( >>>> ).makeValidContext('deleteRateAmount', 'IN', rateAmountLookedUpValue) >>>> + result = run service: 'deleteRateAmount', with: >>>> deleteRateAmountMap >>>> + if (ServiceUtil.isError(result)) return result >>>> + } else { >>>> + return >>>> error(UtilProperties.getMessage('AccountingErrorUiLabels', >>>> 'AccountingUpdateRateAmountAlreadyExist', locale)) >>>> + } >>>> + } >>>> + if (updating) newEntity.store() >>>> + else newEntity.create() >>>> + return success() >>>> +} >>>> + >>>> +/** >>>> + * Service to expire a rate amount value >>>> + */ >>>> +def deleteRateAmount() { >>>> + GenericValue lookedUpValue = >>>> delegator.makeValidValue('RateAmount', >>>> parameters) >>>> + if (!lookedUpValue.rateCurrencyUomId) { >>>> + lookedUpValue.rateCurrencyUomId = >>>> UtilProperties.getPropertyValue('general.properties', >>>> 'currency.uom.id.default') >>>> + } >>>> + lookedUpValue = from('RateAmount').where(looke >>>> dUpValue.getFields(lookedUpValue.getModelEntity(). >>>> getPkFieldNames())).queryOne() >>>> + if (lookedUpValue) { >>>> + Timestamp previousDay = >>>> UtilDateTime.adjustTimestamp(UtilDateTime.nowTimestamp(), >>>> 5, -1) >>>> + lookedUpValue.thruDate = UtilDateTime.getDayEnd(previousDay) >>>> + lookedUpValue.store() >>>> + } else { >>>> + return >>>> error(UtilProperties.getMessage('AccountingErrorUiLabels', >>>> 'AccountingDeleteRateAmount', locale)) >>>> + } >>>> + return success() >>>> +} >>>> + >>>> +def updatePartyRate() { >>>> + List<GenericValue> partyRates = from('PartyRate').where([partyId: >>>> partyId, rateTypeId: rateTypeId]).queryList() >>>> + if (UtilValidate.isNotEmpty(partyRates)) { >>>> + GenericValue partyRate = EntityUtil.getFirst(partyRates) >>>> + partyRate.thruDate = UtilDateTime.nowTimestamp() >>>> + } >>>> + GenericValue newEntity = delegator.makeValidValue('PartyRate', >>>> parameters) >>>> + if (!newEntity.fromDate) newEntity.fromDate = >>>> UtilDateTime.nowTimestamp() >>>> + newEntity.create() >>>> + >>>> + //check other default rate to desactive them >>>> + if ('Y' == newEntity.defaultRate) { >>>> + partyRates = from('PartyRate').where([partyId: partyId, >>>> defaultRate: 'Y']).queryList() >>>> + partyRates.each { partyDefaultRate -> >>>> + partyDefaultRate.defaultRate = 'N' >>>> + partyDefaultRate.store() >>>> + } >>>> + } >>>> + if (parameters.rateAmount) { >>>> + Map createRateAmountMap = dispatcher.getDispatchContext( >>>> ).makeValidContext('updateRateAmount', 'IN', parameters) >>>> + result = run service: 'updateRateAmount', with: >>>> createRateAmountMap >>>> + if (ServiceUtil.isError(result)) return result >>>> + } >>>> + return success() >>>> +} >>>> + >>>> +def deletePartyRate() { >>>> + GenericValue lookedUpValue = from('PartyRate').where([partyId: >>>> partyId, rateTypeId: rateTypeId, fromDate: fromDate]).queryOne() >>>> + if (lookedUpValue) { >>>> + lookedUpValue.thruDate = UtilDateTime.nowTimestamp() >>>> + lookedUpValue.store() >>>> + >>>> + //expire related rate amount >>>> + Map deleteRateAmountMap = dispatcher.getDispatchContext( >>>> ).makeValidContext('deleteRateAmount', 'IN', parameters) >>>> + result = run service: 'deleteRateAmount', with: >>>> deleteRateAmountMap >>>> + if (ServiceUtil.isError(result)) return result >>>> + } >>>> + return success() >>>> +} >>>> >>>> Propchange: >>>> ofbiz/ofbiz-framework/trunk/applications/accounting/groovySc >>>> ripts/rate/RateServices.groovy >>>> ------------------------------------------------------------ >>>> ------------------ >>>> svn:eol-style = native >>>> >>>> Propchange: >>>> ofbiz/ofbiz-framework/trunk/applications/accounting/groovySc >>>> ripts/rate/RateServices.groovy >>>> ------------------------------------------------------------ >>>> ------------------ >>>> svn:keywords = Date Rev Author URL Id >>>> >>>> Propchange: >>>> ofbiz/ofbiz-framework/trunk/applications/accounting/groovySc >>>> ripts/rate/RateServices.groovy >>>> ------------------------------------------------------------ >>>> ------------------ >>>> svn:mime-type = text/plain >>>> >>>> Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/minilang >>>> /rate/RateServices.xml >>>> URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/app >>>> lications/accounting/minilang/rate/RateServices.xml?rev= >>>> 1796428&r1=1796427&r2=1796428&view=diff >>>> ============================================================ >>>> ================== >>>> --- >>>> ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/rate/RateServices.xml >>>> (original) >>>> +++ >>>> ofbiz/ofbiz-framework/trunk/applications/accounting/minilang/rate/RateServices.xml >>>> Sat May 27 16:23:31 2017 >>>> @@ -21,85 +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="updateRateAmount" >>>> short-description="update/create a rate amount value"> >>>> - <!-- set defaults --> >>>> - <if-empty field="parameters.rateCurrencyUomId"> >>>> - <property-to-field resource="general.properties" >>>> property=" >>>> currency.uom.id.default" field="parameters.rateCurrencyUomId"/> >>>> - </if-empty> >>>> - <if-empty field="parameters.periodTypeId"> >>>> - <set field="parameters.periodTypeId" value="RATE_HOUR"/> >>>> - </if-empty> >>>> - <if-empty field="parameters.emplPositionTypeId"> >>>> - <set field="parameters.emplPositionTypeId" value="_NA_"/> >>>> - </if-empty> >>>> - <if-empty field="parameters.partyId"> >>>> - <set field="parameters.partyId" value="_NA_"/> >>>> - </if-empty> >>>> - <if-empty field="parameters.workEffortId"> >>>> - <set field="parameters.workEffortId" value="_NA_"/> >>>> - </if-empty> >>>> - >>>> - <!-- try to find existing value --> >>>> - <entity-and entity-name="RateAmount" list="rateAmounts" >>>> filter-by-date="true"> >>>> - <field-map field-name="rateTypeId" >>>> from-field="parameters.rateTypeId"/> >>>> - <field-map field-name="workEffortId" >>>> from-field="parameters.workEffortId"/> >>>> - <field-map field-name="rateCurrencyUomId" >>>> from-field="parameters.rateCurrencyUomId"/> >>>> - <field-map field-name="emplPositionTypeId" >>>> from-field="parameters.emplPositionTypeId"/> >>>> - <field-map field-name="partyId" >>>> from-field="parameters.partyId"/> >>>> - <field-map field-name="periodTypeId" >>>> from-field="parameters.periodTypeId"/> >>>> - </entity-and> >>>> - >>>> - <!-- end existing value --> >>>> - <if-not-empty field="rateAmounts"> >>>> - <first-from-list list="rateAmounts" entry="rateAmount"/> >>>> - <if-compare-field field="rateAmount.rateAmount" >>>> operator="not-equals" to-field="parameters.rateAmount"> >>>> - <set-service-fields service-name="deleteRateAmount" >>>> map="rateAmount" to-map="delRateAmount"/> >>>> - <call-service service-name="deleteRateAmount" >>>> in-map-name="delRateAmount"/> >>>> - </if-compare-field> >>>> - </if-not-empty> >>>> - >>>> - <make-value entity-name="RateAmount" >>>> value-field="newEntity"/> >>>> - <set-pk-fields map="parameters" value-field="newEntity"/> >>>> - <set-nonpk-fields map="parameters" value-field="newEntity"/> >>>> - <if-empty field="newEntity.fromDate"><now-timestamp >>>> field="newEntity.fromDate"/></if-empty> >>>> - <clear-field field="newEntity.thruDate"/> >>>> - <create-value value-field="newEntity"/> >>>> - </simple-method> >>>> - >>>> - <simple-method method-name="deleteRateAmount" >>>> short-description="update/create a rate amount value"> >>>> - <!-- set defaults --> >>>> - <if-empty field="parameters.rateCurrencyUomId"> >>>> - <property-to-field resource="general.properties" >>>> property=" >>>> currency.uom.id.default" field="parameters.rateCurrencyUomId"/> >>>> - </if-empty> >>>> - <if-empty field="parameters.periodTypeId"> >>>> - <set field="parameters.periodTypeId" value="RATE_HOUR"/> >>>> - </if-empty> >>>> - <if-empty field="parameters.emplPositionTypeId"> >>>> - <set field="parameters.emplPositionTypeId" value="_NA_"/> >>>> - </if-empty> >>>> - <if-empty field="parameters.partyId"> >>>> - <set field="parameters.partyId" value="_NA_"/> >>>> - </if-empty> >>>> - <if-empty field="parameters.workEffortId"> >>>> - <set field="parameters.workEffortId" value="_NA_"/> >>>> - </if-empty> >>>> - >>>> - <entity-one entity-name="RateAmount" >>>> value-field="rateAmount"/> >>>> - >>>> - <if-not-empty field="rateAmount"> >>>> - <now-timestamp field="nowTimestamp"/> >>>> - <set field ="previousDay" value="${groovy: >>>> org.apache.ofbiz.base.util.UtilDateTime.adjustTimestamp(nowTimestamp,5,-1)}" >>>> >>>> type="Timestamp"/> >>>> - <set field="rateAmount.thruDate" value="${groovy: >>>> org.apache.ofbiz.base.util.UtilDateTime.getDayEnd(previousDay)}" >>>> type="Timestamp"/> >>>> - <store-value value-field="rateAmount"/> >>>> - <else> >>>> - <add-error> >>>> - <fail-property resource="AccountingErrorUiLabels" >>>> property="AccountingDeleteRateAmount"/> >>>> - </add-error> >>>> - </else> >>>> - </if-not-empty> >>>> - >>>> - </simple-method> >>>> - >>>> <simple-method method-name="getRateAmount" >>>> short-description="Get >>>> the applicable rate amount value"> >>>> <!-- >>>> Search for the applicable rate from most specific to >>>> most >>>> general in the RateAmount entity >>>> @@ -333,57 +254,4 @@ under the License. >>>> <field-to-result field="parameters.ratesList" >>>> result-name="filteredRatesList"/> >>>> </simple-method> >>>> - <!-- party rate services --> >>>> - <simple-method method-name="updatePartyRate" >>>> short-description="Update/Create PartyRate"> >>>> - <!-- check if already exist is so expire current record --> >>>> - <entity-and entity-name="PartyRate" list="partyRates" >>>> filter-by-date="true"> >>>> - <field-map field-name="partyId" >>>> from-field="parameters.partyId"/> >>>> - <field-map field-name="rateTypeId" >>>> from-field="parameters.rateTypeId"/> >>>> - </entity-and> >>>> - <if-not-empty field="partyRates"> >>>> - <first-from-list list="partyRates" entry="partyRate"/> >>>> - <now-timestamp field="partyRate.thruDate"/> >>>> - <store-value value-field="partyRate"/> >>>> - </if-not-empty> >>>> - >>>> - <make-value value-field="newEntity" entity-name="PartyRate"/> >>>> - <set-pk-fields map="parameters" value-field="newEntity"/> >>>> - <if-empty field="newEntity.fromDate"><now-timestamp >>>> field="newEntity.fromDate"/></if-empty> >>>> - <set-nonpk-fields map="parameters" value-field="newEntity"/> >>>> - <call-simple-method method-name="checkOtherDefaultRate"/> >>>> - <create-value value-field="newEntity"/> >>>> - >>>> - <if-not-empty field="parameters.rateAmount"> >>>> - <set-service-fields service-name="updateRateAmount" >>>> map="parameters" to-map="updRate"/> >>>> - <call-service service-name="updateRateAmount" >>>> in-map-name="updRate"/> >>>> - </if-not-empty> >>>> - </simple-method> >>>> - >>>> - <simple-method method-name="checkOtherDefaultRate" >>>> short-description="remove an other defaultRate flag"> >>>> - <set value="_CREATE" field="securityAction"/> >>>> - <check-permission permission="ACCOUNTING" >>>> action="${securityAction}"> >>>> - <fail-property resource="AccountingUiLabels" >>>> property="AccountingPermissionError"/> >>>> - </check-permission> >>>> - <check-errors/> >>>> - <if-compare field="newEntity.defaultRate" value="Y" >>>> operator="equals"> >>>> - <entity-and entity-name="PartyRate" list="rates" >>>> filter-by-date="true"> >>>> - <field-map field-name="partyId" >>>> from-field="newEntity.partyId"/> >>>> - <field-map field-name="defaultRate" value="Y"/> >>>> - </entity-and> >>>> - <if-not-empty field="rates"> >>>> - <first-from-list list="rates" entry="rate"/> >>>> - <set field="rate.defaultRate" value="N"/> >>>> - <store-value value-field="rate"/> >>>> - </if-not-empty> >>>> - </if-compare> >>>> - </simple-method> >>>> - <simple-method method-name="deletePartyRate" >>>> short-description="Delete PartyRate"> >>>> - <entity-one entity-name="PartyRate" >>>> value-field="lookedUpValue"/> >>>> - <now-timestamp field="lookedUpValue.thruDate"/> >>>> - <store-value value-field="lookedUpValue"/> >>>> - >>>> - <set-service-fields service-name="deleteRateAmount" >>>> map="parameters" to-map="delRateAmount"/> >>>> - <set field="delRateAmount.fromDate" >>>> from-field="parameters.rateAmountFromDate"/> >>>> - <call-service service-name="deleteRateAmount" >>>> in-map-name="delRateAmount"/> >>>> - </simple-method> >>>> </simple-methods> >>>> >>>> Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/serviced >>>> ef/services_rate.xml >>>> URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/app >>>> lications/accounting/servicedef/services_rate.xml?rev= >>>> 1796428&r1=1796427&r2=1796428&view=diff >>>> ============================================================ >>>> ================== >>>> --- >>>> ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_rate.xml >>>> (original) >>>> +++ >>>> ofbiz/ofbiz-framework/trunk/applications/accounting/servicedef/services_rate.xml >>>> Sat May 27 16:23:31 2017 >>>> @@ -24,21 +24,29 @@ under the License. >>>> <vendor>OFBiz</vendor> >>>> <version>1.0</version> >>>> - <service name="updateRateAmount" >>>> default-entity-name="RateAmount" >>>> engine="simple" auth="true" >>>> - location="component://accounting/minilang/rate/RateServices.xml" >>>> invoke="updateRateAmount"> >>>> + <service name="updateRateAmount" default-entity-name="RateAmount" >>>> engine="groovy" auth="true" >>>> + >>>> location="component://accounting/groovyScripts/rate/RateServices.groovy" >>>> >>>> invoke="updateRateAmount"> >>>> <description>Create/update Rate Amount</description> >>>> <permission-service service-name="acctgBasePermissionCheck" >>>> main-action="CREATE"/> >>>> <auto-attributes include="all" mode="IN" optional="true"/> >>>> <override name="rateTypeId" optional="false"/> >>>> <override name="rateAmount" optional="false"/> >>>> - </service> >>>> - <service name="deleteRateAmount" default-entity-name="RateAmount" >>>> engine="simple" auth="true" >>>> - location="component://accounting/minilang/rate/RateServices.xml" >>>> invoke="deleteRateAmount"> >>>> - <description>Delete (expire) Rate Amount</description> >>>> + <override name="emplPositionTypeId" default-value="_NA_"/> >>>> + <override name="workEffortId" default-value="_NA_"/> >>>> + <override name="periodTypeId" default-value="RATE_HOUR"/> >>>> + <override name="partyId" default-value="_NA_"/> >>>> + </service> >>>> + <service name="deleteRateAmount" default-entity-name="RateAmount" >>>> engine="groovy" auth="true" >>>> + >>>> location="component://accounting/groovyScripts/rate/RateServices.groovy" >>>> >>>> invoke="deleteRateAmount"> >>>> + <description>expire Rate Amount</description> >>>> <permission-service service-name="acctgBasePermissionCheck" >>>> main-action="CREATE"/> >>>> <auto-attributes include="pk" mode="IN" optional="true"/> >>>> <override name="rateTypeId" optional="false"/> >>>> <override name="fromDate" optional="false"/> >>>> + <override name="emplPositionTypeId" default-value="_NA_"/> >>>> + <override name="workEffortId" default-value="_NA_"/> >>>> + <override name="periodTypeId" default-value="RATE_HOUR"/> >>>> + <override name="partyId" default-value="_NA_"/> >>>> </service> >>>> <service name="getRateAmount" default-entity-name="RateAmount" >>>> engine="simple" auth="true" >>>> location="component://accounting/minilang/rate/RateServices.xml" >>>> invoke="getRateAmount"> >>>> @@ -96,8 +104,8 @@ under the License. >>>> </service> >>>> <!-- PartyRate Services --> >>>> - <service name="updatePartyRate" default-entity-name="PartyRate" >>>> engine="simple" auth="true" >>>> - location="component://accounting/minilang/rate/RateServices.xml" >>>> invoke="updatePartyRate"> >>>> + <service name="updatePartyRate" default-entity-name="PartyRate" >>>> engine="groovy" auth="true" >>>> + >>>> location="component://accounting/groovyScripts/rate/RateServices.groovy" >>>> >>>> invoke="updatePartyRate"> >>>> <description>Creates PartyRate</description> >>>> <permission-service service-name="acctgBasePermissionCheck" >>>> main-action="CREATE"/> >>>> <auto-attributes include="pk" mode="IN" optional="false"/> >>>> @@ -108,9 +116,9 @@ under the License. >>>> <attribute name="periodTypeId" type="String" mode="IN"/> >>>> <override name="fromDate" optional="true"/> >>>> </service> >>>> - <service name="deletePartyRate" default-entity-name="PartyRate" >>>> engine="simple" auth="true" >>>> - location="component://accounting/minilang/rate/RateServices.xml" >>>> invoke="deletePartyRate"> >>>> - <description>Deletes PartyRate</description> >>>> + <service name="deletePartyRate" default-entity-name="PartyRate" >>>> engine="groovy" auth="true" >>>> + >>>> location="component://accounting/groovyScripts/rate/RateServices.groovy" >>>> >>>> invoke="deletePartyRate"> >>>> + <description>Expire PartyRate and expire related >>>> rateAmount</description> >>>> <permission-service service-name="acctgBasePermissionCheck" >>>> main-action="UPDATE"/> >>>> <auto-attributes include="pk" mode="IN" optional="false"/> >>>> <attribute name="rateAmountFromDate" type="Timestamp" >>>> mode="IN" >>>> optional="true"/><!-- to be able to expire rateamount specific to a >>>> party >>>> records....--> >>>> >>>> >>>> >>> > smime.p7s (5K) Download Attachment |
Free forum by Nabble | Edit this page |