diff --git a/account_invoice_show_currency_rate/README.rst b/account_invoice_show_currency_rate/README.rst index ff3af9edca9..833b960ed73 100644 --- a/account_invoice_show_currency_rate/README.rst +++ b/account_invoice_show_currency_rate/README.rst @@ -28,9 +28,15 @@ Account Invoice Show Currency Rate |badge1| |badge2| |badge3| |badge4| |badge5| -This module shows the currency rate applied in invoices, so you can -visually verify what is going to be applied for the exchange, or which -one was applied once converted to company currency. +Since V18, Odoo shows the currency rate applied to invoices. Also, it +computes the currency rate on journal items by simply looking at the +rates configured in the system, but it does not display it. + +This module shows the currency rate on journal items, useful for other +entries that are not invoices, as well as entries containing lines with +multiple currencies. Furthermore, it ensures that the currency rate on +journal items is based on the actual amount in the journal item's +currency, as this can be manually modified by the user. **Table of contents** @@ -96,6 +102,10 @@ Contributors - Pedro M. Baeza - Víctor Martínez +- `ForgeFlow `__: + + - Jordi Masvidal + Maintainers ----------- diff --git a/account_invoice_show_currency_rate/__manifest__.py b/account_invoice_show_currency_rate/__manifest__.py index 3513d3e4832..01d9ac2e304 100644 --- a/account_invoice_show_currency_rate/__manifest__.py +++ b/account_invoice_show_currency_rate/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Account Invoice Show Currency Rate", "summary": "Show currency rate in invoices.", - "version": "17.0.1.0.0", + "version": "18.0.1.0.0", "category": "Accounting & Finance", "website": "https://github.com/OCA/account-invoicing", "author": "Tecnativa, Odoo Community Association (OCA)", diff --git a/account_invoice_show_currency_rate/models/account_move.py b/account_invoice_show_currency_rate/models/account_move.py index 78f54b9943d..f367e9e14d0 100644 --- a/account_invoice_show_currency_rate/models/account_move.py +++ b/account_invoice_show_currency_rate/models/account_move.py @@ -1,96 +1,57 @@ # Copyright 2021 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import api, fields, models +from odoo import api, models class AccountMove(models.Model): _inherit = "account.move" - currency_rate_amount = fields.Float( - string="Rate amount", - compute="_compute_currency_rate_amount", - digits=0, - ) - show_currency_rate_amount = fields.Boolean( - compute="_compute_show_currency_rate_amount", readonly=True - ) - @api.depends( + "currency_id", + "company_currency_id", + "company_id", + "invoice_date", "state", - "date", "line_ids.amount_currency", "line_ids.balance", - "company_id", - "currency_id", - "show_currency_rate_amount", ) - def _compute_currency_rate_amount(self): - """It's necessary to define value according to some cases: - - Case A: Currency is equal to company currency (Value = 1) - - Case B: Move exist previously (posted) and get real rate according to lines - - Case C: Get expected rate (according to date) to show some value in creation. - """ - self.currency_rate_amount = 1 - for item in self.filtered("show_currency_rate_amount"): - lines = item.line_ids.filtered(lambda x: abs(x.amount_currency) > 0) - if item.state == "posted" and lines: - amount_currency_positive = sum( - [abs(amc) for amc in lines.mapped("amount_currency")] - ) - total_balance_positive = sum([abs(b) for b in lines.mapped("balance")]) - item.currency_rate_amount = item.currency_id.round( - amount_currency_positive / total_balance_positive - ) - else: - rates = item.currency_id._get_rates(item.company_id, item.date) - item.currency_rate_amount = rates.get(item.currency_id.id) - - @api.depends("currency_id", "currency_id.rate_ids", "company_id") - def _compute_show_currency_rate_amount(self): - for item in self: - item.show_currency_rate_amount = ( - item.currency_id and item.currency_id != item.company_id.currency_id + def _compute_invoice_currency_rate(self): + # If move is posted, get rate based on line amount + res = super()._compute_invoice_currency_rate() + for move in self: + lines = move.line_ids.filtered(lambda x: abs(x.amount_currency) > 0) + if move.state != "posted" or not lines or not move.currency_id: + continue + amount_currency_positive = sum( + [abs(amc) for amc in lines.mapped("amount_currency")] ) + total_balance_positive = sum([abs(b) for b in lines.mapped("balance")]) + move.invoice_currency_rate = move.currency_id.round( + amount_currency_positive / total_balance_positive + ) + return res class AccountMoveLine(models.Model): _inherit = "account.move.line" - currency_rate_amount = fields.Float( - string="Rate amount", - compute="_compute_currency_rate_amount", - digits=0, - ) - @api.depends( - "move_id.state", + "currency_id", + "company_id", + "move_id.invoice_currency_rate", "move_id.date", + "move_id.state", "amount_currency", "balance", - "move_id.company_id", - "currency_id", ) - def _compute_currency_rate_amount(self): - """It's necessary to define value according to some cases: - - Case A: Currency is equal to company currency (Value = 1) - - Case B: Move exist previously (posted) and get real rate according to lines - - Case C: Get expected rate (according to date) to show some value in creation. - """ - self.currency_rate_amount = 1 - for item in self: - if ( - not item.currency_id - or item.currency_id == item.move_id.company_id.currency_id - ): + def _compute_currency_rate(self): + # If move is posted, get rate based on line amount + res = super()._compute_currency_rate() + for line in self: + if line.move_id.state != "posted" or not line.amount_currency: continue - amount_currency = abs(item.amount_currency) - if item.move_id.state == "posted" and amount_currency > 0: - item.currency_rate_amount = item.currency_id.round( - amount_currency / abs(item.balance) - ) - else: - rates = item.currency_id._get_rates( - item.move_id.company_id, item.move_id.date - ) - item.currency_rate_amount = rates.get(item.currency_id.id) + line.currency_rate = line.currency_id.round( + abs(line.amount_currency) / abs(line.balance) + ) + return res diff --git a/account_invoice_show_currency_rate/readme/CONTRIBUTORS.md b/account_invoice_show_currency_rate/readme/CONTRIBUTORS.md index 7859439b2d2..77a9ad940d9 100644 --- a/account_invoice_show_currency_rate/readme/CONTRIBUTORS.md +++ b/account_invoice_show_currency_rate/readme/CONTRIBUTORS.md @@ -1,3 +1,5 @@ - [Tecnativa](https://www.tecnativa.com): - Pedro M. Baeza - Víctor Martínez +- [ForgeFlow](https://www.forgeflow.com): + - Jordi Masvidal diff --git a/account_invoice_show_currency_rate/readme/DESCRIPTION.md b/account_invoice_show_currency_rate/readme/DESCRIPTION.md index 25eb21e066e..e297eba15a8 100644 --- a/account_invoice_show_currency_rate/readme/DESCRIPTION.md +++ b/account_invoice_show_currency_rate/readme/DESCRIPTION.md @@ -1,3 +1,9 @@ -This module shows the currency rate applied in invoices, so you can -visually verify what is going to be applied for the exchange, or which -one was applied once converted to company currency. +Since V18, Odoo shows the currency rate applied to invoices. Also, +it computes the currency rate on journal items by simply looking at the rates +configured in the system, but it does not display it. + +This module shows the currency rate on journal items, useful for other +entries that are not invoices, as well as entries containing lines with multiple +currencies. Furthermore, it ensures that the currency rate on journal items is +based on the actual amount in the journal item's currency, as this can be manually +modified by the user. diff --git a/account_invoice_show_currency_rate/static/description/index.html b/account_invoice_show_currency_rate/static/description/index.html index d89f167f944..547d34cd84f 100644 --- a/account_invoice_show_currency_rate/static/description/index.html +++ b/account_invoice_show_currency_rate/static/description/index.html @@ -370,9 +370,14 @@

Account Invoice Show Currency Rate

!! source digest: sha256:9f77ee0ab5b39a670d3a6f6162c64cf595c51ae2dd2782fa01f188cd0fa97dc2 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/account-invoicing Translate me on Weblate Try me on Runboat

-

This module shows the currency rate applied in invoices, so you can -visually verify what is going to be applied for the exchange, or which -one was applied once converted to company currency.

+

Since V18, Odoo shows the currency rate applied to invoices. Also, it +computes the currency rate on journal items by simply looking at the +rates configured in the system, but it does not display it.

+

This module shows the currency rate on journal items, useful for other +entries that are not invoices, as well as entries containing lines with +multiple currencies. Furthermore, it ensures that the currency rate on +journal items is based on the actual amount in the journal item’s +currency, as this can be manually modified by the user.

Table of contents

+
  • ForgeFlow:
      +
    • Jordi Masvidal
    • +
    +
  • diff --git a/account_invoice_show_currency_rate/tests/test_account_move.py b/account_invoice_show_currency_rate/tests/test_account_move.py index 8ee84adb358..f73436b804e 100644 --- a/account_invoice_show_currency_rate/tests/test_account_move.py +++ b/account_invoice_show_currency_rate/tests/test_account_move.py @@ -76,20 +76,20 @@ def _create_invoice(self, currency_id): def test_01_invoice_currency(self): self.partner.property_product_pricelist = self.pricelist_currency invoice = self._create_invoice(self.currency) - self.assertAlmostEqual(invoice.currency_rate_amount, 1.0, 2) - self.assertAlmostEqual(invoice.line_ids[0].currency_rate_amount, 1.0, 2) + self.assertAlmostEqual(invoice.invoice_currency_rate, 1.0, 2) + self.assertAlmostEqual(invoice.line_ids[0].currency_rate, 1.0, 2) def test_02_invoice_currency_extra(self): self.partner.property_product_pricelist = self.pricelist_currency_extra invoice = self._create_invoice(self.currency_extra) - self.assertAlmostEqual(invoice.currency_rate_amount, 2.0, 2) - self.assertAlmostEqual(invoice.line_ids[0].currency_rate_amount, 2.0, 2) + self.assertAlmostEqual(invoice.invoice_currency_rate, 2.0, 2) + self.assertAlmostEqual(invoice.line_ids[0].currency_rate, 2.0, 2) rate_custom = self.currency_extra.rate_ids.filtered( lambda x: x.name == fields.Date.from_string("2000-01-01") ) rate_custom.rate = 3.0 - self.assertAlmostEqual(invoice.currency_rate_amount, 2.0, 2) - self.assertAlmostEqual(invoice.line_ids[0].currency_rate_amount, 2.0, 2) + self.assertAlmostEqual(invoice.invoice_currency_rate, 2.0, 2) + self.assertAlmostEqual(invoice.line_ids[0].currency_rate, 2.0, 2) invoice.button_draft() - self.assertAlmostEqual(invoice.currency_rate_amount, 3.0, 2) - self.assertAlmostEqual(invoice.line_ids[0].currency_rate_amount, 3.0, 2) + self.assertAlmostEqual(invoice.invoice_currency_rate, 3.0, 2) + self.assertAlmostEqual(invoice.line_ids[0].currency_rate, 3.0, 2) diff --git a/account_invoice_show_currency_rate/views/account_move_view.xml b/account_invoice_show_currency_rate/views/account_move_view.xml index 41d1041c290..25cad9217f0 100644 --- a/account_invoice_show_currency_rate/views/account_move_view.xml +++ b/account_invoice_show_currency_rate/views/account_move_view.xml @@ -8,21 +8,12 @@ License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). account.move - - - -