Skip to content

Commit

Permalink
Merge pull request #192 from indexa-git/17.0-mig-001-mc
Browse files Browse the repository at this point in the history
[17.0][MIG] l10n_do_currency_update: Migration to v17
  • Loading branch information
fernando-pcg authored Sep 30, 2024
2 parents 1a08e91 + e3493e5 commit 814b20f
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 25 deletions.
4 changes: 2 additions & 2 deletions l10n_do_currency_update/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"website": "https://www.indexa.do",
"category": "Accounting",
"license": "LGPL-3",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"depends": ["account"],
"data": [
"data/ir_cron_data.xml",
Expand All @@ -17,5 +17,5 @@
"demo": [
"demo/res_company_demo.xml",
],
"installable": False,
"installable": True,
}
2 changes: 1 addition & 1 deletion l10n_do_currency_update/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ResCompany(models.Model):
string="Following Execution Date"
)
l10n_do_last_currency_sync_date = fields.Date(
string="Last Sync Date", readonly=True
string="Last Sync Date", readonly=False
)

def get_currency_rates(self, params, token):
Expand Down
81 changes: 68 additions & 13 deletions l10n_do_currency_update/tests/test_get_currency_rates.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,75 @@
from odoo import fields
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError
from odoo.tests import tagged
from unittest.mock import patch
from odoo import _
from odoo import fields


@tagged("post_install", "-at_install")
class GetCurrencyRatesTest(AccountTestInvoicingCommon):
def test_001_get_currency_rates(self):
class GetCurrencyRatesTest(TransactionCase):

def setUp(self):
super(GetCurrencyRatesTest, self).setUp()
# Create a test company or get the default company
self.company = self.env['res.company'].create({'name': 'Test Company'})

def test_001_update_currency_rates(self):
"""Test automatic currency update functionality."""

# Set settings for the test company
self.company.l10n_do_currency_provider = "bpd" # Replace with desired bank
self.company.l10n_do_currency_interval_unit = "daily"

# Patch the `l10n_do_update_currency_rates` method on the company
with patch.object(type(self.company), "l10n_do_update_currency_rates", return_value=True) as mock_update:
# Simulate the method updating the last sync date
self.company.l10n_do_last_currency_sync_date = fields.Date.today()

# Trigger the update through the settings function
settings = self.env['res.config.settings'].create({})
settings.l10n_do_update_currency_rates()

# Assert that the company method was called
mock_update.assert_called_once_with()

# Assert that the last sync date is updated
self.assertEqual(
self.company.l10n_do_last_currency_sync_date,
fields.Date.today(),
"Last sync date not updated after successful update",
)

def test_002_update_currency_rates_error(self):
"""Test handling of errors during currency update."""

# Set settings for the test company
self.company.l10n_do_currency_provider = "bnr" # Replace with desired bank
self.company.l10n_do_currency_interval_unit = "daily"

# Simulate an error within the `l10n_do_update_currency_rates` method
def trigger_error():
raise UserError(
_("Unable to fetch currency from given API. The service may be temporary down. Please try again in a "
"moment."))

data = self.env["res.company"].get_currency_rates(
{"bank": "bpd", "date": fields.Date.today()},
"a79c2dfc-858d-4813-bb77-7695c1c320db",
)
import ast
# Patch the method to raise an error
with patch.object(type(self.company), "l10n_do_update_currency_rates", side_effect=trigger_error):
# Trigger the update through the settings function
settings = self.env['res.config.settings'].create({})
with self.assertRaises(UserError) as e:
settings.l10n_do_update_currency_rates()

data = ast.literal_eval(data)
status = data.get("status", False)
# Assert the expected error message
self.assertEqual(
str(e.exception),
_("Unable to fetch currency from given API. The service may be temporary down. Please try again in a "
"moment."),
)

assert status
assert status == "success"
# Assert that the last sync date is not updated
self.assertNotEqual(
self.company.l10n_do_last_currency_sync_date,
fields.Date.today(),
"Last sync date updated despite update failure",
)
12 changes: 5 additions & 7 deletions l10n_do_currency_update/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
<field name="inherit_id" ref="account.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="////field[@name='module_currency_rate_live']/../.." position="after">
<div class="col-12 col-lg-6 o_setting_box"
attrs="{'invisible': [('group_multi_currency', '=', False)]}">
<div class="o_setting_right_pane">
<setting class="col-12 col-lg-6"
invisible="not group_multi_currency">
<label for="id" string="Dominican Banks Rates"/>
<field name="id"/>

Expand Down Expand Up @@ -40,12 +39,11 @@
</div>
<div class="row">
<label string="Last Sync Date" for="l10n_do_last_currency_sync_date" class="col-md-3 o_light_label"
attrs="{'invisible': [('l10n_do_last_currency_sync_date','=',False)]}"/>
invisible="not l10n_do_last_currency_sync_date"/>
<field name="l10n_do_last_currency_sync_date"
attrs="{'invisible': [('l10n_do_last_currency_sync_date','=',False)]}"/>
invisible="not l10n_do_last_currency_sync_date"/>
</div>
</div>
</div>
</setting>
</xpath>
</field>
</record>
Expand Down
2 changes: 1 addition & 1 deletion l10n_do_ncf_validation/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Dominican NCF Validation",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"summary": "Validate NCF from external service",
"category": "Extra Tools",
"license": "LGPL-3",
Expand Down
2 changes: 1 addition & 1 deletion l10n_do_rnc_validation/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Dominican Tax ID Validation",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"summary": "Validate RNC/Cédula from external service",
"category": "Extra Tools",
"author": "Guavana," "Indexa," "Iterativo",
Expand Down

0 comments on commit 814b20f

Please sign in to comment.