Skip to content

Commit

Permalink
[13.0] [FIX] account_invoice_move_currency: Write the values after ca…
Browse files Browse the repository at this point in the history
…ll super
  • Loading branch information
nicomacr committed Jan 7, 2021
1 parent e3054ab commit 54f8495
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion account_invoice_move_currency/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
'name': 'Account Invoice Move Currency',
'version': '13.0.1.1.0',
'version': '13.0.1.2.0',
'author': 'ADHOC SA',
'category': 'Accounting & Finance',
'depends': [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from openupgradelib import openupgrade


@openupgrade.migrate(use_env=True)
def migrate(env, version):
# recalculate amount_currency for validated invoices and with another currency
for line in env['account.move.line'].search(
[('move_id.move_currency_id', '!=', False),
('account_id.user_type_id.type', 'in', ('receivable', 'payable')),
('currency_id', '=', False)]):
amount = line.debit if line.debit else line.credit
sign = 1.0 if line.debit else -1.0
line.write({
'currency_id': line.move_id.move_currency_id.id,
'amount_currency': sign * line.move_id.move_currency_id.round(
amount / line.move_id.move_inverse_currency_rate)})
4 changes: 2 additions & 2 deletions account_invoice_move_currency/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def post(self):
""" para no tener que mandar el move currency en el context o hacer tmb onchanges nos la simpificamos y solo
lo computamos en el post. Algo similar pasa tambien en odoo nativo, si bien a priroi se setea la currency_id
(cuando la factura es en otra moneda) se puede forzar que no pase y luego se setea en el post"""

res = super().post()
for rec in self.filtered('move_currency_id'):
if not rec.move_inverse_currency_rate:
raise UserError(_('If Secondary currency select you must set rate. Check invoice id: %s') % rec.id)
Expand All @@ -84,4 +84,4 @@ def post(self):
sign = 1.0 if line.debit else -1.0
line.currency_id = self.move_currency_id.id
line.amount_currency = sign * self.move_currency_id.round(amount / self.move_inverse_currency_rate)
return super().post()
return res

0 comments on commit 54f8495

Please sign in to comment.