Author: jacopoc
Date: Fri Jan 30 10:44:44 2015
New Revision: 1655979
URL: http://svn.apache.org/r1655979
Log:
Implemented missing code to properly handle accounting transactions for foreign
currency converion rates gain/losses.
Modified:
ofbiz/trunk/applications/accounting/data/DemoGlSetupData.xml
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java
Modified: ofbiz/trunk/applications/accounting/data/DemoGlSetupData.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/data/DemoGlSetupData.xml?rev=1655979&r1=1655978&r2=1655979&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/data/DemoGlSetupData.xml (original)
+++ ofbiz/trunk/applications/accounting/data/DemoGlSetupData.xml Fri Jan 30
10:44:44 2015
@@ -312,6 +312,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/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=1655979&r1=1655978&r2=1655979&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
Fri Jan 30 10:44:44 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/trunk/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java?rev=1655979&r1=1655978&r2=1655979&view=diff
==============================================================================
---
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java
(original)
+++
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java
Fri Jan 30 10:44:44 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;
+ }
+
}