Author: jacopoc
Date: Tue Nov 27 02:05:02 2007 New Revision: 598582 URL: http://svn.apache.org/viewvc?rev=598582&view=rev Log: Improved the createAcctgTransAndEntries service: - it automatically retrieves the glAccountId (if it is not passed) from the glAccountTypeId field; - it automatically converts the origAmount from origCurrencyUomId to amount in currencyUomId; - some misc improvements Implemented the *first* service (as a proof of concept) that uses it to automatically create (triggered by a seca, for now disabled) an accounting transaction for sale shipment issuances. Added: ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml (with props) Modified: ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml ofbiz/trunk/applications/accounting/ofbiz-component.xml ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/AcctgTransServices.xml ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml Modified: ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml?rev=598582&r1=598581&r2=598582&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml (original) +++ ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml Tue Nov 27 02:05:02 2007 @@ -42,6 +42,8 @@ <AcctgTransType acctgTransTypeId="INVENTORY_RETURN" description="Inventory from Return" hasTable="N" parentTypeId="EXTERNAL_ACCTG_TRANS"/> + <AcctgTransType acctgTransTypeId="SALES_SHIPMENT" parentTypeId="" hasTable="N" description="Sales Shipment"/> + <AcctgTransEntryType acctgTransEntryTypeId="_NA_" description="Not Applicable" hasTable="N" parentTypeId=""/> <StatusType description="Acctg Entry Reconcile" hasTable="N" parentTypeId="" statusTypeId="ACCTG_ENREC_STATUS"/> Modified: ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml?rev=598582&r1=598581&r2=598582&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml (original) +++ ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml Tue Nov 27 02:05:02 2007 @@ -1423,11 +1423,13 @@ <field name="theirPartyId" type="id"></field> <field name="productId" type="id"></field> <field name="theirProductId" type="id"></field> + <field name="glAccountTypeId" type="id"></field> <field name="glAccountId" type="id-ne"></field> <field name="organizationPartyId" type="id-ne"></field> <field name="amount" type="currency-amount"></field> <field name="currencyUomId" type="id"></field> <field name="origAmount" type="currency-amount"></field> + <field name="origCurrencyUomId" type="id"></field> <field name="debitCreditFlag" type="indicator"></field> <field name="dueDate" type="date"></field> <field name="groupId" type="id"></field> @@ -1443,6 +1445,9 @@ <relation type="one" fk-name="ACCTTXENT_CURNCY" title="Currency" rel-entity-name="Uom"> <!-- title strictly speaking not necessary here but nice for consistency --> <key-map field-name="currencyUomId" rel-field-name="uomId"/> </relation> + <relation type="one" fk-name="ACCTTXENT_OCURNCY" title="OrigCurrency" rel-entity-name="Uom"> + <key-map field-name="origCurrencyUomId" rel-field-name="uomId"/> + </relation> <relation type="one" fk-name="ACCTTXENT_ACTX" rel-entity-name="AcctgTrans"> <key-map field-name="acctgTransId"/> </relation> @@ -1455,6 +1460,9 @@ <relation type="one-nofk" rel-entity-name="PartyRole"> <key-map field-name="partyId"/> <key-map field-name="roleTypeId"/> + </relation> + <relation type="one" fk-name="ACCTTXENT_GLACTT" rel-entity-name="GlAccountType"> + <key-map field-name="glAccountTypeId"/> </relation> <relation type="one" fk-name="ACCTTXENT_GLACT" rel-entity-name="GlAccount"> <key-map field-name="glAccountId"/> Modified: ofbiz/trunk/applications/accounting/ofbiz-component.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/ofbiz-component.xml?rev=598582&r1=598581&r2=598582&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/ofbiz-component.xml (original) +++ ofbiz/trunk/applications/accounting/ofbiz-component.xml Tue Nov 27 02:05:02 2007 @@ -67,6 +67,7 @@ <service-resource type="group" loader="main" location="servicedef/groups.xml"/> <service-resource type="eca" loader="main" location="servicedef/secas.xml"/> <service-resource type="eca" loader="main" location="servicedef/secas_payment.xml"/> + <!--<service-resource type="eca" loader="main" location="servicedef/secas_ledger.xml"/>--> <test-suite loader="main" location="testdef/accountingtests.xml"/> Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/AcctgTransServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/AcctgTransServices.xml?rev=598582&r1=598581&r2=598582&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/AcctgTransServices.xml (original) +++ ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/AcctgTransServices.xml Tue Nov 27 02:05:02 2007 @@ -69,6 +69,9 @@ </entity-one> <set from-field="partyAcctgPreference.baseCurrencyUomId" field="newEntity.currencyUomId"/> </if-empty> + <if-empty field-name="newEntity.acctgTransEntryTypeId"> + <set field="newEntity.acctgTransEntryTypeId" value="_NA_"/> + </if-empty> <!-- by default, set the reconciled status of this new entry to not reconciled --> <set value="AES_NOT_RECONCILED" field="newEntity.reconcileStatusId"/> Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml?rev=598582&r1=598581&r2=598582&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml (original) +++ ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml Tue Nov 27 02:05:02 2007 @@ -300,7 +300,7 @@ <!-- retrieve ledger rounding properties --> <property-to-field resource="arithmetic" property="ledger.decimals" field-name="ledgerDecimals"/> <property-to-field resource="arithmetic" property="ledger.rounding" field-name="roundingMode"/> - <log level="info" message="Using ledger decimals [${ledgerDecimals}] and rounding [${roundingMode}]"/> + <log level="info" message="Using ledger decimals [${ledgerDecimals}] and rounding [${roundingMode}]"/> <!-- first loop through and make sure all the entries are valid --> <iterate list-name="parameters.acctgTransEntries" entry-name="acctgTransEntry"> @@ -314,6 +314,57 @@ <add-error><fail-message message="${acctgTransEntry.organizationPartyId} for transaction ${acctgTransEntry.acctgTransId} entry ${acctgTransEntry.acctTransEntrySeqId} is not an internal organization "/></add-error> <check-errors/> </if-empty> + <!-- if the amount field is empty, then determine it from the origAmount and origCurrencyUomId fields: + if origCurrencyUomId is different from the base currency of the organization, then the amount value will be converted --> + <if-empty field-name="acctgTransEntry.amount"> + <if-not-empty field-name="acctgTransEntry.origAmount"> + <entity-one entity-name="PartyAcctgPreference" value-name="partyAcctgPreference" use-cache="true" auto-field-map="false"> + <field-map field-name="partyId" env-name="acctgTransEntry.organizationPartyId"/> + </entity-one> + <if-empty field-name="acctgTransEntry.origCurrencyUomId"> + <set field="acctgTransEntry.origCurrencyUomId" from-field="partyAcctgPreference.baseCurrencyUomId"/> + </if-empty> + <set field="acctgTransEntry.currencyUomId" from-field="partyAcctgPreference.baseCurrencyUomId"/> + <if-compare-field field-name="acctgTransEntry.origCurrencyUomId" operator="not-equals" to-field-name="acctgTransEntry.currencyUomId"> + <clear-field field-name="convertUomInMap"/> + <set field="convertUomInMap.originalValue" from-field="acctgTransEntry.origAmount"/> + <set field="convertUomInMap.uomId" from-field="acctgTransEntry.origCurrencyUomId"/> + <set field="convertUomInMap.uomIdTo" from-field="acctgTransEntry.currencyUomId"/> + <!-- TODO: set the optional asOfDate input parameter --> + <call-service service-name="convertUom" in-map-name="convertUomInMap"> + <result-to-field result-name="convertedValue" field-name="acctgTransEntry.amount"/> + </call-service> + <else> + <set field="acctgTransEntry.amount" from-field="acctgTransEntry.origAmount"/> + </else> + </if-compare-field> + </if-not-empty> + </if-empty> + <if-empty field-name="acctgTransEntry.amount"> + <add-error><fail-message message="Cannot process accounting transaction entries with null amount: ${acctgTransEntry}"/></add-error> + <check-errors/> + </if-empty> + <!-- if the glAccountId is empty, but we have a glAccountTypeId, then we will determine the + correct glAccountId from the gl setup settings --> + <if-empty field-name="acctgTransEntry.glAccountId"> + <if-not-empty field-name="acctgTransEntry.glAccountTypeId"> + <!-- if a productId is set, then we get the gl account associated to the product, or the default one + for the glAccountTypeId as returned by the service getProductOrgGlAccount --> + <if-not-empty field-name="acctgTransEntry.productId"> + <clear-field field-name="getProductOrgGlAccountInMap"/> + <set field="getProductOrgGlAccountInMap.productId" from-field="acctgTransEntry.productId"/> + <set field="getProductOrgGlAccountInMap.glAccountTypeId" from-field="acctgTransEntry.glAccountTypeId"/> + <set field="getProductOrgGlAccountInMap.organizationPartyId" from-field="acctgTransEntry.organizationPartyId"/> + <call-service service-name="getProductOrgGlAccount" in-map-name="getProductOrgGlAccountInMap"> + <result-to-field result-name="glAccountId" field-name="acctgTransEntry.glAccountId"/> + </call-service> + </if-not-empty> + </if-not-empty> + </if-empty> + <if-empty field-name="acctgTransEntry.glAccountId"> + <add-error><fail-message message="Cannot process accounting transaction entries with a null glAccountId: ${acctgTransEntry}"/></add-error> + <check-errors/> + </if-empty> <!-- add up debits and credits --> <if-compare field-name="acctgTransEntry.debitCreditFlag" operator="equals" value="D"> <calculate field-name="debitTotal" decimal-scale="${ledgerDecimals}" rounding-mode="${roundingMode}"> @@ -369,7 +420,8 @@ </if-compare> </if-compare> - <!-- now create the AcctgTransEntry using the acctgTransId we already have from above --> + <!-- now create the AcctgTransEntry using the acctgTransId we already have from above --> + <clear-field field-name="createAcctgTransEntryParams"/> <set-service-fields service-name="createAcctgTransEntry" map-name="acctgTransEntry" to-map-name="createAcctgTransEntryParams"/> <set from-field="acctgTransId" field="createAcctgTransEntryParams.acctgTransId"/> <call-service service-name="createAcctgTransEntry" in-map-name="createAcctgTransEntryParams"/> @@ -382,7 +434,6 @@ <!-- Miscellaneous services for product and inventory --> <simple-method method-name="getProductOrgGlAccount" short-description="Look up a GlAccountId from ProductGlAccount, then GlAccountTypeDefault"> - <log level="warning" message="getProductOrgGlAccount is deprecated. Please use UtilAccounting.getProductOrgGlAccountId instead."/> <!-- if parameters for ProductGlAccount were passed, then try there first --> <if> <condition> @@ -409,5 +460,58 @@ <entity-one entity-name="InventoryItem" value-name="item"/> <get-related-one relation-name="Facility" value-name="item" to-value-name="facility"/> <field-to-result field-name="facility.ownerPartyId" result-name="ownerPartyId"/> - </simple-method> + </simple-method> + + <!-- Services for the automatic creation of accounting transactions based on business transactions + Typically, these services are triggered by SECAs --> + <simple-method method-name="createAcctgTransForSalesShipment" short-description="Create accounting transactions for issuances for a sales shipment (D: Inventory, C: COGS)"> + <!-- retrieve ledger rounding properties --> + <property-to-field resource="arithmetic" property="ledger.decimals" field-name="ledgerDecimals"/> + <property-to-field resource="arithmetic" property="ledger.rounding" field-name="roundingMode"/> + <log level="info" message="Using ledger decimals [${ledgerDecimals}] and rounding [${roundingMode}]"/> + + <entity-and entity-name="ItemIssuance" list-name="itemIssuances"> + <field-map field-name="shipmentId" env-name="parameters.shipmentId"/> + </entity-and> + <iterate list-name="itemIssuances" entry-name="itemIssuance"> + <get-related-one value-name="itemIssuance" relation-name="OrderHeader" to-value-name="orderHeader"/> + <get-related-one value-name="itemIssuance" relation-name="InventoryItem" to-value-name="inventoryItem"/> + <!-- TODO: handle serialized inventory --> + <calculate field-name="origAmount" type="BigDecimal" decimal-scale="${ledgerDecimals}" rounding-mode="${roundingMode}"> + <calcop operator="multiply"> + <calcop operator="get" field-name="itemIssuance.quantity"/> + <calcop operator="get" field-name="inventoryItem.unitCost"/> + </calcop> + </calculate> + <!-- Credit --> + <make-value entity-name="AcctgTransEntry" value-name="creditEntry"/> + <set field="creditEntry.debitCreditFlag" value="C"/> + <set field="creditEntry.glAccountTypeId" value="INVENTORY_ACCOUNT"/> + <set field="creditEntry.organizationPartyId" from-field="inventoryItem.ownerPartyId"/> + <set field="creditEntry.productId" from-field="inventoryItem.productId"/> + <set field="creditEntry.origAmount" from-field="origAmount"/> + <set field="creditEntry.origCurrencyUomId" from-field="inventoryItem.currencyUomId"/> + <!-- TODO: roleId, partyId --> + <!-- Debit --> + <make-value entity-name="AcctgTransEntry" value-name="debitEntry"/> + <set field="debitEntry.debitCreditFlag" value="D"/> + <set field="debitEntry.glAccountTypeId" value="COGS_ACCOUNT"/> + <set field="debitEntry.organizationPartyId" from-field="inventoryItem.ownerPartyId"/> + <set field="debitEntry.productId" from-field="inventoryItem.productId"/> + <set field="debitEntry.origAmount" from-field="origAmount"/> + <set field="debitEntry.origCurrencyUomId" from-field="inventoryItem.currencyUomId"/> + <!-- TODO: roleId, partyId --> + <set field="acctgTransEntries[]" from-field="creditEntry" type="Object"/> + <set field="acctgTransEntries[]" from-field="debitEntry" type="Object"/> + </iterate> + <set field="createAcctgTransAndEntriesInMap.glFiscalTypeId" value="ACTUAL"/> + <set field="createAcctgTransAndEntriesInMap.acctgTransTypeId" value="SALES_SHIPMENT"/> + <set field="createAcctgTransAndEntriesInMap.shipmentId" from-field="parameters.shipmentId"/> + <set field="createAcctgTransAndEntriesInMap.acctgTransEntries" from-field="acctgTransEntries"/> + <call-service service-name="createAcctgTransAndEntries" in-map-name="createAcctgTransAndEntriesInMap"> + <result-to-field result-name="acctgTransId"/> + </call-service> + <field-to-result field-name="acctgTransId" result-name="acctgTransId"/> + </simple-method> + </simple-methods> Added: ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml?rev=598582&view=auto ============================================================================== --- ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml (added) +++ ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml Tue Nov 27 02:05:02 2007 @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<service-eca xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/service-eca.xsd"> + + <!-- create the accounting transactions for a sales shipment when the status changes to SHIPMENT_PACKED --> + <eca service="updateShipment" event="commit"> + <condition field-name="shipmentTypeId" operator="equals" value="SALES_SHIPMENT"/> + <condition-field field-name="statusId" operator="not-equals" to-field-name="oldStatusId"/> + <condition field-name="statusId" operator="equals" value="SHIPMENT_PACKED"/> + <action service="createAcctgTransForSalesShipment" mode="sync"/> + </eca> + +</service-eca> Propchange: ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Modified: ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml?rev=598582&r1=598581&r2=598582&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml (original) +++ ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml Tue Nov 27 02:05:02 2007 @@ -207,7 +207,6 @@ <auto-attributes include="nonpk" mode="IN" optional="true"> <exclude field-name="reconcileStatusId"/> </auto-attributes> - <override name="acctgTransEntryTypeId" optional="false"/> <override name="glAccountId" optional="false"/> <override name="organizationPartyId" optional="false"/> <override name="amount" optional="false"/> @@ -294,4 +293,14 @@ <auto-attributes include="pk" mode="IN" optional="false"/> <attribute name="ownerPartyId" type="String" mode="OUT" optional="false"/> </service> + + <!-- Services for the automatic creation of accounting transactions based on business transactions + Typically, these services are triggered by SECAs --> + <service name="createAcctgTransForSalesShipment" engine="simple" auth="true" + location="org/ofbiz/accounting/ledger/GeneralLedgerServices.xml" invoke="createAcctgTransForSalesShipment"> + <description>Create accounting transactions for issuances for a sales shipment (D: INVENTORY_ACCOUNT, C: COGS_ACCOUNT)</description> + <attribute name="shipmentId" type="String" mode="IN" optional="false"/> + <attribute name="acctgTransId" type="String" mode="OUT" optional="true"/> + </service> + </services> |
Free forum by Nabble | Edit this page |