You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2015/01/30 11:49:37 UTC

svn commit: r1655981 - in /ofbiz/branches/release14.12: ./ applications/accounting/data/ applications/accounting/script/org/ofbiz/accounting/ledger/ applications/accounting/src/org/ofbiz/accounting/util/

Author: jacopoc
Date: Fri Jan 30 10:49:37 2015
New Revision: 1655981

URL: http://svn.apache.org/r1655981
Log:
Applied fix from trunk for revision: 1655979 
===

Implemented missing code to properly handle accounting transactions for foreign currency converion rates gain/losses.



Modified:
    ofbiz/branches/release14.12/   (props changed)
    ofbiz/branches/release14.12/applications/accounting/data/DemoGlSetupData.xml
    ofbiz/branches/release14.12/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml
    ofbiz/branches/release14.12/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java

Propchange: ofbiz/branches/release14.12/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jan 30 10:49:37 2015
@@ -8,4 +8,4 @@
 /ofbiz/branches/json-integration-refactoring:1634077-1635900
 /ofbiz/branches/multitenant20100310:921280-927264
 /ofbiz/branches/release13.07:1547657
-/ofbiz/trunk:1649393,1649742,1650240,1650583,1650642,1650678,1650882,1650887,1650938,1651593,1652361,1652706,1652725,1652731,1652739,1653248,1653456,1654175,1654273,1655046,1655668
+/ofbiz/trunk:1649393,1649742,1650240,1650583,1650642,1650678,1650882,1650887,1650938,1651593,1652361,1652706,1652725,1652731,1652739,1653248,1653456,1654175,1654273,1655046,1655668,1655979

Modified: ofbiz/branches/release14.12/applications/accounting/data/DemoGlSetupData.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/accounting/data/DemoGlSetupData.xml?rev=1655981&r1=1655980&r2=1655981&view=diff
==============================================================================
--- ofbiz/branches/release14.12/applications/accounting/data/DemoGlSetupData.xml (original)
+++ ofbiz/branches/release14.12/applications/accounting/data/DemoGlSetupData.xml Fri Jan 30 10:49:37 2015
@@ -310,6 +310,7 @@ under the License.
     <GlAccountTypeDefault organizationPartyId="Company" glAccountTypeId="SALES_ACCOUNT" glAccountId="400000"/>
     <GlAccountTypeDefault organizationPartyId="Company" glAccountTypeId="COGS_ACCOUNT" glAccountId="500000"/>
     <GlAccountTypeDefault organizationPartyId="Company" glAccountTypeId="INV_ADJ_VAL" glAccountId="515000"/>
+    <GlAccountTypeDefault organizationPartyId="Company" glAccountTypeId="FX_GAIN_LOSS_ACCT" glAccountId="518000"/>
     <GlAccountTypeDefault organizationPartyId="Company" glAccountTypeId="OPERATING_EXPENSE" glAccountId="600000"/>
     <GlAccountTypeDefault organizationPartyId="Company" glAccountTypeId="PROFIT_LOSS_ACCOUNT" glAccountId="850000"/>
     <GlAccountTypeDefault organizationPartyId="Company" glAccountTypeId="TAX_ACCOUNT" glAccountId="900000"/>

Modified: ofbiz/branches/release14.12/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml?rev=1655981&r1=1655980&r2=1655981&view=diff
==============================================================================
--- ofbiz/branches/release14.12/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml (original)
+++ ofbiz/branches/release14.12/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml Fri Jan 30 10:49:37 2015
@@ -2582,12 +2582,38 @@ under the License.
             <set field="creditEntry.glAccountId" from-field="payment.overrideGlAccountId"/>
             <set field="creditEntry.glAccountTypeId" from-field="paymentGlAccountTypeMap.glAccountTypeId"/>
             <!-- Debit -->
+            <call-class-method class-name="org.ofbiz.accounting.util.UtilAccounting" method-name="getGlExchangeRateOfPurchaseInvoice" ret-field="invoiceExchangeRate">
+                <field field="paymentApplication" type="org.ofbiz.entity.GenericValue"/>
+            </call-class-method>
+            <call-class-method class-name="org.ofbiz.accounting.util.UtilAccounting" method-name="getGlExchangeRateOfOutgoingPayment" ret-field="paymentExchangeRate">
+                <field field="paymentApplication" type="org.ofbiz.entity.GenericValue"/>
+            </call-class-method>
+            <make-value entity-name="AcctgTransEntry" value-field="debitEntry"/>
+            <if-compare-field field="invoiceExchangeRate" operator="not-equals" to-field="paymentExchangeRate">
+                <set field="debitEntry.debitCreditFlag" value="D"/>
+                <set field="debitEntry.organizationPartyId" from-field="payment.partyIdFrom"/>
+                <set field="debitEntry.partyId" from-field="payment.partyIdTo"/>
+                <set field="debitEntry.roleTypeId" value="BILL_FROM_VENDOR"/>
+                <set field="debitEntry.amount" value="${paymentApplication.amountApplied * (paymentExchangeRate - invoiceExchangeRate)}"/>
+                <set field="debitEntry.origCurrencyUomId" from-field="payment.currencyUomId"/>
+                <!--
+                <entity-one entity-name="GlAccountTypeDefault" value-field="currencyExchangeRateGainLossAccount" use-cache="true">
+                    <field-map field-name="organizationPartyId" from-field="parameters.organizationPartyId"/>
+                    <field-map field-name="glAccountTypeId" value="FX_GAIN_LOSS_ACCT"/>
+                </entity-one>
+                <set field="debitEntry.glAccountId" from-field="currencyExchangeRateGainLossAccount.glAccountId"/>
+                -->
+                <set field="debitEntry.glAccountTypeId" value="FX_GAIN_LOSS_ACCT"/>
+                <set field="acctgTransEntries[]" from-field="debitEntry" type="Object"/>
+                <clear-field field="debitEntry"/>
+            </if-compare-field>
             <make-value entity-name="AcctgTransEntry" value-field="debitEntry"/>
             <set field="debitEntry.debitCreditFlag" value="D"/>
             <set field="debitEntry.organizationPartyId" from-field="payment.partyIdFrom"/>
             <set field="debitEntry.partyId" from-field="payment.partyIdTo"/>
             <set field="debitEntry.roleTypeId" value="BILL_FROM_VENDOR"/>
             <set field="debitEntry.origAmount" from-field="paymentApplication.amountApplied"/>
+            <set field="debitEntry.amount" value="${paymentApplication.amountApplied * invoiceExchangeRate}"/>
             <set field="debitEntry.origCurrencyUomId" from-field="payment.currencyUomId"/>
             <set field="debitEntry.glAccountTypeId" value="ACCOUNTS_PAYABLE"/>
             <if-not-empty field="paymentApplication.overrideGlAccountId">

Modified: ofbiz/branches/release14.12/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java?rev=1655981&r1=1655980&r2=1655981&view=diff
==============================================================================
--- ofbiz/branches/release14.12/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java (original)
+++ ofbiz/branches/release14.12/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java Fri Jan 30 10:49:37 2015
@@ -19,14 +19,20 @@
 
 package org.ofbiz.accounting.util;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 import javolution.util.FastList;
 
 import org.ofbiz.accounting.AccountingException;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilNumber;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.condition.EntityJoinOperator;
 import org.ofbiz.entity.util.EntityQuery;
 
 
@@ -288,4 +294,46 @@ public class UtilAccounting {
         return isInvoiceType(invoice, "TEMPLATE");
     }
 
+    public static BigDecimal getGlExchangeRateOfPurchaseInvoice(GenericValue paymentApplication) throws GenericEntityException {
+        BigDecimal exchangeRate = BigDecimal.ONE;
+        Delegator delegator = paymentApplication.getDelegator();
+        List andConditions = UtilMisc.toList(
+                EntityCondition.makeCondition("glAccountTypeId", "ACCOUNTS_PAYABLE"),
+                EntityCondition.makeCondition("debitCreditFlag", "C"),
+                EntityCondition.makeCondition("acctgTransTypeId", "PURCHASE_INVOICE"),
+                EntityCondition.makeCondition("invoiceId", paymentApplication.getString("invoiceId")));
+        EntityCondition whereCondition = EntityCondition.makeCondition(andConditions, EntityJoinOperator.AND);
+        GenericValue amounts = EntityQuery.use(delegator).select("origAmount", "amount").from("AcctgTransAndEntries").where(whereCondition).queryFirst();
+        if (amounts == null) {
+            return exchangeRate;
+        }
+        BigDecimal origAmount = amounts.getBigDecimal("origAmount");
+        BigDecimal amount = amounts.getBigDecimal("amount");
+        if (origAmount != null && amount != null && BigDecimal.ZERO.compareTo(origAmount) != 0 && BigDecimal.ZERO.compareTo(amount) != 0 && amount.compareTo(origAmount) != 0) {
+            exchangeRate = amount.divide(origAmount, UtilNumber.getBigDecimalScale("ledger.decimals"), UtilNumber.getBigDecimalRoundingMode("invoice.rounding"));
+        }
+        return exchangeRate;
+    }
+
+    public static BigDecimal getGlExchangeRateOfOutgoingPayment(GenericValue paymentApplication) throws GenericEntityException {
+        BigDecimal exchangeRate = BigDecimal.ONE;
+        Delegator delegator = paymentApplication.getDelegator();
+        List andConditions = UtilMisc.toList(
+                EntityCondition.makeCondition("glAccountTypeId", "CURRENT_ASSET"),
+                EntityCondition.makeCondition("debitCreditFlag", "C"),
+                EntityCondition.makeCondition("acctgTransTypeId", "OUTGOING_PAYMENT"),
+                EntityCondition.makeCondition("paymentId", paymentApplication.getString("paymentId")));
+        EntityCondition whereCondition = EntityCondition.makeCondition(andConditions, EntityJoinOperator.AND);
+        GenericValue amounts = EntityQuery.use(delegator).select("origAmount", "amount").from("AcctgTransAndEntries").where(whereCondition).queryFirst();
+        if (amounts == null) {
+            return exchangeRate;
+        }
+        BigDecimal origAmount = amounts.getBigDecimal("origAmount");
+        BigDecimal amount = amounts.getBigDecimal("amount");
+        if (origAmount != null && amount != null && BigDecimal.ZERO.compareTo(origAmount) != 0 && BigDecimal.ZERO.compareTo(amount) != 0 && amount.compareTo(origAmount) != 0) {
+            exchangeRate = amount.divide(origAmount, UtilNumber.getBigDecimalScale("ledger.decimals"), UtilNumber.getBigDecimalRoundingMode("invoice.rounding"));
+        }
+        return exchangeRate;
+    }
+
 }