|
| 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