You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ap...@apache.org on 2010/09/23 22:59:05 UTC

svn commit: r1000621 - in /ofbiz/trunk/applications/accounting: data/ script/org/ofbiz/accounting/invoice/ script/org/ofbiz/accounting/ledger/ servicedef/

Author: apatel
Date: Thu Sep 23 20:59:05 2010
New Revision: 1000621

URL: http://svn.apache.org/viewvc?rev=1000621&view=rev
Log:
Fix bug in Gl posting Customer Return Invoice. It was handled as a purchase invoice when its totally different beast. All InvoiceTypes from PURCHASE_INVOICE type tree are still handled like always except for CUST_RTN_INVOICE. Added new service to handle CUST_RTN_INVOICE.

Modified:
    ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
    ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml
    ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml
    ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml
    ofbiz/trunk/applications/accounting/servicedef/services_invoice.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=1000621&r1=1000620&r2=1000621&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml (original)
+++ ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml Thu Sep 23 20:59:05 2010
@@ -45,6 +45,7 @@ under the License.
 
     <AcctgTransType acctgTransTypeId="SALES_INVOICE" description="Sales Invoice" hasTable="N" parentTypeId="OBLIGATION_ACCTG_TRA"/><!-- FIXME: replace with "SALES" -->
     <AcctgTransType acctgTransTypeId="PURCHASE_INVOICE" description="Purchase Invoice" hasTable="N" parentTypeId="OBLIGATION_ACCTG_TRA"/><!-- FIXME: replace with "SALES" -->
+    <AcctgTransType acctgTransTypeId="CUST_RTN_INVOICE" description="Customer Return" hasTable="N" parentTypeId="OBLIGATION_ACCTG_TRA"/><!-- FIXME: replace with "SALES" -->
     <AcctgTransType acctgTransTypeId="SALES_SHIPMENT" description="Sales Shipment" hasTable="N" parentTypeId="EXTERNAL_ACCTG_TRANS"/>
     <AcctgTransType acctgTransTypeId="SHIPMENT_RECEIPT" description="Shipment Receipt" hasTable="N" parentTypeId="EXTERNAL_ACCTG_TRANS"/>
     <AcctgTransType acctgTransTypeId="MANUFACTURING" description="Manufacturing" hasTable="N" parentTypeId=""/>

Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml?rev=1000621&r1=1000620&r2=1000621&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml (original)
+++ ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/invoice/InvoiceServices.xml Thu Sep 23 20:59:05 2010
@@ -455,6 +455,7 @@ under the License.
     <simple-method method-name="setInvoiceStatus" short-description="Set The Invoice Status">
         <entity-one entity-name="Invoice" value-field="invoice"/>
         <field-to-result field="invoice.statusId" result-name="oldStatusId"/>
+        <field-to-result field="invoice.invoiceTypeId" result-name="invoiceTypeId"/>
         <if-compare-field field="invoice.statusId" to-field="parameters.statusId" operator="not-equals">
             <entity-one entity-name="StatusValidChange" value-field="statusChange" auto-field-map="false">
                 <field-map field-name="statusId" from-field="invoice.statusId"/>

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=1000621&r1=1000620&r2=1000621&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 Thu Sep 23 20:59:05 2010
@@ -579,6 +579,10 @@ under the License.
                             <if-compare field="parameters.debitCreditFlag" operator="equals" value="D"/>
                         </and>
                         <and>
+                            <if-compare field="parameters.acctgTransTypeId" operator="equals" value="CUST_RTN_INVOICE"/>
+                            <if-compare field="parameters.debitCreditFlag" operator="equals" value="D"/>
+                        </and>
+                        <and>
                             <if-compare field="parameters.acctgTransTypeId" operator="equals" value="SALES_INVOICE"/>
                             <if-compare field="parameters.debitCreditFlag" operator="equals" value="C"/>
                         </and>
@@ -594,11 +598,16 @@ under the License.
                         <set field="parameters.glAccountTypeId" value="UNINVOICED_SHIP_RCPT"/>
                         <call-simple-method method-name="getGlAccountTypeDefaultInline"/>
                         <set field="glAccountTypeDefault" from-field="lookedUpValue"/>
-                    <else>
+                    </if-compare>
+                    <if-compare field="parameters.acctgTransTypeId" operator="equals" value="CUST_RTN_INVOICE">
+                        <set field="parameters.glAccountTypeId" value="SALES_RETURNS"/>
+                        <call-simple-method method-name="getGlAccountTypeDefaultInline"/>
+                        <set field="glAccountTypeDefault" from-field="lookedUpValue"/>
+                    </if-compare>
+                    <if-compare field="parameters.acctgTransTypeId" operator="equals" value="SALES_INVOICE">
                         <set field="parameters.glAccountTypeId" value="SALES_ACCOUNT"/>
                         <call-simple-method method-name="getGlAccountTypeDefaultInline"/>
                         <set field="glAccountTypeDefault" from-field="lookedUpValue"/>
-                    </else>
                     </if-compare>
                     <if-not-empty field="glAccountTypeDefault.glAccountId">
                         <field-to-result field="glAccountTypeDefault.glAccountId" result-name="glAccountId"/>
@@ -1877,6 +1886,130 @@ under the License.
         </if-compare>
     </simple-method>
 
+    <simple-method method-name="createAcctgTransForCustomerReturnInvoice" short-description="Create an accounting transaction for a Customer Return Invoice">
+        <!-- retrieve ledger rounding properties -->
+        <call-simple-method method-name="getGlArithmeticSettingsInline"/>
+
+        <entity-one entity-name="Invoice" value-field="invoice"/>
+        <get-related-one value-field="invoice" relation-name="InvoiceType" to-value-field="invoiceType"/>
+        <!-- Check invoiceTypeId. This service works only for CustomerReturns -->
+        <if-compare field="invoiceType.invoiceTypeId" operator="equals" value="CUST_RTN_INVOICE">
+            <set field="totalAmountFromInvoice" type="BigDecimal" value="0"/>
+            <set field="transPartyRoleTypeId" value="BILL_TO_CUSTOMER"/>
+            <set field="acctgTransTypeId" value="CUST_RTN_INVOICE"/>
+            <entity-condition entity-name="InvoiceItem" list="invoiceItems" use-cache="true">
+                <condition-list>
+                    <condition-expr field-name="invoiceItemTypeId" operator="not-equals" value="PINV_SALES_TAX"/>
+                    <condition-expr field-name="invoiceItemTypeId" operator="not-equals" value="PITM_SALES_TAX"/>
+                    <condition-expr field-name="invoiceId" operator="equals" from-field="parameters.invoiceId"/>
+                </condition-list>
+            </entity-condition>
+
+            <iterate list="invoiceItems" entry="invoiceItem">
+                <set field="amountFromOrder" type="BigDecimal" value="0"/>
+                <set field="amountFromInvoice" type="BigDecimal" value="0"/>
+                <if-empty field="invoiceItem.quantity">
+                    <set field="invoiceItem.quantity" value="1"/>
+                </if-empty>
+                <!-- This InvoiceItem amount. -->
+                <calculate field="amountFromInvoice"  decimal-scale="${ledgerDecimals}" rounding-mode="${roundingMode}">
+                    <calcop operator="multiply">
+                        <calcop operator="get" field="invoiceItem.quantity"/>
+                        <calcop operator="get" field="invoiceItem.amount"/>
+                    </calcop>
+                </calculate>
+                <!-- Keep building Invoice Total for use in credit entry -->
+                <calculate field="totalAmountFromInvoice" decimal-scale="${ledgerDecimals}" rounding-mode="${roundingMode}">
+                    <calcop operator="add">
+                        <calcop operator="get" field="totalAmountFromInvoice"/>
+                        <calcop operator="get" field="amountFromInvoice"/>
+                    </calcop>
+                </calculate>
+                <!-- Debit -->
+                <make-value entity-name="AcctgTransEntry" value-field="debitEntry"/>
+                <set field="debitEntry.debitCreditFlag" value="D"/>
+                <set field="debitEntry.organizationPartyId" from-field="invoice.partyId"/>
+                <set field="debitEntry.partyId" from-field="invoice.partyIdFrom"/>
+                <set field="debitEntry.roleTypeId" from-field="transPartyRoleTypeId"/>
+                <set field="debitEntry.productId" from-field="invoiceItem.productId"/>
+                <set field="debitEntry.glAccountTypeId" from-field="invoiceItem.invoiceItemTypeId"/>
+                <set field="debitEntry.glAccountId" from-field="invoiceItem.overrideGlAccountId"/>
+                <set field="debitEntry.origAmount" from-field="amountFromInvoice"/>
+                <set field="debitEntry.origCurrencyUomId" from-field="invoice.currencyUomId"/>
+                <set field="acctgTransEntries[]" from-field="debitEntry" type="Object"/>
+            </iterate>
+            <!-- debit entry for SALES_TAX-->
+            <call-class-method method-name="getInvoiceTaxAuthPartyAndGeos" class-name="org.ofbiz.accounting.invoice.InvoiceWorker"
+                  ret-field="taxAuthPartyAndGeos">
+                <field field="invoice" type="org.ofbiz.entity.GenericValue"/>
+            </call-class-method>
+            <iterate-map key="taxAuthPartyId" value="taxAuthGeoIds" map="taxAuthPartyAndGeos">
+                <iterate entry="taxAuthGeoId" list="taxAuthGeoIds">
+                    <clear-field field="debitEntry"/>
+                    <make-value entity-name="AcctgTransEntry" value-field="debitEntry"/>
+                    <set field="debitEntry.debitCreditFlag" value="D"/>
+                    <set field="debitEntry.organizationPartyId" from-field="invoice.partyIdFrom"/>
+                    <call-class-method method-name="getInvoiceTaxTotalForTaxAuthPartyAndGeo" class-name="org.ofbiz.accounting.invoice.InvoiceWorker"
+                            ret-field="taxAmount">
+                        <field field="invoice" type="GenericValue"/>
+                        <field field="taxAuthPartyId" type="String"/>
+                        <field field="taxAuthGeoId" type="String"/>
+                    </call-class-method>
+                    <set field="debitEntry.origAmount" from-field="taxAmount"/>
+                    <set field="debitEntry.origCurrencyUomId" from-field="invoice.currencyUomId"/>
+                    <set field="debitEntry.partyId" from-field="taxAuthPartyId"/>
+                    <set field="debitEntry.roleTypeId" value="TAX_AUTHORITY"/>
+                    <set field="acctgTransEntries[]" from-field="debitEntry" type="Object"/>
+                </iterate>
+            </iterate-map>
+            <!-- Another entry for tax not attributed to a taxAuthPartyId -->
+            <clear-field field="debitEntry"/>
+            <make-value entity-name="AcctgTransEntry" value-field="debitEntry"/>
+            <set field="debitEntry.debitCreditFlag" value="D"/>
+            <set field="debitEntry.organizationPartyId" from-field="invoice.partyIdFrom"/>
+            <call-class-method method-name="getInvoiceUnattributedTaxTotal" class-name="org.ofbiz.accounting.invoice.InvoiceWorker"
+                    ret-field="taxAmount">
+                <field field="invoice" type="GenericValue"/>
+            </call-class-method>
+            <set field="debitEntry.origAmount" from-field="taxAmount"/>
+            <set field="debitEntry.origCurrencyUomId" from-field="invoice.currencyUomId"/>
+            <set field="acctgTransEntries[]" from-field="debitEntry" type="Object"/>
+
+            <!-- Credit -->
+            <make-value entity-name="AcctgTransEntry" value-field="creditEntry"/>
+            <set field="creditEntry.debitCreditFlag" value="C"/>
+            <set field="creditEntry.organizationPartyId" from-field="invoice.partyId"/>
+            <set field="creditEntry.glAccountTypeId" value="ACCOUNTS_PAYABLE"/>
+            <calculate field="totalAmountFromInvoice" type="BigDecimal" decimal-scale="${ledgerDecimals}" rounding-mode="${roundingMode}">
+                <calcop operator="add">
+                    <calcop operator="get" field="totalAmountFromInvoice"/>
+                    <calcop operator="get" field="invoiceTaxTotal"/>
+                </calcop>
+            </calculate>
+            <set field="creditEntry.origAmount" from-field="totalAmountFromInvoice"/>
+            <set field="creditEntry.origCurrencyUomId" from-field="invoice.currencyUomId"/>
+            <set field="creditEntry.partyId" from-field="invoice.partyIdFrom"/>
+            <set field="creditEntry.roleTypeId" from-field="transPartyRoleTypeId"/>
+            <set field="acctgTransEntries[]" from-field="creditEntry" type="Object"/>
+
+            <!-- Set header fields (AcctgTrans) -->
+            <set field="createAcctgTransAndEntriesInMap.glFiscalTypeId" value="ACTUAL"/>
+            <set field="createAcctgTransAndEntriesInMap.acctgTransTypeId" from-field="acctgTransTypeId"/>
+            <set field="createAcctgTransAndEntriesInMap.invoiceId" from-field="invoice.invoiceId"/>
+            <set field="createAcctgTransAndEntriesInMap.partyId" from-field="invoice.partyIdFrom"/>
+            <set field="createAcctgTransAndEntriesInMap.roleTypeId" value="BILL_FROM_VENDOR"/>
+            <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="acctgTransId" result-name="acctgTransId"/>
+        <else>
+            <!-- This invoice is not a Customer Return. Return error -->
+            <add-error><fail-message message="Bad invoiceTypeId [${invoiceType.invoiceTypeId}]. Service createAcctgTransForCustomerReturnInvoice for type CUST_RTN_INVOICE."/></add-error>
+        </else>
+        </if-compare>
+    </simple-method>
+
     <!-- Service for the automatic creation of accounting transaction for Purchase Invoice -->
     <simple-method method-name="createAcctgTransForPurchaseInvoice" short-description="Create an accounting transaction for a purchase invoice">
         <!-- retrieve ledger rounding properties -->

Modified: ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml?rev=1000621&r1=1000620&r2=1000621&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml (original)
+++ ofbiz/trunk/applications/accounting/servicedef/secas_ledger.xml Thu Sep 23 20:59:05 2010
@@ -86,6 +86,7 @@ under the License.
     <!-- accounting transactions for Purchase (AP) and Sales Invoices (AR) -->
     <eca service="setInvoiceStatus" event="commit">
         <condition field-name="invoiceId" operator="is-not-empty"/>
+        <condition field-name="invoiceTypeId" operator="not-equals" value="CUST_RTN_INVOICE"/>
         <condition field-name="statusId" operator="equals" value="INVOICE_READY"/>
         <condition field-name="oldStatusId" operator="not-equals" value="INVOICE_READY"/>
         <condition field-name="oldStatusId" operator="not-equals" value="INVOICE_PAID"/>
@@ -94,6 +95,14 @@ under the License.
     </eca>
     <eca service="setInvoiceStatus" event="commit">
         <condition field-name="invoiceId" operator="is-not-empty"/>
+        <condition field-name="invoiceTypeId" operator="equals" value="CUST_RTN_INVOICE"/>
+        <condition field-name="statusId" operator="equals" value="INVOICE_READY"/>
+        <condition field-name="oldStatusId" operator="not-equals" value="INVOICE_READY"/>
+        <condition field-name="oldStatusId" operator="not-equals" value="INVOICE_PAID"/>
+        <action service="createAcctgTransForCustomerReturnInvoice" mode="sync"/>
+    </eca>
+    <eca service="setInvoiceStatus" event="commit">
+        <condition field-name="invoiceId" operator="is-not-empty"/>
         <condition field-name="statusId" operator="equals" value="INVOICE_CANCELLED"/>
         <action service="cancelInvoice" mode="sync"/>
     </eca>

Modified: ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml?rev=1000621&r1=1000620&r2=1000621&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml (original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_invoice.xml Thu Sep 23 20:59:05 2010
@@ -92,6 +92,7 @@ under the License.
         <attribute name="statusId" type="String" mode="IN" optional="false"/>
         <attribute name="statusDate" type="Timestamp" mode="IN" optional="true"/>
         <attribute name="paidDate" type="Timestamp" mode="IN" optional="true"/> <!-- only relevant for changes to PAID -->
+        <attribute name="invoiceTypeId" type="String" mode="OUT" optional="true"/>
         <attribute name="oldStatusId" type="String" mode="OUT" optional="true"/>
     </service>
     <service name="copyInvoiceToTemplate" engine="simple"

Modified: ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml?rev=1000621&r1=1000620&r2=1000621&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml (original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml Thu Sep 23 20:59:05 2010
@@ -453,6 +453,14 @@ under the License.
         <attribute name="acctgTransId" type="String" mode="OUT" optional="true"/>
     </service>
 
+    <!-- An automatic GL Posting for Customer Return Invoice-->
+    <service name="createAcctgTransForCustomerReturnInvoice" engine="simple" auth="true"
+        location="component://accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml" invoke="createAcctgTransForCustomerReturnInvoice">
+        <description>Create an accounting transaction for a Customer Return invoice</description>
+        <attribute name="invoiceId" type="String" mode="IN" optional="false"/>
+        <attribute name="acctgTransId" type="String" mode="OUT" optional="true"/>
+    </service>
+
     <!-- An automatic GL Posting for Purchase Invoice-->
     <service name="createAcctgTransForPurchaseInvoice" engine="simple" auth="true"
         location="component://accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml" invoke="createAcctgTransForPurchaseInvoice">