Skip to content

Commit

Permalink
Merge pull request #102 from grindtildeath/10.0_fix_revaluation_label…
Browse files Browse the repository at this point in the history
…_rate

[10.0] account_multicurrency_revaluation: Fixes and improvements
  • Loading branch information
yvaucher committed Apr 16, 2019
2 parents dffa153 + 82056c3 commit e1f2949
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 45 deletions.
1 change: 0 additions & 1 deletion account_multicurrency_revaluation/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from . import res_company
from . import account
from . import res_currency
from . import res_config
32 changes: 0 additions & 32 deletions account_multicurrency_revaluation/model/res_currency.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_uk_revaluation(self):
data = {
'revaluation_date': '2017-03-15',
'journal_id': self.reval_journal.id,
'label': '[%(account)s] wiz_test',
'label': '[%(account)s, %(rate)s] wiz_test',
}
wiz = wizard.create(data)
result = wiz.revaluate_currency()
Expand All @@ -42,6 +42,11 @@ def test_uk_revaluation(self):
self.assertEquals(len(reval_move_lines), 8)

for reval_line in reval_move_lines:

label = reval_line.name
rate = label[label.find(',') + 1:label.find(']')].strip()
self.assertEqual(rate, '2.5')

if reval_line.account_id.name == 'Account Liquidity USD':
self.assertFalse(reval_line.partner_id)
self.assertEquals(reval_line.credit, 0.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def _get_default_journal_id(self):
"%(rate)s currency revaluation"
)

@api.model
def _compute_unrealized_currency_gl(self, currency_id, balances, form):
@api.multi
def _compute_unrealized_currency_gl(self, currency_id, balances):
"""
Update data dict with the unrealized currency gain and loss
plus add 'currency_rate' which is the value used for rate in
Expand All @@ -65,22 +65,18 @@ def _compute_unrealized_currency_gl(self, currency_id, balances, form):

# Compute unrealized gain loss
ctx_rate = context.copy()
ctx_rate['date'] = form.revaluation_date
cp_currency = form.journal_id.company_id.currency_id
ctx_rate['date'] = self.revaluation_date
cp_currency = self.journal_id.company_id.currency_id

currency = currency_obj.browse(currency_id)
currency = currency_obj.browse(currency_id).with_context(ctx_rate)

foreign_balance = adjusted_balance = balances.get(
'foreign_balance', 0.0)
balance = balances.get('balance', 0.0)
unrealized_gain_loss = 0.0
if foreign_balance:
ctx_rate['revaluation'] = True
adjusted_balance = currency.with_context(ctx_rate).compute(
foreign_balance, cp_currency
)
adjusted_balance = currency.compute(foreign_balance, cp_currency)
unrealized_gain_loss = adjusted_balance - balance
# revaluated_balance = balance + unrealized_gain_loss
else:
if balance:
if currency_id != cp_currency.id:
Expand Down Expand Up @@ -290,7 +286,8 @@ def revaluate_currency(self):
# Update sums with compute amount currency balance
diff_balances = self._compute_unrealized_currency_gl(
currency_id,
sums, self)
sums
)
account_sums[account_id][currency_id][partner_id].\
update(diff_balances)

Expand Down

0 comments on commit e1f2949

Please sign in to comment.