Skip to content

Commit

Permalink
[ADD] l10n_uy_currency_update: actiave and fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
zaoral committed Oct 2, 2024
1 parent 7bcc5ba commit adc37f5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 34 deletions.
1 change: 1 addition & 0 deletions l10n_uy_currency_update/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# directory
##############################################################################
from . import models
from . import tests
1 change: 1 addition & 0 deletions l10n_uy_currency_update/models/res_currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
_logger = logging.getLogger(__name__)


class ResCurrency(models.Model):

_inherit = "res.currency"
Expand Down
2 changes: 1 addition & 1 deletion l10n_uy_currency_update/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
# from . import test_l10n_uy_currency_update
from . import test_l10n_uy_currency_update
68 changes: 35 additions & 33 deletions l10n_uy_currency_update/tests/test_l10n_uy_currency_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,48 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo.tests import common
from odoo import fields
import datetime
from unittest.mock import patch

from odoo.addons.account.tests.common import AccountTestInvoicingCommon

class TestL10nUyCurrencyUpdate(common.TransactionCase):

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

def setUp(self):
@classmethod
def setUpClass(cls, chart_template_ref="uy"):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.UYU = cls.env.ref('base.UYU')
cls.UYI = cls.env.ref('base.UYI')
cls.ARS = cls.env.ref('base.ARS')
cls.USD = cls.env.ref('base.USD')
cls.EUR = cls.env.ref('base.EUR')

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

super().setUp()

self.UYU = self.env.ref('base.UYU')
self.UYI = self.env.ref('base.UYI')
self.ARS = self.env.ref('base.ARS')
self.USD = self.env.ref('base.USD')
self.EUR = self.env.ref('base.EUR')
cls.utils_path = "odoo.addons.currency_rate_live.models.res_config_settings.ResCompany"

def test_bcu_rates(self):
""" When the base currency is UYU """
company = self.env.ref('l10n_uy_account.company_uy')
company.currency_id = self.UYU
self.env.company = company

with patch.object(fields.Date, 'today', lambda *args, **kwargs: self.frozen_date), \
patch.object(fields.Date, 'context_today', lambda *args, **kwargs: self.frozen_date), \
patch.object(type(self.env['res.company']), 'get_bcu_last_date', lambda *args, **kwargs: fields.Date.subtract(self.frozen_date, days=1)):

company.update_currency_rates()

self.assertEqual(self.UYU.rate, 1.0)
self.assertAlmostEqual(self.USD.rate, self.UYU_USD, places=3)
self.assertAlmostEqual(self.EUR.rate, self.UYU_EUR, places=3)
self.assertAlmostEqual(self.ARS.rate, self.UYU_ARS, places=3)
self.assertAlmostEqual(self.UYI.rate, self.UYU_UYI, places=3)
self.assertEqual(self.USD.rate, 1.0)
self.assertEqual(self.EUR.rate, 1.0)
self.assertEqual(self.ARS.rate, 1.0)
self.assertEqual(self.UYI.rate, 1.0)

test_date = datetime.date(2024, 9, 26)
mocked_res = {
'ARS': (28.57142857142857, test_date),
'EUR': (0.021456809662928324, test_date),
'USD': (0.023986567522187575, test_date),
'UYI': (0.16387263818560216, test_date),
'UYU': (1.0, test_date),
}

with patch(f"{self.utils_path}._parse_bcu_data", return_value=mocked_res):
self.env.company.update_currency_rates()

self.assertEqual(self.UYU.rate, 1.0)
self.assertAlmostEqual(self.USD.rate, 0.023986567522187575, places=16)
self.assertAlmostEqual(self.EUR.rate, 0.021456809662928324, places=16)
self.assertAlmostEqual(self.ARS.rate, 28.57142857142857, places=16)
self.assertAlmostEqual(self.UYI.rate, 0.16387263818560216, places=16)

0 comments on commit adc37f5

Please sign in to comment.