diff --git a/l10n_do_currency_update/__manifest__.py b/l10n_do_currency_update/__manifest__.py
index bcb61c8..4f1b25f 100644
--- a/l10n_do_currency_update/__manifest__.py
+++ b/l10n_do_currency_update/__manifest__.py
@@ -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",
@@ -17,5 +17,5 @@
"demo": [
"demo/res_company_demo.xml",
],
- "installable": False,
+ "installable": True,
}
diff --git a/l10n_do_currency_update/models/res_company.py b/l10n_do_currency_update/models/res_company.py
index c71ae42..65ee6a1 100644
--- a/l10n_do_currency_update/models/res_company.py
+++ b/l10n_do_currency_update/models/res_company.py
@@ -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):
diff --git a/l10n_do_currency_update/tests/test_get_currency_rates.py b/l10n_do_currency_update/tests/test_get_currency_rates.py
index 58ae03f..b1bce3d 100644
--- a/l10n_do_currency_update/tests/test_get_currency_rates.py
+++ b/l10n_do_currency_update/tests/test_get_currency_rates.py
@@ -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",
+ )
diff --git a/l10n_do_currency_update/views/res_config_settings_views.xml b/l10n_do_currency_update/views/res_config_settings_views.xml
index 92bc955..f1e67dc 100644
--- a/l10n_do_currency_update/views/res_config_settings_views.xml
+++ b/l10n_do_currency_update/views/res_config_settings_views.xml
@@ -7,9 +7,8 @@
-