Skip to content

Commit 10fca99

Browse files
authored
Merge pull request ingadhoc#234 from ingadhoc/18.0-fw-vib
[ADD] l10n_uy_currency_update: actiave and fix unit test
2 parents ff1a00d + e92a474 commit 10fca99

4 files changed

Lines changed: 38 additions & 34 deletions

File tree

l10n_uy_currency_update/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
# directory
44
##############################################################################
55
from . import models
6+
from . import tests

l10n_uy_currency_update/models/res_currency.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
_logger = logging.getLogger(__name__)
77

8+
89
class ResCurrency(models.Model):
910

1011
_inherit = "res.currency"

l10n_uy_currency_update/tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# For copyright and license notices, see __manifest__.py file in module root
33
# directory
44
##############################################################################
5-
# from . import test_l10n_uy_currency_update
5+
from . import test_l10n_uy_currency_update

l10n_uy_currency_update/tests/test_l10n_uy_currency_update.py

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,48 @@
22
# For copyright and license notices, see __manifest__.py file in module root
33
# directory
44
##############################################################################
5-
from odoo.tests import common
6-
from odoo import fields
5+
import datetime
76
from unittest.mock import patch
87

8+
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
99

10-
class TestL10nUyCurrencyUpdate(common.TransactionCase):
1110

12-
# TODO when running this test please update this values to the day rate.
13-
# can use only rates of the last 30 days
11+
class TestL10nUyCurrencyUpdate(AccountTestInvoicingCommon):
1412

15-
def setUp(self):
13+
@classmethod
14+
def setUpClass(cls, chart_template_ref="uy"):
15+
super().setUpClass(chart_template_ref=chart_template_ref)
16+
cls.UYU = cls.env.ref('base.UYU')
17+
cls.UYI = cls.env.ref('base.UYI')
18+
cls.ARS = cls.env.ref('base.ARS')
19+
cls.USD = cls.env.ref('base.USD')
20+
cls.EUR = cls.env.ref('base.EUR')
1621

17-
self.frozen_date = fields.Date.from_string('2022-03-17')
18-
self.UYU_USD = 1.0 / 42.652
19-
self.UYU_EUR = 1.0 / 46.923598
20-
self.UYU_ARS = 1.0 / 0.389819
21-
self.UYU_UYI = 1.0 / 5.2768
22+
(cls.UYU + cls.UYI + cls.ARS + cls.USD + cls.EUR).active = True
2223

23-
super().setUp()
24-
25-
self.UYU = self.env.ref('base.UYU')
26-
self.UYI = self.env.ref('base.UYI')
27-
self.ARS = self.env.ref('base.ARS')
28-
self.USD = self.env.ref('base.USD')
29-
self.EUR = self.env.ref('base.EUR')
24+
cls.utils_path = "odoo.addons.currency_rate_live.models.res_config_settings.ResCompany"
3025

3126
def test_bcu_rates(self):
3227
""" When the base currency is UYU """
33-
company = self.env.ref('l10n_uy_account.company_uy')
34-
company.currency_id = self.UYU
35-
self.env.company = company
36-
37-
with patch.object(fields.Date, 'today', lambda *args, **kwargs: self.frozen_date), \
38-
patch.object(fields.Date, 'context_today', lambda *args, **kwargs: self.frozen_date), \
39-
patch.object(type(self.env['res.company']), 'get_bcu_last_date', lambda *args, **kwargs: fields.Date.subtract(self.frozen_date, days=1)):
40-
41-
company.update_currency_rates()
42-
43-
self.assertEqual(self.UYU.rate, 1.0)
44-
self.assertAlmostEqual(self.USD.rate, self.UYU_USD, places=3)
45-
self.assertAlmostEqual(self.EUR.rate, self.UYU_EUR, places=3)
46-
self.assertAlmostEqual(self.ARS.rate, self.UYU_ARS, places=3)
47-
self.assertAlmostEqual(self.UYI.rate, self.UYU_UYI, places=3)
28+
self.assertEqual(self.USD.rate, 1.0)
29+
self.assertEqual(self.EUR.rate, 1.0)
30+
self.assertEqual(self.ARS.rate, 1.0)
31+
self.assertEqual(self.UYI.rate, 1.0)
32+
33+
test_date = datetime.date(2024, 9, 26)
34+
mocked_res = {
35+
'ARS': (28.57142857142857, test_date),
36+
'EUR': (0.021456809662928324, test_date),
37+
'USD': (0.023986567522187575, test_date),
38+
'UYI': (0.16387263818560216, test_date),
39+
'UYU': (1.0, test_date),
40+
}
41+
42+
with patch(f"{self.utils_path}._parse_bcu_data", return_value=mocked_res):
43+
self.env.company.update_currency_rates()
44+
45+
self.assertEqual(self.UYU.rate, 1.0)
46+
self.assertAlmostEqual(self.USD.rate, 0.023986567522187575, places=16)
47+
self.assertAlmostEqual(self.EUR.rate, 0.021456809662928324, places=16)
48+
self.assertAlmostEqual(self.ARS.rate, 28.57142857142857, places=16)
49+
self.assertAlmostEqual(self.UYI.rate, 0.16387263818560216, places=16)

0 commit comments

Comments
 (0)