Skip to content

Commit 7383b2f

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 foreign currency or as foreign currency per company currency. Example (company currency: JPY; 1 USD = 150 JPY): - (Default) Foreign currency per company currency → 0.0067 (USD/JPY) - Company currency per foreign currency → 150 (JPY/USD)
1 parent ecb9aa1 commit 7383b2f

File tree

11 files changed

+168
-9
lines changed

11 files changed

+168
-9
lines changed

account_invoice_show_currency_rate/README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ 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 Currency Rate Display section, select the default display style for all invoices:
60+
- Foreign Currency per Company Currency Rate (default): Displays the foreign currency per 1 unit of the company currency.
61+
- Company Currency per Foreign Currency Rate: Displays the company currency per 1 unit of the foreign currency.
62+
5663
Usage
5764
=====
5865

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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ class AccountMove(models.Model):
1212
compute="_compute_currency_rate_amount",
1313
digits=0,
1414
)
15+
company_currency_rate_amount = fields.Float(
16+
string="Rate Amount",
17+
compute="_compute_currency_rate_amount",
18+
digits=0,
19+
)
20+
currency_rate_display = fields.Selection(related="company_id.currency_rate_display")
1521
show_currency_rate_amount = fields.Boolean(
1622
compute="_compute_show_currency_rate_amount", readonly=True
1723
)
@@ -32,6 +38,7 @@ def _compute_currency_rate_amount(self):
3238
- Case C: Get expected rate (according to date) to show some value in creation.
3339
"""
3440
self.currency_rate_amount = 1
41+
self.company_currency_rate_amount = 1
3542
for item in self.filtered("show_currency_rate_amount"):
3643
lines = item.line_ids.filtered(lambda x: abs(x.amount_currency) > 0)
3744
if item.state == "posted" and lines:
@@ -42,9 +49,15 @@ def _compute_currency_rate_amount(self):
4249
item.currency_rate_amount = (
4350
amount_currency_positive / total_balance_positive
4451
)
52+
item.company_currency_rate_amount = (
53+
total_balance_positive / amount_currency_positive
54+
)
4555
else:
4656
rates = item.currency_id._get_rates(item.company_id, item.date)
4757
item.currency_rate_amount = rates.get(item.currency_id.id)
58+
item.company_currency_rate_amount = item.currency_id._convert(
59+
1.0, item.company_id.currency_id, item.company_id, item.date
60+
)
4861

4962
@api.depends("currency_id", "currency_id.rate_ids", "company_id")
5063
def _compute_show_currency_rate_amount(self):
@@ -57,6 +70,41 @@ def _compute_show_currency_rate_amount(self):
5770
class AccountMoveLine(models.Model):
5871
_inherit = "account.move.line"
5972

73+
company_currency_rate_amount = fields.Float(
74+
string="Rate Amount",
75+
compute="_compute_company_currency_rate_amount",
76+
digits=0,
77+
)
78+
currency_rate_display = fields.Selection(related="company_id.currency_rate_display")
79+
80+
@api.depends(
81+
"currency_id",
82+
"move_id.company_id",
83+
"move_id.date",
84+
"move_id.state",
85+
"amount_currency",
86+
"balance",
87+
)
88+
def _compute_company_currency_rate_amount(self):
89+
for line in self:
90+
line.currency_rate = 1
91+
if line.currency_id:
92+
if line.move_id.state != "posted" or not line.amount_currency:
93+
line.company_currency_rate_amount = line.currency_id._convert(
94+
1.0,
95+
line.company_id.currency_id,
96+
line.company_id,
97+
date=line.move_id.invoice_date
98+
or line.move_id.date
99+
or fields.Date.context_today(line),
100+
)
101+
else:
102+
line.company_currency_rate_amount = (
103+
abs(line.balance) / abs(line.amount_currency)
104+
if line.amount_currency
105+
else 0
106+
)
107+
60108
@api.depends(
61109
"currency_id",
62110
"move_id.company_id",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
currency_rate_display = fields.Selection(
11+
[
12+
("foreign_per_company", "Foreign Currency per Company Currency Rate"),
13+
("company_per_foreign", "Company Currency per Foreign Currency Rate"),
14+
],
15+
default="foreign_per_company",
16+
help=(
17+
"Select how to display the exchange rate. Example (company currency: JPY; "
18+
"1 USD = 150 JPY):\n"
19+
"- Foreign currency per company currency → 0.0067 (USD/JPY)\n"
20+
"- Company currency per foreign currency → 150 (JPY/USD)"
21+
),
22+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
currency_rate_display = fields.Selection(
11+
related="company_id.currency_rate_display",
12+
readonly=False,
13+
)

account_invoice_show_currency_rate/readme/CONFIGURE.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ 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 Currency Rate Display section, select the default display style for all invoices:
20+
- Foreign Currency per Company Currency Rate (default): Displays the foreign currency per 1 unit of the company currency.
21+
- Company Currency per Foreign Currency Rate: Displays the company currency per 1 unit of the foreign currency.

account_invoice_show_currency_rate/static/description/index.html

Lines changed: 11 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,13 @@ <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 Currency Rate Display section, select the default display style for all invoices:
408+
- Foreign Currency per Company Currency Rate (default): Displays the foreign currency per 1 unit of the company currency.
409+
- Company Currency per Foreign Currency Rate: Displays the company currency per 1 unit of the foreign currency.</li>
410+
</ul>
405411
</div>
406412
<div class="section" id="usage">
407413
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
@@ -441,9 +447,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
441447
<div class="section" id="maintainers">
442448
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
443449
<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>
450+
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
447451
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
448452
mission is to support the collaborative development of Odoo features and
449453
promote its widespread use.</p>

account_invoice_show_currency_rate/tests/test_account_move.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,28 @@ def test_01_invoice_currency(self):
7777
invoice = self._create_invoice(self.currency)
7878
self.assertAlmostEqual(invoice.currency_rate_amount, 1.0, 2)
7979
self.assertAlmostEqual(invoice.line_ids[0].currency_rate, 1.0, 2)
80+
self.assertAlmostEqual(invoice.company_currency_rate_amount, 1.0, 2)
81+
self.assertAlmostEqual(invoice.line_ids[0].company_currency_rate_amount, 1.0, 2)
8082

8183
def test_02_invoice_currency_extra(self):
8284
self.partner.property_product_pricelist = self.pricelist_currency_extra
8385
invoice = self._create_invoice(self.currency_extra)
8486
self.assertAlmostEqual(invoice.currency_rate_amount, 2.0, 2)
8587
self.assertAlmostEqual(invoice.line_ids[0].currency_rate, 2.0, 2)
88+
self.assertAlmostEqual(invoice.company_currency_rate_amount, 0.5, 2)
89+
self.assertAlmostEqual(invoice.line_ids[0].company_currency_rate_amount, 0.5, 2)
8690
rate_custom = self.currency_extra.rate_ids.filtered(
8791
lambda x: x.name == fields.Date.from_string("2000-01-01")
8892
)
8993
rate_custom.rate = 3.0
9094
self.assertAlmostEqual(invoice.currency_rate_amount, 2.0, 2)
9195
self.assertAlmostEqual(invoice.line_ids[0].currency_rate, 2.0, 2)
96+
self.assertAlmostEqual(invoice.company_currency_rate_amount, 0.5, 2)
97+
self.assertAlmostEqual(invoice.line_ids[0].company_currency_rate_amount, 0.5, 2)
9298
invoice.button_draft()
9399
self.assertAlmostEqual(invoice.currency_rate_amount, 3.0, 2)
94100
self.assertAlmostEqual(invoice.line_ids[0].currency_rate, 3.0, 2)
101+
self.assertAlmostEqual(invoice.company_currency_rate_amount, 0.33, 2)
102+
self.assertAlmostEqual(
103+
invoice.line_ids[0].company_currency_rate_amount, 0.33, 2
104+
)

account_invoice_show_currency_rate/views/account_move_view.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@ License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
1010
<field name="arch" type="xml">
1111
<xpath expr="//div[@name='journal_div']" position="after">
1212
<field name="show_currency_rate_amount" invisible="1" />
13+
<field name="currency_rate_display" invisible="1" />
1314
<field
1415
name="currency_rate_amount"
1516
groups="base.group_multi_currency"
1617
digits="[12,12]"
17-
attrs="{'invisible':[('show_currency_rate_amount', '=', False)]}"
18+
attrs="{'invisible':['|', ('show_currency_rate_amount', '=', False), ('currency_rate_display', '=', 'company_per_foreign')]}"
19+
/>
20+
<field
21+
name="company_currency_rate_amount"
22+
groups="base.group_multi_currency"
23+
digits="[12,12]"
24+
attrs="{'invisible':['|', ('show_currency_rate_amount', '=', False), ('currency_rate_display', '=', 'foreign_per_company')]}"
1825
/>
1926
</xpath>
2027
<xpath
@@ -28,6 +35,13 @@ License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
2835
groups="base.group_multi_currency"
2936
optional="hide"
3037
/>
38+
<field
39+
name="company_currency_rate_amount"
40+
string="Rate"
41+
digits="[12,12]"
42+
groups="base.group_multi_currency"
43+
optional="hide"
44+
/>
3145
</xpath>
3246
</field>
3347
</record>

0 commit comments

Comments
 (0)