Skip to content

Commit 2c6b4e0

Browse files
committed
[FIX] sale_order_currency_rate
1 parent 680c061 commit 2c6b4e0

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

sale_order_currency_rate/models/sale_order.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@
77
class SaleOrder(models.Model):
88
_inherit = "sale.order"
99

10-
currency_rate = fields.Float(
11-
compute="_compute_currency_rate",
12-
digits="Currency Rate Precision",
13-
)
14-
1510
inverse_currency_rate = fields.Float(
16-
compute="_compute_currency_rate",
11+
compute="_compute_inverse_currency_rate",
1712
digits="Currency Rate Precision",
1813
)
1914

@@ -23,23 +18,15 @@ class SaleOrder(models.Model):
2318
)
2419

2520
@api.depends("currency_id", "company_id.currency_id")
26-
def _compute_currency_rate(self):
21+
def _compute_inverse_currency_rate(self):
2722
for order in self:
2823
if order.currency_id != order.company_id.currency_id:
29-
order.currency_rate = order.currency_id._convert(
24+
order.inverse_currency_rate = order.currency_id._convert(
3025
1.0,
3126
order.company_id.currency_id,
3227
order.company_id,
3328
order.date_order,
3429
round=False,
3530
)
36-
order.inverse_currency_rate = order.company_id.currency_id._convert(
37-
1.0,
38-
order.currency_id,
39-
order.company_id,
40-
order.date_order,
41-
round=False,
42-
)
4331
else:
44-
order.currency_rate = 1.0
4532
order.inverse_currency_rate = 1.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_sale_order_currency_rate
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
2+
from odoo.fields import Command
3+
from odoo.tests.common import TransactionCase
4+
5+
6+
class TestSaleOrderCurrencyRate(TransactionCase):
7+
@classmethod
8+
def setUpClass(cls):
9+
super().setUpClass()
10+
partner_id = cls.env.ref("base.res_partner_1")
11+
product_1 = cls.env.ref("product.product_product_4")
12+
product_2 = cls.env.ref("product.product_product_5")
13+
pricelist = cls.env.ref("product.list0")
14+
pricelist_data = pricelist.copy_data()[0]
15+
currency_eur = cls.env.ref("base.EUR")
16+
pricelist_data.update({"currency_id": currency_eur.id})
17+
cls.pricelist_eur = cls.env["product.pricelist"].create(pricelist_data)
18+
order_lines = [
19+
{"product_id": product_1.id, "product_uom_qty": 1},
20+
{"product_id": product_2.id, "product_uom_qty": 1},
21+
]
22+
cls.order = cls.env["sale.order"].create(
23+
{
24+
"name": "SO Test",
25+
"partner_id": partner_id.id,
26+
"pricelist_id": pricelist.id,
27+
"order_line": [Command.create(line) for line in order_lines],
28+
}
29+
)
30+
31+
def test_sale_order_currency_rate(self):
32+
# Setting the configuration to "both" in order to show currency rate and inverse
33+
# currency rate, when the pricelist of the order changes, it corresponds to
34+
# currency set in the pricelist.
35+
self.env["res.config.settings"].create({"sale_show_currency_rate": "both"})
36+
self.assertEqual(self.order.currency_rate, 1.0)
37+
self.assertEqual(self.order.inverse_currency_rate, 1.0)
38+
self.order.write({"pricelist_id": self.pricelist_eur.id})
39+
self.assertAlmostEqual(self.order.currency_rate, 0.65, places=2)
40+
self.assertAlmostEqual(self.order.inverse_currency_rate, 1.53, places=2)

0 commit comments

Comments
 (0)