diff --git a/currency_rate_inverted/README.rst b/currency_rate_inverted/README.rst new file mode 100644 index 00000000..231e8007 --- /dev/null +++ b/currency_rate_inverted/README.rst @@ -0,0 +1,103 @@ +====================== +Currency Rate Inverted +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5320232dc12a7405479ad155d83e1e267868f45e81228196dc5551d654be9c46 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fcurrency-lightgray.png?logo=github + :target: https://github.com/OCA/currency/tree/16.0/currency_rate_inverted + :alt: OCA/currency +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/currency-16-0/currency-16-0-currency_rate_inverted + :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/currency&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module applies the inverse method in the conversion between two currencies. + +The inverse method is a calculation method that uses the inverse (reciprocal) +exchange rate for the multiplier and divisor when converting amounts from one +currency to another. + +The exchange rate of the multiplier and divisor are the reciprocal, +or opposite, of each other. + +The inverse method multiplies the foreign amount by the +exchange rate to calculate the company currency (also called domestic) amount. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To convert amounts from one currency to another using the inverse method, +you have to go to *Accounting / Configuration / Accounting / Currencies*. +Then select the foreign currency that you wish to maintain inversion for +and set the flag *Inverted exchange rate*. + +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 +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* ForgeFlow (www.forgeflow.com) +* Techrifiv Solutions Pte Ltd (www.techrifiv.com.sg) +* Statecraft Systems Pte Ltd (www.statecraftsystems.sg) +* Komit (Jean-Charles Drubay ) +* `CorporateHub `__ + + * Alexey Pelykh + +* Pimolnat Suntian +* SkiBY (Sergej Ruzki ) + +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. + +This module is part of the `OCA/currency `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/currency_rate_inverted/__init__.py b/currency_rate_inverted/__init__.py new file mode 100644 index 00000000..31660d6a --- /dev/null +++ b/currency_rate_inverted/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/currency_rate_inverted/__manifest__.py b/currency_rate_inverted/__manifest__.py new file mode 100644 index 00000000..2fe1b8a5 --- /dev/null +++ b/currency_rate_inverted/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) +# Copyright 2021 ForgeFlow, S.L. +# Copyright 2015 Techrifiv Solutions Pte Ltd +# Copyright 2015 Statecraft Systems Pte Ltd +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Currency Rate Inverted", + "version": "16.0.1.0.0", + "category": "Accounting & Finance", + "summary": "Allows to maintain an exchange rate using the inversion method", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/currency", + "license": "AGPL-3", + "depends": ["base"], + "data": ["views/res_currency_view.xml"], + "installable": True, +} diff --git a/currency_rate_inverted/i18n/ca.po b/currency_rate_inverted/i18n/ca.po new file mode 100644 index 00000000..5e055994 --- /dev/null +++ b/currency_rate_inverted/i18n/ca.po @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * currency_rate_inverted +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-03-26 19:46+0000\n" +"Last-Translator: eduardgm \n" +"Language-Team: none\n" +"Language: ca\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.3.2\n" + +#. module: currency_rate_inverted +#: model:ir.model,name:currency_rate_inverted.model_res_currency +msgid "Currency" +msgstr "Moneda" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__display_name +msgid "Display Name" +msgstr "" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__id +msgid "ID" +msgstr "" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__rate_inverted +msgid "Inverted exchange rate" +msgstr "Tipus de canvi invertit" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency____last_update +msgid "Last Modified on" +msgstr "" diff --git a/currency_rate_inverted/i18n/currency_rate_inverted.pot b/currency_rate_inverted/i18n/currency_rate_inverted.pot new file mode 100644 index 00000000..f4425c28 --- /dev/null +++ b/currency_rate_inverted/i18n/currency_rate_inverted.pot @@ -0,0 +1,39 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * currency_rate_inverted +# +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_inverted +#: model:ir.model,name:currency_rate_inverted.model_res_currency +msgid "Currency" +msgstr "" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__display_name +msgid "Display Name" +msgstr "" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__id +msgid "ID" +msgstr "" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__rate_inverted +msgid "Inverted exchange rate" +msgstr "" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency____last_update +msgid "Last Modified on" +msgstr "" diff --git a/currency_rate_inverted/i18n/es.po b/currency_rate_inverted/i18n/es.po new file mode 100644 index 00000000..f09ada96 --- /dev/null +++ b/currency_rate_inverted/i18n/es.po @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * currency_rate_inverted +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-19 14:36+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\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_inverted +#: model:ir.model,name:currency_rate_inverted.model_res_currency +msgid "Currency" +msgstr "Moneda" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__id +msgid "ID" +msgstr "ID (identificación)" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__rate_inverted +msgid "Inverted exchange rate" +msgstr "Tipo de cambio invertido" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency____last_update +msgid "Last Modified on" +msgstr "Última Modificación el" diff --git a/currency_rate_inverted/i18n/es_AR.po b/currency_rate_inverted/i18n/es_AR.po new file mode 100644 index 00000000..6ba8d8af --- /dev/null +++ b/currency_rate_inverted/i18n/es_AR.po @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * currency_rate_inverted +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-07-28 05:06+0000\n" +"Last-Translator: Ignacio Buioli \n" +"Language-Team: none\n" +"Language: es_AR\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.3.2\n" + +#. module: currency_rate_inverted +#: model:ir.model,name:currency_rate_inverted.model_res_currency +msgid "Currency" +msgstr "Moneda" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__id +msgid "ID" +msgstr "ID" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__rate_inverted +msgid "Inverted exchange rate" +msgstr "Tasa de cambio invertida" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency____last_update +msgid "Last Modified on" +msgstr "Última modificación en" diff --git a/currency_rate_inverted/i18n/fr.po b/currency_rate_inverted/i18n/fr.po new file mode 100644 index 00000000..cd088470 --- /dev/null +++ b/currency_rate_inverted/i18n/fr.po @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * currency_rate_inverted +# +# Translators: +# Quentin THEURET , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-04-11 12:43+0000\n" +"PO-Revision-Date: 2023-06-10 20:18+0000\n" +"Last-Translator: Claude R Perrin \n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"Language: fr\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_inverted +#: model:ir.model,name:currency_rate_inverted.model_res_currency +msgid "Currency" +msgstr "Devise" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__display_name +msgid "Display Name" +msgstr "Nom affiché" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__id +msgid "ID" +msgstr "ID" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__rate_inverted +msgid "Inverted exchange rate" +msgstr "Taux de change inversé" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency____last_update +msgid "Last Modified on" +msgstr "Dernière modification le" diff --git a/currency_rate_inverted/i18n/hr.po b/currency_rate_inverted/i18n/hr.po new file mode 100644 index 00000000..dfa28a58 --- /dev/null +++ b/currency_rate_inverted/i18n/hr.po @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * currency_rate_inverted +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-11-13 15:34+0000\n" +"Last-Translator: Bole \n" +"Language-Team: none\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" +"X-Generator: Weblate 3.8\n" + +#. module: currency_rate_inverted +#: model:ir.model,name:currency_rate_inverted.model_res_currency +msgid "Currency" +msgstr "Valuta" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__display_name +msgid "Display Name" +msgstr "" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__id +msgid "ID" +msgstr "" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__rate_inverted +msgid "Inverted exchange rate" +msgstr "Inverzni tečaj" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency____last_update +msgid "Last Modified on" +msgstr "" diff --git a/currency_rate_inverted/i18n/it.po b/currency_rate_inverted/i18n/it.po new file mode 100644 index 00000000..6c10a5f6 --- /dev/null +++ b/currency_rate_inverted/i18n/it.po @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * currency_rate_inverted +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-29 12:36+0000\n" +"Last-Translator: Francesco Foresti \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_inverted +#: model:ir.model,name:currency_rate_inverted.model_res_currency +msgid "Currency" +msgstr "Valuta" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__id +msgid "ID" +msgstr "ID" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency__rate_inverted +msgid "Inverted exchange rate" +msgstr "Tasso di cambio invertito" + +#. module: currency_rate_inverted +#: model:ir.model.fields,field_description:currency_rate_inverted.field_res_currency____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" diff --git a/currency_rate_inverted/models/__init__.py b/currency_rate_inverted/models/__init__.py new file mode 100644 index 00000000..e6fbed83 --- /dev/null +++ b/currency_rate_inverted/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import res_currency diff --git a/currency_rate_inverted/models/res_currency.py b/currency_rate_inverted/models/res_currency.py new file mode 100644 index 00000000..e38cbd5a --- /dev/null +++ b/currency_rate_inverted/models/res_currency.py @@ -0,0 +1,36 @@ +# Copyright 2021 Sergej Ruzki. ReSuSolutions. +# Copyright 2021 ForgeFlow, S.L. +# Copyright 2015 Techrifiv Solutions Pte Ltd +# Copyright 2015 Statecraft Systems Pte Ltd +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class ResCurrency(models.Model): + _inherit = "res.currency" + + rate_inverted = fields.Boolean( + string="Inverted exchange rate", + company_dependent=True, + ) + + @api.model + def _get_conversion_rate(self, from_currency, to_currency, company, date): + rate = super()._get_conversion_rate(from_currency, to_currency, company, date) + + from_currency = from_currency.with_company(company) + to_currency = to_currency.with_company(company) + + if not from_currency.rate_inverted and not to_currency.rate_inverted: + return rate + elif from_currency.rate_inverted and to_currency.rate_inverted: + return 1 / rate + + currency_rates = (from_currency + to_currency)._get_rates(company, date) + l_rate = currency_rates.get(to_currency.id) + r_rate = currency_rates.get(from_currency.id) + if not from_currency.rate_inverted and to_currency.rate_inverted: + return 1 / (l_rate * r_rate) + elif from_currency.rate_inverted and not to_currency.rate_inverted: + return l_rate * r_rate diff --git a/currency_rate_inverted/readme/CONFIGURE.rst b/currency_rate_inverted/readme/CONFIGURE.rst new file mode 100644 index 00000000..7668e67d --- /dev/null +++ b/currency_rate_inverted/readme/CONFIGURE.rst @@ -0,0 +1,4 @@ +To convert amounts from one currency to another using the inverse method, +you have to go to *Accounting / Configuration / Accounting / Currencies*. +Then select the foreign currency that you wish to maintain inversion for +and set the flag *Inverted exchange rate*. diff --git a/currency_rate_inverted/readme/CONTRIBUTORS.rst b/currency_rate_inverted/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..7007a775 --- /dev/null +++ b/currency_rate_inverted/readme/CONTRIBUTORS.rst @@ -0,0 +1,10 @@ +* ForgeFlow (www.forgeflow.com) +* Techrifiv Solutions Pte Ltd (www.techrifiv.com.sg) +* Statecraft Systems Pte Ltd (www.statecraftsystems.sg) +* Komit (Jean-Charles Drubay ) +* `CorporateHub `__ + + * Alexey Pelykh + +* Pimolnat Suntian +* SkiBY (Sergej Ruzki ) diff --git a/currency_rate_inverted/readme/DESCRIPTION.rst b/currency_rate_inverted/readme/DESCRIPTION.rst new file mode 100644 index 00000000..163cdec3 --- /dev/null +++ b/currency_rate_inverted/readme/DESCRIPTION.rst @@ -0,0 +1,11 @@ +This module applies the inverse method in the conversion between two currencies. + +The inverse method is a calculation method that uses the inverse (reciprocal) +exchange rate for the multiplier and divisor when converting amounts from one +currency to another. + +The exchange rate of the multiplier and divisor are the reciprocal, +or opposite, of each other. + +The inverse method multiplies the foreign amount by the +exchange rate to calculate the company currency (also called domestic) amount. diff --git a/currency_rate_inverted/static/description/icon.png b/currency_rate_inverted/static/description/icon.png new file mode 100644 index 00000000..69a8569d Binary files /dev/null and b/currency_rate_inverted/static/description/icon.png differ diff --git a/currency_rate_inverted/static/description/index.html b/currency_rate_inverted/static/description/index.html new file mode 100644 index 00000000..00a99973 --- /dev/null +++ b/currency_rate_inverted/static/description/index.html @@ -0,0 +1,447 @@ + + + + + +Currency Rate Inverted + + + +
+

Currency Rate Inverted

+ + +

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

+

This module applies the inverse method in the conversion between two currencies.

+

The inverse method is a calculation method that uses the inverse (reciprocal) +exchange rate for the multiplier and divisor when converting amounts from one +currency to another.

+

The exchange rate of the multiplier and divisor are the reciprocal, +or opposite, of each other.

+

The inverse method multiplies the foreign amount by the +exchange rate to calculate the company currency (also called domestic) amount.

+

Table of contents

+ +
+

Configuration

+

To convert amounts from one currency to another using the inverse method, +you have to go to Accounting / Configuration / Accounting / Currencies. +Then select the foreign currency that you wish to maintain inversion for +and set the flag Inverted exchange rate.

+
+
+

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

+
    +
  • ForgeFlow
  • +
+
+
+

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.

+

This module is part of the OCA/currency project on GitHub.

+

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

+
+
+
+ + diff --git a/currency_rate_inverted/tests/__init__.py b/currency_rate_inverted/tests/__init__.py new file mode 100644 index 00000000..e342d64b --- /dev/null +++ b/currency_rate_inverted/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_currency_rate_inverted diff --git a/currency_rate_inverted/tests/test_currency_rate_inverted.py b/currency_rate_inverted/tests/test_currency_rate_inverted.py new file mode 100644 index 00000000..5d2c8a0b --- /dev/null +++ b/currency_rate_inverted/tests/test_currency_rate_inverted.py @@ -0,0 +1,107 @@ +# Copyright 2019 Brainbean Apps +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from datetime import timedelta + +from odoo import fields +from odoo.tests import common + + +class TestCurrencyRateInverted(common.SavepointCase): + def setUp(self): + super().setUp() + + self.today = fields.Date.today() + self.Currency = self.env["res.currency"] + self.SudoCurrency = self.Currency.sudo() + self.eur = self.SudoCurrency.search([("name", "=", "EUR")], limit=1) + self.usd = self.SudoCurrency.search([("name", "=", "USD")], limit=1) + self.gbp = self.SudoCurrency.search( + [("name", "=", "GBP"), ("active", "=", False)], limit=1 + ) + self.gbp.active = True + + def test_1(self): + self.eur.write( + {"rate_ids": [(0, False, {"name": self.today + timedelta(days=10)})]} + ) + self.usd.write( + { + "rate_ids": [ + (0, False, {"name": self.today + timedelta(days=10), "rate": 0.8}) + ], + } + ) + self.gbp.write( + { + "rate_ids": [ + (0, False, {"name": self.today + timedelta(days=10), "rate": 1.1}) + ], + } + ) + + self.usd.rate_inverted = True + self.assertAlmostEqual( + self.eur.with_context(date=self.today + timedelta(days=10)).compute( + 1.0, self.usd + ), + 1.25, + 2, + ) + self.assertAlmostEqual( + self.usd.with_context(date=self.today + timedelta(days=10)).compute( + 1.0, self.eur + ), + 0.8, + 2, + ) + + self.gbp.rate_inverted = True + self.assertAlmostEqual( + self.gbp.with_context(date=self.today + timedelta(days=10)).compute( + 1.0, self.usd + ), + 1.38, + 2, + ) + self.gbp.rate_inverted = False + self.assertAlmostEqual( + self.gbp.with_context(date=self.today + timedelta(days=10)).compute( + 1.0, self.usd + ), + 1.14, + 2, + ) + + self.usd.rate_inverted = False + self.assertAlmostEqual( + self.eur.with_context(date=self.today + timedelta(days=10)).compute( + 1.0, self.usd + ), + 0.8, + 2, + ) + self.assertAlmostEqual( + self.usd.with_context(date=self.today + timedelta(days=10)).compute( + 1.0, self.eur + ), + 1.25, + 2, + ) + + self.gbp.rate_inverted = True + self.assertAlmostEqual( + self.gbp.with_context(date=self.today + timedelta(days=10)).compute( + 1.0, self.usd + ), + 0.88, + 2, + ) + self.gbp.rate_inverted = False + self.assertAlmostEqual( + self.gbp.with_context(date=self.today + timedelta(days=10)).compute( + 1.0, self.usd + ), + 0.73, + 2, + ) diff --git a/currency_rate_inverted/views/res_currency_view.xml b/currency_rate_inverted/views/res_currency_view.xml new file mode 100644 index 00000000..1b741dcc --- /dev/null +++ b/currency_rate_inverted/views/res_currency_view.xml @@ -0,0 +1,23 @@ + + + + res.currency.tree + res.currency + + + + + + + + + res.currency.form + res.currency + + + + + + + + diff --git a/setup/currency_rate_inverted/odoo/addons/currency_rate_inverted b/setup/currency_rate_inverted/odoo/addons/currency_rate_inverted new file mode 120000 index 00000000..85b97192 --- /dev/null +++ b/setup/currency_rate_inverted/odoo/addons/currency_rate_inverted @@ -0,0 +1 @@ +../../../../currency_rate_inverted \ No newline at end of file diff --git a/setup/currency_rate_inverted/setup.py b/setup/currency_rate_inverted/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/currency_rate_inverted/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)