diff --git a/product_pricelist_fixed_currency_rate/README.rst b/product_pricelist_fixed_currency_rate/README.rst new file mode 100644 index 00000000000..16686474e5f --- /dev/null +++ b/product_pricelist_fixed_currency_rate/README.rst @@ -0,0 +1,104 @@ +===================================== +Product Pricelist Fixed Currency Rate +===================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:db69ced5276e16601e3f8a0dad96a12d837f7d194b980fa9fcc44a77ddf508d4 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fproduct--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/18.0/product_pricelist_fixed_currency_rate + :alt: OCA/product-attribute +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_pricelist_fixed_currency_rate + :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/product-attribute&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the product pricelists feature to allow to set a +fixed currency rate to convert from a pricelist with a different +currency. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +When using advanced price rules: + +1. Go to a pricelist and create a pricelist with a given currency. +2. Create a new pricelist rule with computation formula. +3. Make it based on other pricelist that uses a different currency. +4. *Fixed Currency Rate* will show up, set a value. + +This will force the currency conversion to always use the specified +*Fixed Currency Rate* rate when using this pricelist. + +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 +------------ + +- Lois Rilo +- Mohamed Alkobrosli +- Heliconia Solutions Pvt. Ltd. + +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-LoisRForgeFlow| image:: https://github.com/LoisRForgeFlow.png?size=40px + :target: https://github.com/LoisRForgeFlow + :alt: LoisRForgeFlow +.. |maintainer-kobros-tech| image:: https://github.com/kobros-tech.png?size=40px + :target: https://github.com/kobros-tech + :alt: kobros-tech + +Current `maintainers `__: + +|maintainer-LoisRForgeFlow| |maintainer-kobros-tech| + +This module is part of the `OCA/product-attribute `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_pricelist_fixed_currency_rate/__init__.py b/product_pricelist_fixed_currency_rate/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/product_pricelist_fixed_currency_rate/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_pricelist_fixed_currency_rate/__manifest__.py b/product_pricelist_fixed_currency_rate/__manifest__.py new file mode 100644 index 00000000000..822014290a5 --- /dev/null +++ b/product_pricelist_fixed_currency_rate/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + "name": "Product Pricelist Fixed Currency Rate", + "summary": "Set a fixed currency rate between pricelists", + "version": "18.0.1.0.0", + "category": "Product", + "website": "https://github.com/OCA/product-attribute", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "maintainers": ["LoisRForgeFlow", "kobros-tech"], + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["product"], + "data": [ + "views/pricelist_views.xml", + ], +} diff --git a/product_pricelist_fixed_currency_rate/i18n/es.po b/product_pricelist_fixed_currency_rate/i18n/es.po new file mode 100644 index 00000000000..aa833fbc230 --- /dev/null +++ b/product_pricelist_fixed_currency_rate/i18n/es.po @@ -0,0 +1,84 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_pricelist_fixed_currency_rate +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-11-15 20:38+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: product_pricelist_fixed_currency_rate +#. odoo-python +#: code:addons/product_pricelist_fixed_currency_rate/models/product_pricelist_item.py:0 +#, python-format +msgid "({curr_from} to {curr_to} rates)" +msgstr "({curr_from} to {curr_to} rates)" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__actual_currency_rate +msgid "Actual Currency Rate" +msgstr "Tipo de Cambio Real" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model,name:product_pricelist_fixed_currency_rate.model_res_currency +msgid "Currency" +msgstr "Divisa" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__currency_rate_tooltip +msgid "Currency Rate Tooltip" +msgstr "Información sobre el Tipo de Cambio" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__do_inverse_currency_rate +msgid "Do Inverse Currency Rate" +msgstr "Invertir el Tipo de Cambio" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__fixed_currency_rate +msgid "Fixed Currency Rate" +msgstr "Tipo de Cambio Fijo" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,help:product_pricelist_fixed_currency_rate.field_product_pricelist_item__fixed_currency_rate +#: model:ir.model.fields,help:product_pricelist_fixed_currency_rate.field_product_pricelist_item__inverse_fixed_currency_rate +msgid "" +"If set (different to 0.0), the currency conversion will ignore the actual " +"currency rate and always use the fixed currency rate." +msgstr "" +"Si se establece (diferente a 0.0), la conversión de moneda ignorará el tipo " +"de moneda actual y utilizará siempre el tipo de moneda fijo." + +#. module: product_pricelist_fixed_currency_rate +#: model_terms:ir.ui.view,arch_db:product_pricelist_fixed_currency_rate.product_pricelist_item_form_view +msgid "Inverse" +msgstr "Inverso" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__inverse_actual_currency_rate +msgid "Inverse Actual Currency Rate" +msgstr "Tipo de Divisa Real Inverso" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__inverse_fixed_currency_rate +msgid "Inverse Fixed Currency Rate" +msgstr "Tipo de Cambio Fijo Inverso" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__is_fixed_currency_rate_applicable +msgid "Is Fixed Currency Rate Applicable" +msgstr "Es aplicable el tipo de cambio fijo" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model,name:product_pricelist_fixed_currency_rate.model_product_pricelist_item +msgid "Pricelist Rule" +msgstr "Regla de la lista de precios" diff --git a/product_pricelist_fixed_currency_rate/i18n/it.po b/product_pricelist_fixed_currency_rate/i18n/it.po new file mode 100644 index 00000000000..14a78f87f38 --- /dev/null +++ b/product_pricelist_fixed_currency_rate/i18n/it.po @@ -0,0 +1,84 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_pricelist_fixed_currency_rate +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-11-13 16:38+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: product_pricelist_fixed_currency_rate +#. odoo-python +#: code:addons/product_pricelist_fixed_currency_rate/models/product_pricelist_item.py:0 +#, python-format +msgid "({curr_from} to {curr_to} rates)" +msgstr "(tasso da {curr_from} a {curr_to})" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__actual_currency_rate +msgid "Actual Currency Rate" +msgstr "Tasso valuta attuale" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model,name:product_pricelist_fixed_currency_rate.model_res_currency +msgid "Currency" +msgstr "Valuta" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__currency_rate_tooltip +msgid "Currency Rate Tooltip" +msgstr "Nota tasso valuta" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__do_inverse_currency_rate +msgid "Do Inverse Currency Rate" +msgstr "Inverti tasso valuta" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__fixed_currency_rate +msgid "Fixed Currency Rate" +msgstr "Tasso valuta fisso" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,help:product_pricelist_fixed_currency_rate.field_product_pricelist_item__fixed_currency_rate +#: model:ir.model.fields,help:product_pricelist_fixed_currency_rate.field_product_pricelist_item__inverse_fixed_currency_rate +msgid "" +"If set (different to 0.0), the currency conversion will ignore the actual " +"currency rate and always use the fixed currency rate." +msgstr "" +"Se impostata (diversa da 0,0), la vonversione di valuta ignorerà il tasso " +"valuta attuale e userà sempre il tasso valuta fisso." + +#. module: product_pricelist_fixed_currency_rate +#: model_terms:ir.ui.view,arch_db:product_pricelist_fixed_currency_rate.product_pricelist_item_form_view +msgid "Inverse" +msgstr "Inverso" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__inverse_actual_currency_rate +msgid "Inverse Actual Currency Rate" +msgstr "Inverso tasso valuta attuale" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__inverse_fixed_currency_rate +msgid "Inverse Fixed Currency Rate" +msgstr "Inverso tasso valuta fisso" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__is_fixed_currency_rate_applicable +msgid "Is Fixed Currency Rate Applicable" +msgstr "È applicabile il tasso valuta fisso" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model,name:product_pricelist_fixed_currency_rate.model_product_pricelist_item +msgid "Pricelist Rule" +msgstr "Regola listino prezzi" diff --git a/product_pricelist_fixed_currency_rate/i18n/product_pricelist_fixed_currency_rate.pot b/product_pricelist_fixed_currency_rate/i18n/product_pricelist_fixed_currency_rate.pot new file mode 100644 index 00000000000..1117b4ce686 --- /dev/null +++ b/product_pricelist_fixed_currency_rate/i18n/product_pricelist_fixed_currency_rate.pot @@ -0,0 +1,79 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_pricelist_fixed_currency_rate +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.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: product_pricelist_fixed_currency_rate +#. odoo-python +#: code:addons/product_pricelist_fixed_currency_rate/models/product_pricelist_item.py:0 +#, python-format +msgid "({curr_from} to {curr_to} rates)" +msgstr "" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__actual_currency_rate +msgid "Actual Currency Rate" +msgstr "" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model,name:product_pricelist_fixed_currency_rate.model_res_currency +msgid "Currency" +msgstr "" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__currency_rate_tooltip +msgid "Currency Rate Tooltip" +msgstr "" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__do_inverse_currency_rate +msgid "Do Inverse Currency Rate" +msgstr "" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__fixed_currency_rate +msgid "Fixed Currency Rate" +msgstr "" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,help:product_pricelist_fixed_currency_rate.field_product_pricelist_item__fixed_currency_rate +#: model:ir.model.fields,help:product_pricelist_fixed_currency_rate.field_product_pricelist_item__inverse_fixed_currency_rate +msgid "" +"If set (different to 0.0), the currency conversion will ignore the actual " +"currency rate and always use the fixed currency rate." +msgstr "" + +#. module: product_pricelist_fixed_currency_rate +#: model_terms:ir.ui.view,arch_db:product_pricelist_fixed_currency_rate.product_pricelist_item_form_view +msgid "Inverse" +msgstr "" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__inverse_actual_currency_rate +msgid "Inverse Actual Currency Rate" +msgstr "" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__inverse_fixed_currency_rate +msgid "Inverse Fixed Currency Rate" +msgstr "" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model.fields,field_description:product_pricelist_fixed_currency_rate.field_product_pricelist_item__is_fixed_currency_rate_applicable +msgid "Is Fixed Currency Rate Applicable" +msgstr "" + +#. module: product_pricelist_fixed_currency_rate +#: model:ir.model,name:product_pricelist_fixed_currency_rate.model_product_pricelist_item +msgid "Pricelist Rule" +msgstr "" diff --git a/product_pricelist_fixed_currency_rate/models/__init__.py b/product_pricelist_fixed_currency_rate/models/__init__.py new file mode 100644 index 00000000000..612e869f33a --- /dev/null +++ b/product_pricelist_fixed_currency_rate/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_pricelist_item +from . import res_currency diff --git a/product_pricelist_fixed_currency_rate/models/product_pricelist_item.py b/product_pricelist_fixed_currency_rate/models/product_pricelist_item.py new file mode 100644 index 00000000000..6dd74ec8745 --- /dev/null +++ b/product_pricelist_fixed_currency_rate/models/product_pricelist_item.py @@ -0,0 +1,110 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models + + +class ProductPricelist(models.Model): + _inherit = "product.pricelist.item" + + fixed_currency_rate = fields.Float( + digits=(12, 12), + help="If set (different to 0.0), the currency conversion will " + "ignore the actual currency rate and always use the fixed " + "currency rate.", + ) + inverse_fixed_currency_rate = fields.Float( + digits=(12, 12), + compute="_compute_inverse_fixed_currency_rate", + inverse="_inverse_inverse_fixed_currency_rate", + help="If set (different to 0.0), the currency conversion will " + "ignore the actual currency rate and always use the fixed " + "currency rate.", + ) + is_fixed_currency_rate_applicable = fields.Boolean( + compute="_compute_is_fixed_currency_rate_applicable" + ) + actual_currency_rate = fields.Float( + digits=(12, 12), compute="_compute_is_fixed_currency_rate_applicable" + ) + inverse_actual_currency_rate = fields.Float( + digits=(12, 12), compute="_compute_is_fixed_currency_rate_applicable" + ) + do_inverse_currency_rate = fields.Boolean( + compute="_compute_do_inverse_currency_rate", + store=True, + readonly=False, + ) + currency_rate_tooltip = fields.Char( + compute="_compute_currency_rate_tooltip", + ) + + @api.depends("base_pricelist_id", "base_pricelist_id.currency_id", "base") + def _compute_is_fixed_currency_rate_applicable(self): + for rec in self: + applicable = ( + rec.base == "pricelist" + and rec.base_pricelist_id + and rec.base_pricelist_id.currency_id != rec.pricelist_id.currency_id + ) + rec.is_fixed_currency_rate_applicable = applicable + if applicable: + curr_from = rec.base_pricelist_id.currency_id + curr_to = rec.pricelist_id.currency_id + company = rec.company_id or self.env.company + rate = self.env["res.currency"]._get_conversion_rate( + curr_from, curr_to, company, rec.date_end or fields.Date.today() + ) + rec.actual_currency_rate = rate + rec.inverse_actual_currency_rate = 1 / rate if rate else 0.0 + else: + rec.actual_currency_rate = 1.0 + rec.inverse_actual_currency_rate = 1.0 + + def _compute_base_price(self, product, quantity, uom, date, target_currency): + if self.is_fixed_currency_rate_applicable and self.fixed_currency_rate: + return super( + ProductPricelist, + self.with_context(fixed_currency_rate=self.fixed_currency_rate), + )._compute_base_price(product, quantity, uom, date, target_currency) + return super()._compute_base_price( + product, quantity, uom, date, target_currency + ) + + @api.depends("base_pricelist_id", "base_pricelist_id.currency_id") + def _compute_do_inverse_currency_rate(self): + for rec in self: + if rec.is_fixed_currency_rate_applicable: + rec.do_inverse_currency_rate = rec.actual_currency_rate < 1.0 + + @api.depends("do_inverse_currency_rate") + def _compute_currency_rate_tooltip(self): + for rec in self: + if rec.do_inverse_currency_rate: + curr_from = rec.pricelist_id.currency_id + curr_to = rec.base_pricelist_id.currency_id + else: + curr_from = rec.base_pricelist_id.currency_id + curr_to = rec.pricelist_id.currency_id + rec.currency_rate_tooltip = _("({curr_from} to {curr_to} rates)").format( + curr_from=curr_from.name, curr_to=curr_to.name + ) + + @api.depends("fixed_currency_rate") + def _compute_inverse_fixed_currency_rate(self): + for rec in self: + rec.inverse_fixed_currency_rate = ( + 1 / rec.fixed_currency_rate if rec.fixed_currency_rate else 0.0 + ) + + def _inverse_inverse_fixed_currency_rate(self): + for rec in self: + rec.fixed_currency_rate = ( + 1 / rec.inverse_fixed_currency_rate + if rec.inverse_fixed_currency_rate + else 0.0 + ) + + def toggle_do_inverse_currency_rate(self): + for rec in self: + rec.do_inverse_currency_rate = not rec.do_inverse_currency_rate diff --git a/product_pricelist_fixed_currency_rate/models/res_currency.py b/product_pricelist_fixed_currency_rate/models/res_currency.py new file mode 100644 index 00000000000..e04f08f4987 --- /dev/null +++ b/product_pricelist_fixed_currency_rate/models/res_currency.py @@ -0,0 +1,15 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ProductPricelist(models.Model): + _inherit = "res.currency" + + @api.model + def _get_conversion_rate(self, from_currency, to_currency, company, date): + fixed_rate = self.env.context.get("fixed_currency_rate") + if fixed_rate: + return fixed_rate + return super()._get_conversion_rate(from_currency, to_currency, company, date) diff --git a/product_pricelist_fixed_currency_rate/pyproject.toml b/product_pricelist_fixed_currency_rate/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/product_pricelist_fixed_currency_rate/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/product_pricelist_fixed_currency_rate/readme/CONTRIBUTORS.md b/product_pricelist_fixed_currency_rate/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..98ff7eb6c0e --- /dev/null +++ b/product_pricelist_fixed_currency_rate/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Lois Rilo \<\> +- Mohamed Alkobrosli \<\> +- Heliconia Solutions Pvt. Ltd. \<\> diff --git a/product_pricelist_fixed_currency_rate/readme/DESCRIPTION.md b/product_pricelist_fixed_currency_rate/readme/DESCRIPTION.md new file mode 100644 index 00000000000..2cd73ba04a1 --- /dev/null +++ b/product_pricelist_fixed_currency_rate/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module extends the product pricelists feature to allow to set a +fixed currency rate to convert from a pricelist with a different +currency. diff --git a/product_pricelist_fixed_currency_rate/readme/USAGE.md b/product_pricelist_fixed_currency_rate/readme/USAGE.md new file mode 100644 index 00000000000..3c2df0ebb1e --- /dev/null +++ b/product_pricelist_fixed_currency_rate/readme/USAGE.md @@ -0,0 +1,9 @@ +When using advanced price rules: + +1. Go to a pricelist and create a pricelist with a given currency. +2. Create a new pricelist rule with computation formula. +3. Make it based on other pricelist that uses a different currency. +4. *Fixed Currency Rate* will show up, set a value. + +This will force the currency conversion to always use the specified +*Fixed Currency Rate* rate when using this pricelist. diff --git a/product_pricelist_fixed_currency_rate/static/description/icon.png b/product_pricelist_fixed_currency_rate/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/product_pricelist_fixed_currency_rate/static/description/icon.png differ diff --git a/product_pricelist_fixed_currency_rate/static/description/index.html b/product_pricelist_fixed_currency_rate/static/description/index.html new file mode 100644 index 00000000000..3f2329c8fe5 --- /dev/null +++ b/product_pricelist_fixed_currency_rate/static/description/index.html @@ -0,0 +1,442 @@ + + + + + +Product Pricelist Fixed Currency Rate + + + +
+

Product Pricelist Fixed Currency Rate

+ + +

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

+

This module extends the product pricelists feature to allow to set a +fixed currency rate to convert from a pricelist with a different +currency.

+

Table of contents

+ +
+

Usage

+

When using advanced price rules:

+
    +
  1. Go to a pricelist and create a pricelist with a given currency.
  2. +
  3. Create a new pricelist rule with computation formula.
  4. +
  5. Make it based on other pricelist that uses a different currency.
  6. +
  7. Fixed Currency Rate will show up, set a value.
  8. +
+

This will force the currency conversion to always use the specified +Fixed Currency Rate rate when using this pricelist.

+
+
+

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.

+

Current maintainers:

+

LoisRForgeFlow kobros-tech

+

This module is part of the OCA/product-attribute project on GitHub.

+

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

+
+
+
+ + diff --git a/product_pricelist_fixed_currency_rate/tests/__init__.py b/product_pricelist_fixed_currency_rate/tests/__init__.py new file mode 100644 index 00000000000..a2463030e55 --- /dev/null +++ b/product_pricelist_fixed_currency_rate/tests/__init__.py @@ -0,0 +1 @@ +from . import test_product_pricelist_fixed_currency_rate diff --git a/product_pricelist_fixed_currency_rate/tests/test_product_pricelist_fixed_currency_rate.py b/product_pricelist_fixed_currency_rate/tests/test_product_pricelist_fixed_currency_rate.py new file mode 100644 index 00000000000..b5ce81d18a3 --- /dev/null +++ b/product_pricelist_fixed_currency_rate/tests/test_product_pricelist_fixed_currency_rate.py @@ -0,0 +1,190 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo.tests import common + + +class TestProductPricelistFixedCurrencyRate(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.pricelist_model = cls.env["product.pricelist"] + cls.product_model = cls.env["product.product"] + + cls.company = cls.env["res.company"].create( + { + "name": "Test", + "currency_id": cls.env.ref("base.EUR").id, + } + ) + cls.env.user.company_id = cls.company + + cls.product_1 = cls.product_model.create( + { + "name": "Product 1", + "list_price": 150.00, + "company_id": cls.company.id, + } + ) + cls.product_2 = cls.product_model.create( + { + "name": "Product 1", + "list_price": 200.00, + "company_id": cls.company.id, + } + ) + + cls.pricelist_eur = cls.pricelist_model.create( + { + "name": "Pricelist EUR", + "currency_id": cls.env.ref("base.EUR").id, + "company_id": cls.company.id, + "item_ids": [ + ( + 0, + 0, + { + "applied_on": "0_product_variant", + "compute_price": "fixed", + "product_id": cls.product_1.id, + "fixed_price": 140.00, + }, + ) + ], + } + ) + cls.pricelist_usd = cls.pricelist_model.create( + { + "name": "Pricelist USD", + "currency_id": cls.env.ref("base.USD").id, + "company_id": cls.company.id, + "item_ids": [ + ( + 0, + 0, + { + "applied_on": "3_global", + "compute_price": "formula", + "base": "pricelist", + "base_pricelist_id": cls.pricelist_eur.id, + }, + ) + ], + } + ) + cls.pricelist_usd_fixed_rate = cls.pricelist_model.create( + { + "name": "Pricelist USD", + "currency_id": cls.env.ref("base.USD").id, + "company_id": cls.company.id, + "item_ids": [ + ( + 0, + 0, + { + "applied_on": "3_global", + "compute_price": "formula", + "base": "pricelist", + "base_pricelist_id": cls.pricelist_eur.id, + "fixed_currency_rate": 2.0, + }, + ) + ], + } + ) + # Clean rates: + cls.env["res.currency.rate"].search( + [ + ("currency_id", "=", cls.env.ref("base.USD").id), + ("company_id", "=", cls.company.id), + ] + ).unlink() + cls.env["res.currency.rate"].create( + { + "name": "2023-01-01", + "rate": 1.5, + "currency_id": cls.env.ref("base.USD").id, + "company_id": cls.company.id, + } + ) + + def test_01_pricelist_currency_rate(self): + # Product 1 (item in base pricelist) + self.assertEqual(self.env.company.currency_id, self.env.ref("base.EUR")) + eur_price_1 = self.pricelist_eur._get_product_price(self.product_1, 1.0) + self.assertEqual(eur_price_1, 140.0) + usd_price_1 = self.pricelist_usd._get_product_price(self.product_1, 1.0) + expected = 140 * 1.5 + self.assertEqual(usd_price_1, expected) + usd_fr_price_1 = self.pricelist_usd_fixed_rate._get_product_price( + self.product_1, 1.0 + ) + expected = 140 * 2.0 + self.assertEqual(usd_fr_price_1, expected) + # Product 2 (no item in base pricelist) + eur_price_2 = self.pricelist_eur._get_product_price(self.product_2, 1.0) + self.assertEqual(eur_price_2, 200.0) + usd_price_2 = self.pricelist_usd._get_product_price(self.product_2, 1.0) + expected = 200 * 1.5 + self.assertEqual(usd_price_2, expected) + usd_fr_price_2 = self.pricelist_usd_fixed_rate._get_product_price( + self.product_2, 1.0 + ) + expected = 200 * 2.0 + self.assertEqual(usd_fr_price_2, expected) + + def test_02_auxiliary_fields(self): + item = self.pricelist_usd_fixed_rate.item_ids + self.assertTrue(item.is_fixed_currency_rate_applicable) + self.assertEqual(item.actual_currency_rate, 1.5) + + def test_03_currency_rate_tooltip(self): + item = self.pricelist_usd_fixed_rate.item_ids + + # Case 1 + item.do_inverse_currency_rate = True + curr_from = item.pricelist_id.currency_id + curr_to = item.base_pricelist_id.currency_id + currency_rate_tooltip = f"({curr_from.name} to {curr_to.name} rates)" + self.assertEqual(item.currency_rate_tooltip, currency_rate_tooltip) + + # Case 2 + item.do_inverse_currency_rate = False + curr_from = item.base_pricelist_id.currency_id + curr_to = item.pricelist_id.currency_id + currency_rate_tooltip = f"({curr_from.name} to {curr_to.name} rates)" + self.assertEqual(item.currency_rate_tooltip, currency_rate_tooltip) + + def test_04_inverse_fixed_currency_rate(self): + item = self.pricelist_usd_fixed_rate.item_ids + inverse_fixed_currency_rate = ( + 1 / item.fixed_currency_rate if item.fixed_currency_rate else 0.0 + ) + self.assertEqual(item.inverse_fixed_currency_rate, inverse_fixed_currency_rate) + + def test_05_fixed_currency_rate(self): + item = self.pricelist_usd_fixed_rate.item_ids + + # Case 1 + item.fixed_currency_rate = 0.5 + fixed_currency_rate = ( + 1 / item.inverse_fixed_currency_rate + if item.inverse_fixed_currency_rate + else 0.0 + ) + self.assertEqual(item.fixed_currency_rate, fixed_currency_rate) + + # Case 2 + item.fixed_currency_rate = 1 + fixed_currency_rate = ( + 1 / item.inverse_fixed_currency_rate + if item.inverse_fixed_currency_rate + else 0.0 + ) + self.assertEqual(item.fixed_currency_rate, fixed_currency_rate) + + def test_06_do_inverse_currency_rate(self): + item = self.pricelist_usd_fixed_rate.item_ids + do_inverse_currency_rate = not item.do_inverse_currency_rate + item.toggle_do_inverse_currency_rate() + self.assertEqual(item.do_inverse_currency_rate, do_inverse_currency_rate) diff --git a/product_pricelist_fixed_currency_rate/views/pricelist_views.xml b/product_pricelist_fixed_currency_rate/views/pricelist_views.xml new file mode 100644 index 00000000000..b356ded058e --- /dev/null +++ b/product_pricelist_fixed_currency_rate/views/pricelist_views.xml @@ -0,0 +1,44 @@ + + + + product.pricelist.item.form - product_pricelist_fixed_currency_rate + product.pricelist.item + + + + + + + + + + + + + + +