diff --git a/currency_rate_update_boi/README.rst b/currency_rate_update_boi/README.rst new file mode 100644 index 000000000000..9b8f93890b20 --- /dev/null +++ b/currency_rate_update_boi/README.rst @@ -0,0 +1,120 @@ +==================================== +Currency Rate Update: Banca d'Italia +==================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5bdb22c9d941bdf7ebd502bde54b74255a4cc54d14eac7908310510681aa73f2 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github + :target: https://github.com/OCA/l10n-italy/tree/16.0/currency_rate_update_boi + :alt: OCA/l10n-italy +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/l10n-italy-16-0/l10n-italy-16-0-currency_rate_update_boi + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +**Italiano** + +Questo modulo aggiunge la `Banca d'Italia `_ +come fornitore dei tassi di cambio. + +Le istruzioni per l'esportazione dei dati sono disponibili all'indirizzo +https://tassidicambio.bancaditalia.it/terzevalute-wf-ui-web/assets/files/Operating_Instructions.pdf + +I tassi di cambio sono esportati nel formato JSON. + +**English** + +This module adds `Bank of Italy `_ +currency exchange rates provider. + +Data export instructions are available at +https://tassidicambio.bancaditalia.it/terzevalute-wf-ui-web/assets/files/Operating_Instructions.pdf + +Exchange rates are exported in JSON format. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +**Italiano** + +Suggeriamo di eseguire l'azione pianificata "Aggiornamento tassi di cambio (OCA) giornaliero" alla fine del giorno, +per essere sicuri che la Banca d'Italia abbia aggiornato i dati. + +**English** + +We suggest to execute the "Currency Rates Update (OCA) daily" cron at the end of the day, +to be sure that Bank of Italy updated the data. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* TAKOBI + +Contributors +~~~~~~~~~~~~ + +* Giacomo Grasso +* Gabriele Baldessari + +* `TAKOBI `_: + + * Lorenzo Battistini + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-eLBati| image:: https://github.com/eLBati.png?size=40px + :target: https://github.com/eLBati + :alt: eLBati + +Current `maintainer `__: + +|maintainer-eLBati| + +This module is part of the `OCA/l10n-italy `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/currency_rate_update_boi/__init__.py b/currency_rate_update_boi/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/currency_rate_update_boi/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/currency_rate_update_boi/__manifest__.py b/currency_rate_update_boi/__manifest__.py new file mode 100644 index 000000000000..0dab31ddbfdb --- /dev/null +++ b/currency_rate_update_boi/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2021 Lorenzo Battistini @ TAKOBI +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Currency Rate Update: Banca d'Italia", + "version": "16.0.1.0.0", + "category": "Financial Management/Configuration", + "summary": "Update exchange rates using www.bancaditalia.it", + "author": "TAKOBI, " "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/l10n-italy" + "/tree/16.0/currency_rate_update_boi", + "maintainers": ["eLBati"], + "license": "AGPL-3", + "installable": True, + "application": False, + "depends": [ + "account", + "currency_rate_update", + ], + "data": [], +} diff --git a/currency_rate_update_boi/i18n/currency_rate_update_boi.pot b/currency_rate_update_boi/i18n/currency_rate_update_boi.pot new file mode 100644 index 000000000000..3feb794fea40 --- /dev/null +++ b/currency_rate_update_boi/i18n/currency_rate_update_boi.pot @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * currency_rate_update_boi +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: currency_rate_update_boi +#: model:ir.model.fields.selection,name:currency_rate_update_boi.selection__res_currency_rate_provider__service__boi +msgid "Bank of Italy" +msgstr "" + +#. module: currency_rate_update_boi +#: model:ir.model,name:currency_rate_update_boi.model_res_currency_rate_provider +msgid "Currency Rates Provider" +msgstr "" + +#. module: currency_rate_update_boi +#: model:ir.model.fields,field_description:currency_rate_update_boi.field_res_currency_rate_provider__display_name +msgid "Display Name" +msgstr "" + +#. module: currency_rate_update_boi +#: model:ir.model.fields,field_description:currency_rate_update_boi.field_res_currency_rate_provider__id +msgid "ID" +msgstr "" + +#. module: currency_rate_update_boi +#: model:ir.model.fields,field_description:currency_rate_update_boi.field_res_currency_rate_provider____last_update +msgid "Last Modified on" +msgstr "" + +#. module: currency_rate_update_boi +#: model:ir.model.fields,field_description:currency_rate_update_boi.field_res_currency_rate_provider__service +msgid "Source Service" +msgstr "" diff --git a/currency_rate_update_boi/i18n/it.po b/currency_rate_update_boi/i18n/it.po new file mode 100644 index 000000000000..42e50cc56391 --- /dev/null +++ b/currency_rate_update_boi/i18n/it.po @@ -0,0 +1,50 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * currency_rate_update_boi +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-07-24 09:10+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: currency_rate_update_boi +#: model:ir.model.fields.selection,name:currency_rate_update_boi.selection__res_currency_rate_provider__service__boi +msgid "Bank of Italy" +msgstr "Banca d'Italia" + +#. module: currency_rate_update_boi +#: model:ir.model,name:currency_rate_update_boi.model_res_currency_rate_provider +msgid "Currency Rates Provider" +msgstr "Provider Cambi Valuta" + +#. module: currency_rate_update_boi +#: model:ir.model.fields,field_description:currency_rate_update_boi.field_res_currency_rate_provider__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: currency_rate_update_boi +#: model:ir.model.fields,field_description:currency_rate_update_boi.field_res_currency_rate_provider__id +msgid "ID" +msgstr "ID" + +#. module: currency_rate_update_boi +#: model:ir.model.fields,field_description:currency_rate_update_boi.field_res_currency_rate_provider____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: currency_rate_update_boi +#: model:ir.model.fields,field_description:currency_rate_update_boi.field_res_currency_rate_provider__service +msgid "Source Service" +msgstr "Servizio Sorgente" + +#~ msgid "European Central Bank" +#~ msgstr "Banca Centrale Europea" diff --git a/currency_rate_update_boi/models/__init__.py b/currency_rate_update_boi/models/__init__.py new file mode 100644 index 000000000000..429f804cde54 --- /dev/null +++ b/currency_rate_update_boi/models/__init__.py @@ -0,0 +1 @@ +from . import res_currency_rate_provider_BOI diff --git a/currency_rate_update_boi/models/res_currency_rate_provider_BOI.py b/currency_rate_update_boi/models/res_currency_rate_provider_BOI.py new file mode 100644 index 000000000000..e5e5d182c265 --- /dev/null +++ b/currency_rate_update_boi/models/res_currency_rate_provider_BOI.py @@ -0,0 +1,291 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from datetime import timedelta + +import requests + +from odoo import fields, models +from odoo.tools.safe_eval import safe_eval + + +class ResCurrencyRateProviderBOI(models.Model): + _inherit = "res.currency.rate.provider" + + service = fields.Selection( + selection_add=[("BOI", "Bank of Italy")], ondelete={"BOI": "cascade"} + ) + + def _get_supported_currencies(self): + self.ensure_one() + if self.service != "BOI": + return super()._get_supported_currencies() # pragma: no cover + + return [ + "AFN", + "ALL", + "DZD", + "ADP", + "AOA", + "XCD", + "ANG", + "SAR", + "ARS", + "AMD", + "AWG", + "AUD", + "ATS", + "AZN", + "AZM", + "BSD", + "BHD", + "BDT", + "BBD", + "BEF", + "BZD", + "XOF", + "BMD", + "BTN", + "BYB", + "BYN", + "BYR", + "BOB", + "BAM", + "BWP", + "BRL", + "BND", + "BGL", + "BGN", + "XOF", + "BIF", + "KHR", + "XAF", + "CAD", + "CVE", + "KYD", + "CZK", + "CSK", + "XAF", + "XAF", + "CLP", + "CNY", + "CYP", + "COP", + "KMF", + "XAF", + "ZRN", + "CDF", + "KPW", + "KRW", + "XOF", + "CRC", + "HRK", + "CUP", + "DKK", + "XCD", + "DOP", + "ECS", + "EGP", + "SVC", + "AED", + "ERN", + "EEK", + "ETB", + "FKP", + "FJD", + "PHP", + "FIM", + "XDR", + "FRF", + "XAF", + "GMD", + "GEL", + "DEM", + "DDM", + "GHS", + "GHC", + "JMD", + "JPY", + "GIP", + "DJF", + "JOD", + "GRD", + "XCD", + "GTQ", + "GNF", + "GWP", + "XOF", + "XAF", + "GQE", + "GYD", + "HTG", + "HNL", + "HKD", + "INR", + "IDR", + "IRR", + "IQD", + "IEP", + "ISK", + "ILS", + "ITL", + "YUM", + "KZT", + "KES", + "KGS", + "KWD", + "LAK", + "LSL", + "LVL", + "LBP", + "LRD", + "LYD", + "LTL", + "LUF", + "MOP", + "MKD", + "MGA", + "MGF", + "MWK", + "MYR", + "MVR", + "XOF", + "MLF", + "MTL", + "MAD", + "MRO", + "MUR", + "MXN", + "MDL", + "MNT", + "MZM", + "MZN", + "MMK", + "NAD", + "NPR", + "NIO", + "XOF", + "NGN", + "NOK", + "NZD", + "NLG", + "OMR", + "PKR", + "PAB", + "PGK", + "PYG", + "PEN", + "XPF", + "PLN", + "PTE", + "QAR", + "GBP", + "ROL", + "RON", + "RUB", + "RWF", + "SBD", + "WST", + "SHP", + "STD", + "XOF", + "CSD", + "RSD", + "CSD", + "SCR", + "SLL", + "SGD", + "SYP", + "ECU", + "SKK", + "SIT", + "SOS", + "ESP", + "LKR", + "XCD", + "XCD", + "USD", + "XCD", + "ZAR", + "SSP", + "SDG", + "SDD", + "SRG", + "SRD", + "SEK", + "CHF", + "SZL", + "TJS", + "TJR", + "TWD", + "TZS", + "THB", + "XOF", + "TOP", + "TTD", + "TND", + "TRY", + "TRL", + "TMM", + "TMT", + "UAH", + "UGX", + "HUF", + "EUR", + "SUR", + "UYU", + "UZS", + "VUV", + "VEF", + "VEB", + "VND", + "YER", + "YDD", + "ZMW", + "ZMK", + "ZWD", + "ZWN", + ] + + def _obtain_rates(self, base_currency, currencies, date_from, date_to): + self.ensure_one() + if self.service != "BOI": + return super()._obtain_rates( + base_currency, currencies, date_from, date_to + ) # pragma: no cover + + invert_calculation = False + if base_currency != "EUR": + invert_calculation = True + if base_currency not in currencies: + currencies.append(base_currency) + content = {} + + while date_from <= date_to: + date_from_str = str(date_from) + + url = ( + "https://tassidicambio.bancaditalia.it/terzevalute-wf-web/" + "rest/v1.0/dailyRates?referenceDate={ref_date}" + "¤cyIsoCode={ref_cur}&lang={lang}".format( + ref_date=date_from_str, + ref_cur="EUR", + lang="EN", + ) + ) + response = requests.get( + url, headers={"Accept": "application/json"}, timeout=10 + ) + curr_dict = response.content + content[date_from_str] = {} + for row in safe_eval(curr_dict)["rates"]: + if row["isoCode"] in currencies: + content[date_from_str][row["isoCode"]] = row["avgRate"] + date_from += timedelta(days=1) + + if invert_calculation: + for k in content.keys(): + base_rate = float(content[k][base_currency]) + for rate in content[k].keys(): + content[k][rate] = str(float(content[k][rate]) / base_rate) + content[k]["EUR"] = str(1.0 / base_rate) + return content diff --git a/currency_rate_update_boi/readme/CONFIGURE.rst b/currency_rate_update_boi/readme/CONFIGURE.rst new file mode 100644 index 000000000000..2f239132b403 --- /dev/null +++ b/currency_rate_update_boi/readme/CONFIGURE.rst @@ -0,0 +1,9 @@ +**Italiano** + +Suggeriamo di eseguire l'azione pianificata "Aggiornamento tassi di cambio (OCA) giornaliero" alla fine del giorno, +per essere sicuri che la Banca d'Italia abbia aggiornato i dati. + +**English** + +We suggest to execute the "Currency Rates Update (OCA) daily" cron at the end of the day, +to be sure that Bank of Italy updated the data. diff --git a/currency_rate_update_boi/readme/CONTRIBUTORS.rst b/currency_rate_update_boi/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..9d7555a93d80 --- /dev/null +++ b/currency_rate_update_boi/readme/CONTRIBUTORS.rst @@ -0,0 +1,6 @@ +* Giacomo Grasso +* Gabriele Baldessari + +* `TAKOBI `_: + + * Lorenzo Battistini diff --git a/currency_rate_update_boi/readme/DESCRIPTION.rst b/currency_rate_update_boi/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..8e2933aef52a --- /dev/null +++ b/currency_rate_update_boi/readme/DESCRIPTION.rst @@ -0,0 +1,19 @@ +**Italiano** + +Questo modulo aggiunge la `Banca d'Italia `_ +come fornitore dei tassi di cambio. + +Le istruzioni per l'esportazione dei dati sono disponibili all'indirizzo +https://tassidicambio.bancaditalia.it/terzevalute-wf-ui-web/assets/files/Operating_Instructions.pdf + +I tassi di cambio sono esportati nel formato JSON. + +**English** + +This module adds `Bank of Italy `_ +currency exchange rates provider. + +Data export instructions are available at +https://tassidicambio.bancaditalia.it/terzevalute-wf-ui-web/assets/files/Operating_Instructions.pdf + +Exchange rates are exported in JSON format. diff --git a/currency_rate_update_boi/static/description/icon.png b/currency_rate_update_boi/static/description/icon.png new file mode 100644 index 000000000000..9333e33755a7 Binary files /dev/null and b/currency_rate_update_boi/static/description/icon.png differ diff --git a/currency_rate_update_boi/static/description/index.html b/currency_rate_update_boi/static/description/index.html new file mode 100644 index 000000000000..c44b54d95104 --- /dev/null +++ b/currency_rate_update_boi/static/description/index.html @@ -0,0 +1,449 @@ + + + + + + +Currency Rate Update: Banca d'Italia + + + +
+

Currency Rate Update: Banca d’Italia

+ + +

Beta License: AGPL-3 OCA/l10n-italy Translate me on Weblate Try me on Runboat

+

Italiano

+

Questo modulo aggiunge la Banca d’Italia +come fornitore dei tassi di cambio.

+

Le istruzioni per l’esportazione dei dati sono disponibili all’indirizzo +https://tassidicambio.bancaditalia.it/terzevalute-wf-ui-web/assets/files/Operating_Instructions.pdf

+

I tassi di cambio sono esportati nel formato JSON.

+

English

+

This module adds Bank of Italy +currency exchange rates provider.

+

Data export instructions are available at +https://tassidicambio.bancaditalia.it/terzevalute-wf-ui-web/assets/files/Operating_Instructions.pdf

+

Exchange rates are exported in JSON format.

+

Table of contents

+ +
+

Configuration

+

Italiano

+

Suggeriamo di eseguire l’azione pianificata “Aggiornamento tassi di cambio (OCA) giornaliero” alla fine del giorno, +per essere sicuri che la Banca d’Italia abbia aggiornato i dati.

+

English

+

We suggest to execute the “Currency Rates Update (OCA) daily” cron at the end of the day, +to be sure that Bank of Italy updated the data.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • TAKOBI
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

eLBati

+

This module is part of the OCA/l10n-italy project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/currency_rate_update_boi/tests/__init__.py b/currency_rate_update_boi/tests/__init__.py new file mode 100644 index 000000000000..93badc28397c --- /dev/null +++ b/currency_rate_update_boi/tests/__init__.py @@ -0,0 +1 @@ +from . import test_currency_rate_update_boi diff --git a/currency_rate_update_boi/tests/test_currency_rate_update_boi.py b/currency_rate_update_boi/tests/test_currency_rate_update_boi.py new file mode 100644 index 000000000000..c54bce67064d --- /dev/null +++ b/currency_rate_update_boi/tests/test_currency_rate_update_boi.py @@ -0,0 +1,156 @@ +# Copyright 2023 Giuseppe Borruso (gborruso@dinamicheaziendali.it) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import date +from unittest import mock + +from dateutil.relativedelta import relativedelta +from freezegun import freeze_time + +from odoo import fields +from odoo.tests import tagged + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon + +_module_ns = "odoo.addons.currency_rate_update_boi" +_file_ns = _module_ns + ".models.res_currency_rate_provider_BOI" +_BOI_provider_class = _file_ns + ".ResCurrencyRateProviderBOI" + + +@tagged("post_install", "-at_install") +class TestCurrencyRateUpdate(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.Company = cls.env["res.company"] + cls.CurrencyRate = cls.env["res.currency.rate"] + cls.CurrencyRateProvider = cls.env["res.currency.rate.provider"] + + cls.today = fields.Date.today() + cls.eur_currency = cls.env.ref("base.EUR") + cls.usd_currency = cls.env.ref("base.USD") + cls.gbp_currency = cls.env.ref("base.GBP") + cls.company = cls.Company.create( + {"name": "Test company", "currency_id": cls.eur_currency.id} + ) + cls.env.user.company_ids += cls.company + cls.env.user.company_id = cls.company + cls.ecb_provider = cls.CurrencyRateProvider.create( + { + "service": "BOI", + "currency_ids": [ + (4, cls.usd_currency.id), + (4, cls.gbp_currency.id), + (4, cls.env.user.company_id.currency_id.id), + ], + } + ) + cls.CurrencyRate.search([]).unlink() + + def test_supported_currencies_BOI(self): + self.ecb_provider._get_supported_currencies() + + def test_error_BOI(self): + with mock.patch(_BOI_provider_class + "._obtain_rates", return_value=None): + self.ecb_provider._update(self.today, self.today) + + def _get_no_weekend_date(self, compute_date): + if compute_date.weekday() == 5 or compute_date.weekday() == 6: + compute_date -= relativedelta(days=1) + return compute_date + + def test_update_BOI_yesterday(self): + compute_date = self._get_no_weekend_date(self.today - relativedelta(days=1)) + self.ecb_provider._update(compute_date, self.today) + + rates = self.CurrencyRate.search( + [("currency_id", "=", self.usd_currency.id)], limit=1 + ) + self.assertTrue(rates) + + self.CurrencyRate.search([("company_id", "=", self.company.id)]).unlink() + + def test_update_BOI_month(self): + compute_date = self._get_no_weekend_date(self.today - relativedelta(months=1)) + self.ecb_provider._update(compute_date, self.today) + + rates = self.CurrencyRate.search( + [("currency_id", "=", self.usd_currency.id)], limit=1 + ) + self.assertTrue(rates) + + self.CurrencyRate.search([("company_id", "=", self.company.id)]).unlink() + + def test_update_BOI_year(self): + compute_date = self._get_no_weekend_date(self.today - relativedelta(years=1)) + self.ecb_provider._update(compute_date, self.today) + + rates = self.CurrencyRate.search( + [("currency_id", "=", self.usd_currency.id)], limit=1 + ) + self.assertTrue(rates) + + self.CurrencyRate.search([("company_id", "=", self.company.id)]).unlink() + + def test_update_BOI_scheduled(self): + self.ecb_provider.interval_type = "days" + self.ecb_provider.interval_number = 14 + self.ecb_provider.next_run = self._get_no_weekend_date( + self.today - relativedelta(days=1) + ) + self.ecb_provider._scheduled_update() + + rates = self.CurrencyRate.search( + [("currency_id", "=", self.usd_currency.id)], limit=1 + ) + self.assertTrue(rates) + + self.CurrencyRate.search([("company_id", "=", self.company.id)]).unlink() + + def test_update_BOI_sequence(self): + self.ecb_provider.interval_type = "days" + self.ecb_provider.interval_number = 2 + self.ecb_provider.last_successful_run = None + self.ecb_provider.next_run = date(2019, 4, 1) + + self.ecb_provider._scheduled_update() + self.assertEqual(self.ecb_provider.last_successful_run, date(2019, 4, 1)) + self.assertEqual(self.ecb_provider.next_run, date(2019, 4, 3)) + rates = self.CurrencyRate.search( + [ + ("company_id", "=", self.company.id), + ("currency_id", "=", self.usd_currency.id), + ] + ) + self.assertEqual(len(rates), 1) + + self.ecb_provider._scheduled_update() + self.assertEqual(self.ecb_provider.last_successful_run, date(2019, 4, 3)) + self.assertEqual(self.ecb_provider.next_run, date(2019, 4, 5)) + rates = self.CurrencyRate.search( + [ + ("company_id", "=", self.company.id), + ("currency_id", "=", self.usd_currency.id), + ] + ) + self.assertEqual(len(rates), 2) + + self.CurrencyRate.search([("company_id", "=", self.company.id)]).unlink() + + @freeze_time("2022-04-19 22:00") + def test_update_BOI_with_daily(self): + self.ecb_provider.interval_type = "days" + self.ecb_provider.interval_number = 1 + self.ecb_provider.last_successful_run = date(2021, 4, 19) + + self.ecb_provider._scheduled_update() + + self.assertEqual(self.ecb_provider.last_successful_run, date(2022, 4, 19)) + + def test_foreign_base_currency(self): + self.test_update_BOI_yesterday() + self.test_update_BOI_month() + self.test_update_BOI_year() + self.test_update_BOI_scheduled() + self.test_update_BOI_sequence() diff --git a/setup/currency_rate_update_boi/odoo/addons/currency_rate_update_boi b/setup/currency_rate_update_boi/odoo/addons/currency_rate_update_boi new file mode 120000 index 000000000000..986e9841e6ea --- /dev/null +++ b/setup/currency_rate_update_boi/odoo/addons/currency_rate_update_boi @@ -0,0 +1 @@ +../../../../currency_rate_update_boi \ No newline at end of file diff --git a/setup/currency_rate_update_boi/setup.py b/setup/currency_rate_update_boi/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/currency_rate_update_boi/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)