Skip to content

Commit d01904d

Browse files
[IMP] account_invoice_show_currency_rate: add option to choose currency rate display format
This commit adds an option to display the exchange rate either as company currency per unit or unit per company currency. Example (company currency: JPY; 1 USD = 150 JPY): - (Default) Unit per Company Currency → 0.0066 (USD/JPY) - Company Currency per Unit → 150 (JPY/USD)
1 parent ecb9aa1 commit d01904d

File tree

11 files changed

+131
-10
lines changed

11 files changed

+131
-10
lines changed

account_invoice_show_currency_rate/README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ Some rates must be defined (and be distinct to 1.0) for currencies different fro
5353
#. Go to Rates smart-button
5454
#. Update 01/01/2010 record and change rate to 1.5
5555

56+
To change the currency rate display style on invoices:
57+
58+
- Go to Accounting (or Invoicing) → Configuration → Settings.
59+
- In the Invoice Rate Display Type section, select the default display type for all currencies.
60+
5661
Usage
5762
=====
5863

@@ -88,6 +93,11 @@ Contributors
8893
* Pedro M. Baeza
8994
* Víctor Martínez
9095

96+
* `Quartle <https://www.quartile.co>`_:
97+
98+
* Aung Ko Ko Lin
99+
* Yoshi Tashiro
100+
91101
Maintainers
92102
~~~~~~~~~~~
93103

account_invoice_show_currency_rate/__manifest__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
"installable": True,
1212
"depends": ["account"],
1313
"maintainers": ["victoralmau"],
14-
"data": ["views/account_move_view.xml"],
14+
"data": [
15+
"views/account_move_view.xml",
16+
"views/res_config_settings_views.xml",
17+
],
1518
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from . import account_move
2+
from . import res_company
3+
from . import res_config_settings

account_invoice_show_currency_rate/models/account_move.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def _compute_currency_rate_amount(self):
3232
- Case C: Get expected rate (according to date) to show some value in creation.
3333
"""
3434
self.currency_rate_amount = 1
35+
inverse = self.env.company.invoice_rate_display_type == "inverse_rate"
3536
for item in self.filtered("show_currency_rate_amount"):
3637
lines = item.line_ids.filtered(lambda x: abs(x.amount_currency) > 0)
3738
if item.state == "posted" and lines:
@@ -40,11 +41,19 @@ def _compute_currency_rate_amount(self):
4041
)
4142
total_balance_positive = sum([abs(b) for b in lines.mapped("balance")])
4243
item.currency_rate_amount = (
43-
amount_currency_positive / total_balance_positive
44+
(amount_currency_positive / total_balance_positive)
45+
if not inverse
46+
else (total_balance_positive / amount_currency_positive)
4447
)
4548
else:
4649
rates = item.currency_id._get_rates(item.company_id, item.date)
47-
item.currency_rate_amount = rates.get(item.currency_id.id)
50+
item.currency_rate_amount = (
51+
rates.get(item.currency_id.id)
52+
if not inverse
53+
else item.currency_id._convert(
54+
1.0, item.company_id.currency_id, item.company_id, item.date
55+
)
56+
)
4857

4958
@api.depends("currency_id", "currency_id.rate_ids", "company_id")
5059
def _compute_show_currency_rate_amount(self):
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResCompany(models.Model):
8+
_inherit = "res.company"
9+
10+
invoice_rate_display_type = fields.Selection(
11+
[
12+
("normal", "Unit per Company Currency"),
13+
("inverse_rate", "Company Currency per Unit"),
14+
],
15+
default="normal",
16+
required=True,
17+
help=(
18+
"Select how to display exchange rates on invoices.\n"
19+
"Example (company currency: JPY; 1 USD = 150 JPY):\n"
20+
"- Unit per company currency → 0.0066 (USD per JPY)\n"
21+
"- Company currency per unit → 150 (JPY per USD)"
22+
),
23+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResConfigSettings(models.TransientModel):
8+
_inherit = "res.config.settings"
9+
10+
invoice_rate_display_type = fields.Selection(
11+
related="company_id.invoice_rate_display_type", readonly=False
12+
)

account_invoice_show_currency_rate/readme/CONFIGURE.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ Some rates must be defined (and be distinct to 1.0) for currencies different fro
1212
#. Go to Invoicing > Configuration > Currencies and go to EUR
1313
#. Go to Rates smart-button
1414
#. Update 01/01/2010 record and change rate to 1.5
15+
16+
To change the currency rate display style on invoices:
17+
18+
- Go to Accounting (or Invoicing) → Configuration → Settings.
19+
- In the Invoice Rate Display Type section, select the default display type for all currencies.

account_invoice_show_currency_rate/readme/CONTRIBUTORS.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22

33
* Pedro M. Baeza
44
* Víctor Martínez
5+
6+
* `Quartle <https://www.quartile.co>`_:
7+
8+
* Aung Ko Ko Lin
9+
* Yoshi Tashiro

account_invoice_show_currency_rate/static/description/index.html

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88

99
/*
1010
:Author: David Goodger ([email protected])
11-
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
11+
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15-
Despite the name, some widely supported CSS2 features are used.
1615
1716
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1817
customize this style sheet.
@@ -275,7 +274,7 @@
275274
margin-left: 2em ;
276275
margin-right: 2em }
277276

278-
pre.code .ln { color: gray; } /* line numbers */
277+
pre.code .ln { color: grey; } /* line numbers */
279278
pre.code, code { background-color: #eeeeee }
280279
pre.code .comment, code .comment { color: #5C6576 }
281280
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +300,7 @@
301300
span.pre {
302301
white-space: pre }
303302

304-
span.problematic, pre.problematic {
303+
span.problematic {
305304
color: red }
306305

307306
span.section-subtitle {
@@ -402,6 +401,11 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
402401
<li>Go to Rates smart-button</li>
403402
<li>Update 01/01/2010 record and change rate to 1.5</li>
404403
</ol>
404+
<p>To change the currency rate display style on invoices:</p>
405+
<ul class="simple">
406+
<li>Go to Accounting (or Invoicing) → Configuration → Settings.</li>
407+
<li>In the Invoice Rate Display Type section, select the default display type for all currencies.</li>
408+
</ul>
405409
</div>
406410
<div class="section" id="usage">
407411
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
@@ -436,14 +440,17 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
436440
<li>Víctor Martínez</li>
437441
</ul>
438442
</li>
443+
<li><a class="reference external" href="https://www.quartile.co">Quartle</a>:<ul>
444+
<li>Aung Ko Ko Lin</li>
445+
<li>Yoshi Tashiro</li>
446+
</ul>
447+
</li>
439448
</ul>
440449
</div>
441450
<div class="section" id="maintainers">
442451
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
443452
<p>This module is maintained by the OCA.</p>
444-
<a class="reference external image-reference" href="https://odoo-community.org">
445-
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
446-
</a>
453+
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
447454
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
448455
mission is to support the collaborative development of Odoo features and
449456
promote its widespread use.</p>

account_invoice_show_currency_rate/tests/test_account_move.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,16 @@ def test_02_invoice_currency_extra(self):
9292
invoice.button_draft()
9393
self.assertAlmostEqual(invoice.currency_rate_amount, 3.0, 2)
9494
self.assertAlmostEqual(invoice.line_ids[0].currency_rate, 3.0, 2)
95+
96+
def test_02_invoice_currency_extra_inverse_rate(self):
97+
self.partner.property_product_pricelist = self.pricelist_currency_extra
98+
self.env.company.invoice_rate_display_type = "inverse_rate"
99+
invoice = self._create_invoice(self.currency_extra)
100+
self.assertAlmostEqual(invoice.currency_rate_amount, 0.5, 2)
101+
rate_custom = self.currency_extra.rate_ids.filtered(
102+
lambda x: x.name == fields.Date.from_string("2000-01-01")
103+
)
104+
rate_custom.rate = 3.0
105+
self.assertAlmostEqual(invoice.currency_rate_amount, 0.5, 2)
106+
invoice.button_draft()
107+
self.assertAlmostEqual(invoice.currency_rate_amount, 0.33, 2)

0 commit comments

Comments
 (0)