diff --git a/account_invoice_change_currency/README.rst b/account_invoice_change_currency/README.rst new file mode 100644 index 00000000000..d143a7cdeb6 --- /dev/null +++ b/account_invoice_change_currency/README.rst @@ -0,0 +1,116 @@ +================================= +Account Invoice - Change Currency +================================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Faccount--invoicing-lightgray.png?logo=github + :target: https://github.com/OCA/account-invoicing/tree/15.0/account_invoice_change_currency + :alt: OCA/account-invoicing +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-invoicing-15-0/account-invoicing-15-0-account_invoice_change_currency + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/95/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +================================== +Update currency of Account Invoice +================================== + +This module allows users to update the currency of Invoices (in draft state) by +a button Update Currency at the invoice form. +After update to new currency, all the unit prices of invoice lines will be +recomputed to new currency, thus the Total amounts (tax and without tax) of +Invoice will be in the new currency also + +Also this module allows user to set a custom rate that will be take to recompute +all lines. By default the custom rate proposed is the rate between invoice +currency and base currency (company currency), after the first coversion the +custom rate will be proposed by default between last currency and invoice +currency. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +The exchange rate will be configured in +Accounting > Configuration > Multi-Currencies > Currencies + +Usage +===== + +To use this module, the user must be in group Accounting & Finance / Adviser +to be able to update currency of Invoices + +Note : you have to save new invoice before change currency + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Vauxoo +* Komit Consulting + +Contributors +~~~~~~~~~~~~ + +* Duc, Dao Dong (https://komit-consulting.com) +* Hugo Adan +* Saran Lim. +* Rolando Duarte + +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-luisg123v| image:: https://github.com/luisg123v.png?size=40px + :target: https://github.com/luisg123v + :alt: luisg123v +.. |maintainer-rolandojduartem| image:: https://github.com/rolandojduartem.png?size=40px + :target: https://github.com/rolandojduartem + :alt: rolandojduartem + +Current `maintainers `__: + +|maintainer-luisg123v| |maintainer-rolandojduartem| + +This module is part of the `OCA/account-invoicing `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_invoice_change_currency/__init__.py b/account_invoice_change_currency/__init__.py new file mode 100644 index 00000000000..7bfe3975dea --- /dev/null +++ b/account_invoice_change_currency/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2017 Komit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import models +from .hooks import pre_init_hook diff --git a/account_invoice_change_currency/__manifest__.py b/account_invoice_change_currency/__manifest__.py new file mode 100644 index 00000000000..467dfbf57ed --- /dev/null +++ b/account_invoice_change_currency/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2017 Komit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Account Invoice - Change Currency", + "version": "16.0.1.0.0", + "category": "Accounting & Finance", + "summary": "Allows to change currency of Invoice by wizard", + "author": "Vauxoo, Komit Consulting, Odoo Community Association (OCA)", + "maintainers": ["luisg123v", "rolandojduartem"], + "website": "https://github.com/OCA/account-invoicing", + "license": "AGPL-3", + "depends": ["account"], + "data": [ + "views/account_move_views.xml", + ], + "pre_init_hook": "pre_init_hook", + "installable": True, +} diff --git a/account_invoice_change_currency/hooks.py b/account_invoice_change_currency/hooks.py new file mode 100644 index 00000000000..fa721fc6933 --- /dev/null +++ b/account_invoice_change_currency/hooks.py @@ -0,0 +1,29 @@ +import logging + +from odoo import tools + +_logger = logging.getLogger(__name__) + + +def pre_init_hook(cr): + """ + Initializing column custom_rate on table account_move + for the improvement in performance to avoid long + duration in databases with thousand of moves + """ + _logger.info("Initializing column custom_rate on table account_move") + tools.create_column( + cr=cr, + tablename="account_move", + columnname="custom_rate", + columntype="numeric", + comment="Custom Rate", + ) + cr.execute( + """ + UPDATE + account_move + SET + custom_rate = 1.0 + """ + ) diff --git a/account_invoice_change_currency/i18n/account_invoice_change_currency.pot b/account_invoice_change_currency/i18n/account_invoice_change_currency.pot new file mode 100644 index 00000000000..2849e27b3f4 --- /dev/null +++ b/account_invoice_change_currency/i18n/account_invoice_change_currency.pot @@ -0,0 +1,106 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_change_currency +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-10-11 06:39+0000\n" +"PO-Revision-Date: 2022-10-11 06:39+0000\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: account_invoice_change_currency +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "" +"" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__is_original_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__is_original_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__is_original_currency +msgid "" +"Check if current currency is the original currency. This is used to hide " +"custom rate field in the form view." +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_res_currency +msgid "Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__custom_rate +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__custom_rate +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__custom_rate +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "Custom Rate" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__is_original_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__is_original_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__is_original_currency +msgid "Is Original Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__original_currency_id +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__original_currency_id +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__original_currency_id +msgid "Original Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move_line__original_price_unit +msgid "Original Price Unit" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__custom_rate +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__custom_rate +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__custom_rate +msgid "" +"Set new currency rate to apply on the invoice.\n" +"This rate will be taken in order to convert amounts between the currency on the invoice and last currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move_line__original_price_unit +msgid "" +"Store price unit from every line when the invoice is created or the " +"conversion is called for the first time to use it to convert the amount in " +"the new currency." +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__original_currency_id +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__original_currency_id +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__original_currency_id +msgid "" +"Store the original currency when the invoice is created or the conversion is" +" called for the first time. This is used to calculate conversion from this " +"currency." +msgstr "" + +#. module: account_invoice_change_currency +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "Update Currency" +msgstr "" diff --git a/account_invoice_change_currency/i18n/ca.po b/account_invoice_change_currency/i18n/ca.po new file mode 100644 index 00000000000..57415522cd9 --- /dev/null +++ b/account_invoice_change_currency/i18n/ca.po @@ -0,0 +1,114 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_change_currency +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-08-09 10:06+0000\n" +"Last-Translator: jabelchi \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: account_invoice_change_currency +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "" +"" +msgstr "" +"" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__is_original_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__is_original_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__is_original_currency +msgid "" +"Check if current currency is the original currency. This is used to hide " +"custom rate field in the form view." +msgstr "" +"Comproveu si la divisa actual és la divisa original. Això es fa servir per a " +"ocultar el factor de conversió al formulari." + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_res_currency +msgid "Currency" +msgstr "Divisa" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__custom_rate +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__custom_rate +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__custom_rate +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "Custom Rate" +msgstr "Taxa de canvi" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__is_original_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__is_original_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__is_original_currency +msgid "Is Original Currency" +msgstr "És la divisa original" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_account_move +msgid "Journal Entry" +msgstr "Assentament comptable" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_account_move_line +msgid "Journal Item" +msgstr "Apunt comptable" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__original_currency_id +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__original_currency_id +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__original_currency_id +msgid "Original Currency" +msgstr "Divisa original" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move_line__original_price_unit +msgid "Original Price Unit" +msgstr "Preu unitari original" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__custom_rate +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__custom_rate +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__custom_rate +msgid "" +"Set new currency rate to apply on the invoice.\n" +"This rate will be taken in order to convert amounts between the currency on the invoice and last currency" +msgstr "" +"Estableix nova taxa de canvi a aplicar a la factura.\n" +"Aquesta taxa es farà servir per a convertir imports entre la divisa de la " +"factura i la darrera divisa" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move_line__original_price_unit +msgid "" +"Store price unit from every line when the invoice is created or the " +"conversion is called for the first time to use it to convert the amount in " +"the new currency." +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__original_currency_id +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__original_currency_id +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__original_currency_id +msgid "" +"Store the original currency when the invoice is created or the conversion is" +" called for the first time. This is used to calculate conversion from this " +"currency." +msgstr "" + +#. module: account_invoice_change_currency +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "Update Currency" +msgstr "Actualitzar divisa" diff --git a/account_invoice_change_currency/i18n/de.po b/account_invoice_change_currency/i18n/de.po new file mode 100644 index 00000000000..2ff677d184b --- /dev/null +++ b/account_invoice_change_currency/i18n/de.po @@ -0,0 +1,125 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_change_currency +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-06-12 13:19+0000\n" +"Last-Translator: Maria Sparenberg \n" +"Language-Team: none\n" +"Language: de\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 3.10\n" + +#. module: account_invoice_change_currency +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "" +"" +msgstr "" +"" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__is_original_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__is_original_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__is_original_currency +msgid "" +"Check if current currency is the original currency. This is used to hide " +"custom rate field in the form view." +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_res_currency +msgid "Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__custom_rate +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__custom_rate +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__custom_rate +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "Custom Rate" +msgstr "Umrechungsfaktor" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__is_original_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__is_original_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__is_original_currency +msgid "Is Original Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__original_currency_id +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__original_currency_id +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__original_currency_id +msgid "Original Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move_line__original_price_unit +msgid "Original Price Unit" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__custom_rate +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__custom_rate +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__custom_rate +msgid "" +"Set new currency rate to apply on the invoice.\n" +"This rate will be taken in order to convert amounts between the currency on " +"the invoice and last currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move_line__original_price_unit +msgid "" +"Store price unit from every line when the invoice is created or the " +"conversion is called for the first time to use it to convert the amount in " +"the new currency." +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__original_currency_id +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__original_currency_id +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__original_currency_id +msgid "" +"Store the original currency when the invoice is created or the conversion is " +"called for the first time. This is used to calculate conversion from this " +"currency." +msgstr "" + +#. module: account_invoice_change_currency +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "Update Currency" +msgstr "" + +#~ msgid "Currency Updated" +#~ msgstr "Währung aktualisiert" + +#~ msgid "Invoice" +#~ msgstr "Rechnung" + +#~ msgid "" +#~ "Set new currency rate to apply on the invoice\n" +#~ ".This rate will be taken in order to convert amounts between the currency " +#~ "on the invoice and last currency" +#~ msgstr "" +#~ "Bitte hier den neuen Umrechnungsfaktor für die Währung angeben.\n" +#~ "Der Faktor wird verwendet, um die Beträge in der Rechnung entsprechend " +#~ "umzurechnen." diff --git a/account_invoice_change_currency/i18n/es.po b/account_invoice_change_currency/i18n/es.po new file mode 100644 index 00000000000..3becee6b5c3 --- /dev/null +++ b/account_invoice_change_currency/i18n/es.po @@ -0,0 +1,134 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_change_currency +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-07-22 20:43+0000\n" +"Last-Translator: Josep M \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 3.7.1\n" + +#. module: account_invoice_change_currency +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "" +"" +msgstr "" +"" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__is_original_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__is_original_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__is_original_currency +msgid "" +"Check if current currency is the original currency. This is used to hide " +"custom rate field in the form view." +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_res_currency +msgid "Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__custom_rate +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__custom_rate +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__custom_rate +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "Custom Rate" +msgstr "Cambio Personalizado" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__is_original_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__is_original_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__is_original_currency +msgid "Is Original Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__original_currency_id +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__original_currency_id +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__original_currency_id +msgid "Original Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move_line__original_price_unit +msgid "Original Price Unit" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__custom_rate +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__custom_rate +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__custom_rate +msgid "" +"Set new currency rate to apply on the invoice.\n" +"This rate will be taken in order to convert amounts between the currency on " +"the invoice and last currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move_line__original_price_unit +msgid "" +"Store price unit from every line when the invoice is created or the " +"conversion is called for the first time to use it to convert the amount in " +"the new currency." +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__original_currency_id +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__original_currency_id +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__original_currency_id +msgid "" +"Store the original currency when the invoice is created or the conversion is " +"called for the first time. This is used to calculate conversion from this " +"currency." +msgstr "" + +#. module: account_invoice_change_currency +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "Update Currency" +msgstr "" + +#~ msgid "Currency Updated" +#~ msgstr "Moneda Actualizada" + +#~ msgid "Forced Rate" +#~ msgstr "Cambio Forzado" + +#~ msgid "Invoice" +#~ msgstr "Factura" + +#~ msgid "Opened" +#~ msgstr "Abiertas" + +#~ msgid "" +#~ "Set new currency rate to apply on the invoice\n" +#~ ".This rate will be taken in order to convert amounts between the currency " +#~ "on the invoice and last currency" +#~ msgstr "" +#~ "Establece el cambio de la nueva moneda para aplicar en la factura\n" +#~ ".Este cambio se usará para convertir las cantidades entre la moneda de la " +#~ "factura y la última moneda" + +#~ msgid "Toggle custom force rate" +#~ msgstr "Activar/Desactivar forzar cambio personalizado" diff --git a/account_invoice_change_currency/i18n/es_MX.po b/account_invoice_change_currency/i18n/es_MX.po new file mode 100644 index 00000000000..99f0fd51ee8 --- /dev/null +++ b/account_invoice_change_currency/i18n/es_MX.po @@ -0,0 +1,106 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_change_currency +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: es_MX\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" + +#. module: account_invoice_change_currency +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "" +"" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__is_original_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__is_original_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__is_original_currency +msgid "" +"Check if current currency is the original currency. This is used to hide " +"custom rate field in the form view." +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_res_currency +msgid "Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__custom_rate +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__custom_rate +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__custom_rate +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "Custom Rate" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__is_original_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__is_original_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__is_original_currency +msgid "Is Original Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__original_currency_id +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__original_currency_id +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__original_currency_id +msgid "Original Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move_line__original_price_unit +msgid "Original Price Unit" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__custom_rate +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__custom_rate +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__custom_rate +msgid "" +"Set new currency rate to apply on the invoice.\n" +"This rate will be taken in order to convert amounts between the currency on " +"the invoice and last currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move_line__original_price_unit +msgid "" +"Store price unit from every line when the invoice is created or the " +"conversion is called for the first time to use it to convert the amount in " +"the new currency." +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__original_currency_id +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__original_currency_id +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__original_currency_id +msgid "" +"Store the original currency when the invoice is created or the conversion is " +"called for the first time. This is used to calculate conversion from this " +"currency." +msgstr "" + +#. module: account_invoice_change_currency +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "Update Currency" +msgstr "" diff --git a/account_invoice_change_currency/i18n/hr.po b/account_invoice_change_currency/i18n/hr.po new file mode 100644 index 00000000000..16c19c2259a --- /dev/null +++ b/account_invoice_change_currency/i18n/hr.po @@ -0,0 +1,123 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_change_currency +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-03-05 16:13+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.10\n" + +#. module: account_invoice_change_currency +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "" +"" +msgstr "" +"" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__is_original_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__is_original_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__is_original_currency +msgid "" +"Check if current currency is the original currency. This is used to hide " +"custom rate field in the form view." +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_res_currency +msgid "Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__custom_rate +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__custom_rate +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__custom_rate +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "Custom Rate" +msgstr "Prilagođeni tečaj" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__is_original_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__is_original_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__is_original_currency +msgid "Is Original Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model,name:account_invoice_change_currency.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_bank_statement_line__original_currency_id +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move__original_currency_id +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_payment__original_currency_id +msgid "Original Currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,field_description:account_invoice_change_currency.field_account_move_line__original_price_unit +msgid "Original Price Unit" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__custom_rate +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__custom_rate +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__custom_rate +msgid "" +"Set new currency rate to apply on the invoice.\n" +"This rate will be taken in order to convert amounts between the currency on " +"the invoice and last currency" +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move_line__original_price_unit +msgid "" +"Store price unit from every line when the invoice is created or the " +"conversion is called for the first time to use it to convert the amount in " +"the new currency." +msgstr "" + +#. module: account_invoice_change_currency +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_bank_statement_line__original_currency_id +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_move__original_currency_id +#: model:ir.model.fields,help:account_invoice_change_currency.field_account_payment__original_currency_id +msgid "" +"Store the original currency when the invoice is created or the conversion is " +"called for the first time. This is used to calculate conversion from this " +"currency." +msgstr "" + +#. module: account_invoice_change_currency +#: model_terms:ir.ui.view,arch_db:account_invoice_change_currency.view_move_form +msgid "Update Currency" +msgstr "" + +#~ msgid "Currency Updated" +#~ msgstr "Valuta ažurirana" + +#~ msgid "Forced Rate" +#~ msgstr "Prisili tečaj" + +#~ msgid "Invoice" +#~ msgstr "Račun" + +#~ msgid "Opened" +#~ msgstr "Otvoren" diff --git a/account_invoice_change_currency/models/__init__.py b/account_invoice_change_currency/models/__init__.py new file mode 100644 index 00000000000..73cae86d34d --- /dev/null +++ b/account_invoice_change_currency/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_move +from . import account_move_line +from . import res_currency diff --git a/account_invoice_change_currency/models/account_move.py b/account_invoice_change_currency/models/account_move.py new file mode 100644 index 00000000000..1fdbd4a4214 --- /dev/null +++ b/account_invoice_change_currency/models/account_move.py @@ -0,0 +1,95 @@ +# Copyright 2017-2018 Vauxoo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + custom_rate = fields.Float( + digits=(12, 6), + default=1, + store=True, + readonly=False, + compute="_compute_currency_change_rate", + help="Set new currency rate to apply on the invoice.\n" + "This rate will be taken in order to convert amounts between the " + "currency on the invoice and last currency", + ) + original_currency_id = fields.Many2one( + "res.currency", + help="Store the original currency when the invoice is created or the " + "conversion is called for the first time. " + "This is used to calculate conversion from this currency.", + ) + is_original_currency = fields.Boolean( + compute="_compute_is_original_currency", + help="Check if current currency is the original currency. " + "This is used to hide custom rate field in the form view.", + ) + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if "currency_id" in vals and not vals.get("original_currency_id", False): + vals["original_currency_id"] = vals["currency_id"] + return super().create(vals_list) + + def action_account_change_currency(self): + """ + This method convert the original price unit from the original + currency when the invoice was created to the current currency + using the custom rate and recompute all taxes. + """ + today = fields.Date.context_today(self) + invoices = self.filtered(lambda x: x.state == "draft").with_context( + check_move_validity=False, + ) + for invoice in invoices: + if not invoice.original_currency_id: + invoice.write({"original_currency_id": invoice.currency_id}) + invoice.invoice_line_ids._set_original_price_unit() + invoice_date = invoice.invoice_date or today + to_currency = invoice.currency_id + context = {"custom_rate": invoice.custom_rate, "to_currency": to_currency} + original_currency = invoice.original_currency_id.with_context(**context) + for line in invoice.invoice_line_ids: + line.price_unit = original_currency._convert( + line.original_price_unit, + to_currency, + invoice.company_id, + invoice_date, + ) + + @api.depends("company_id", "currency_id", "invoice_date") + def _compute_currency_change_rate(self): + """ + Compute the custom rate from the original currency when the invoice + was created to the current currency. The custom rate field is + editable, but it will not change if custom rate is zero or the + current currency and the original currency are the same + """ + for invoice in self: + if not invoice.currency_id or not invoice.company_id: + invoice.custom_rate = 1.0 + continue + date = invoice.invoice_date or fields.Date.context_today(invoice) + from_currency = invoice.original_currency_id or invoice.currency_id + invoice.custom_rate = from_currency._get_conversion_rate( + from_currency, + invoice.currency_id, + invoice.company_id, + date, + ) + + @api.depends("currency_id", "original_currency_id") + def _compute_is_original_currency(self): + """ + Compute if the current currency and the original currency + are the same. The is_original_currency field is used in the + view to hide the custom_rate field. + """ + for invoice in self: + invoice.is_original_currency = ( + invoice.currency_id == invoice.original_currency_id + ) diff --git a/account_invoice_change_currency/models/account_move_line.py b/account_invoice_change_currency/models/account_move_line.py new file mode 100644 index 00000000000..9e763fdd94f --- /dev/null +++ b/account_invoice_change_currency/models/account_move_line.py @@ -0,0 +1,25 @@ +# Copyright 2017-2018 Vauxoo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + original_price_unit = fields.Monetary( + help="Store price unit from every line when the " + "invoice is created or the conversion is called " + "for the first time to use it to convert the " + "amount in the new currency.", + ) + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if "price_unit" in vals: + vals["original_price_unit"] = vals["price_unit"] + return super().create(vals_list) + + def _set_original_price_unit(self): + for line in self: + line.write({"original_price_unit": line.price_unit}) diff --git a/account_invoice_change_currency/models/res_currency.py b/account_invoice_change_currency/models/res_currency.py new file mode 100644 index 00000000000..b299ced53ac --- /dev/null +++ b/account_invoice_change_currency/models/res_currency.py @@ -0,0 +1,21 @@ +# Copyright 2017-2018 Vauxoo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import models + + +class ResCurrency(models.Model): + _inherit = "res.currency" + + def _get_rates(self, company, date): + """ + Inheritance to use the provided custom rate by user + instead of the rate from odoo. + """ + custom_rate = self.env.context.get("custom_rate") + to_currency = self.env.context.get("to_currency") + if custom_rate and to_currency: + return { + currency.id: custom_rate if currency == to_currency else 1.0 + for currency in self + } + return super()._get_rates(company, date) diff --git a/account_invoice_change_currency/readme/CONFIGURE.rst b/account_invoice_change_currency/readme/CONFIGURE.rst new file mode 100644 index 00000000000..93bf72dd2ad --- /dev/null +++ b/account_invoice_change_currency/readme/CONFIGURE.rst @@ -0,0 +1,2 @@ +The exchange rate will be configured in +Accounting > Configuration > Multi-Currencies > Currencies diff --git a/account_invoice_change_currency/readme/CONTRIBUTORS.rst b/account_invoice_change_currency/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..050685e4b1a --- /dev/null +++ b/account_invoice_change_currency/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* Duc, Dao Dong (https://komit-consulting.com) +* Hugo Adan +* Saran Lim. +* Rolando Duarte +* Luis J. Salvatierra (https://factorlibre.com) diff --git a/account_invoice_change_currency/readme/DESCRIPTION.rst b/account_invoice_change_currency/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..7ac0542c492 --- /dev/null +++ b/account_invoice_change_currency/readme/DESCRIPTION.rst @@ -0,0 +1,15 @@ +================================== +Update currency of Account Invoice +================================== + +This module allows users to update the currency of Invoices (in draft state) by +a button Update Currency at the invoice form. +After update to new currency, all the unit prices of invoice lines will be +recomputed to new currency, thus the Total amounts (tax and without tax) of +Invoice will be in the new currency also + +Also this module allows user to set a custom rate that will be take to recompute +all lines. By default the custom rate proposed is the rate between invoice +currency and base currency (company currency), after the first coversion the +custom rate will be proposed by default between last currency and invoice +currency. diff --git a/account_invoice_change_currency/readme/USAGE.rst b/account_invoice_change_currency/readme/USAGE.rst new file mode 100644 index 00000000000..cb07fac5c96 --- /dev/null +++ b/account_invoice_change_currency/readme/USAGE.rst @@ -0,0 +1,4 @@ +To use this module, the user must be in group Accounting & Finance / Adviser +to be able to update currency of Invoices + +Note : you have to save new invoice before change currency diff --git a/account_invoice_change_currency/static/description/icon.png b/account_invoice_change_currency/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/account_invoice_change_currency/static/description/icon.png differ diff --git a/account_invoice_change_currency/static/description/index.html b/account_invoice_change_currency/static/description/index.html new file mode 100644 index 00000000000..375c74d1b7c --- /dev/null +++ b/account_invoice_change_currency/static/description/index.html @@ -0,0 +1,453 @@ + + + + + + +README.rst + + + +
+ + +
+

Account Invoice - Change Currency

+ +

Beta License: AGPL-3 OCA/account-invoicing Translate me on Weblate Try me on Runbot

+
+
+

Update currency of Account Invoice

+

This module allows users to update the currency of Invoices (in draft state) by +a button Update Currency at the invoice form. +After update to new currency, all the unit prices of invoice lines will be +recomputed to new currency, thus the Total amounts (tax and without tax) of +Invoice will be in the new currency also

+

Also this module allows user to set a custom rate that will be take to recompute +all lines. By default the custom rate proposed is the rate between invoice +currency and base currency (company currency), after the first coversion the +custom rate will be proposed by default between last currency and invoice +currency.

+

Table of contents

+ +
+

Configuration

+

The exchange rate will be configured in +Accounting > Configuration > Multi-Currencies > Currencies

+
+
+

Usage

+

To use this module, the user must be in group Accounting & Finance / Adviser +to be able to update currency of Invoices

+

Note : you have to save new invoice before change currency

+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Vauxoo
  • +
  • Komit Consulting
  • +
+
+ +
+

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:

+

luisg123v rolandojduartem

+

This module is part of the OCA/account-invoicing project on GitHub.

+

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

+
+
+
+
+ + diff --git a/account_invoice_change_currency/tests/__init__.py b/account_invoice_change_currency/tests/__init__.py new file mode 100644 index 00000000000..ac7057b6c2d --- /dev/null +++ b/account_invoice_change_currency/tests/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2017 Komit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import test_account_invoice_change_currency diff --git a/account_invoice_change_currency/tests/test_account_invoice_change_currency.py b/account_invoice_change_currency/tests/test_account_invoice_change_currency.py new file mode 100644 index 00000000000..940dddd9202 --- /dev/null +++ b/account_invoice_change_currency/tests/test_account_invoice_change_currency.py @@ -0,0 +1,220 @@ +# Copyright 2018 Komit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import fields +from odoo.tests import tagged +from odoo.tools import float_compare + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon + + +@tagged("post_install", "-at_install") +class TestAccountInvoiceChangeCurrency(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + decimal_precision_name = ( + cls.env["account.move.line"]._fields["price_unit"]._digits + ) + decimal_precision = cls.env["decimal.precision"].search( + [("name", "=", decimal_precision_name)] + ) + cls.precision = decimal_precision.digits + + def test_change_invoice_currency(self): + inv = self.init_invoice( + "out_invoice", + products=self.product_a + self.product_b, + invoice_date=fields.Date.today(), + ) + before_curr = inv.currency_id + before_amount = inv.amount_total + after_curr = self.env.ref("base.USD") + inv.write({"currency_id": after_curr.id}) + inv.action_account_change_currency() + expected_value = before_curr._convert( + before_amount, after_curr, inv.company_id, fields.Date.today() + ) + self.assertEqual( + float_compare(inv.amount_total, expected_value, 0), + 0, + "Total amount of invoice does not match to the expected value", + ) + + def test_change_validated_invoice_currency(self): + inv = self.init_invoice( + "out_invoice", + products=self.product_a + self.product_b, + invoice_date=fields.Date.today(), + ) + before_amount = inv.amount_total + inv.action_post() + # Make sure that we can not change the currency after validated: + inv.write({"currency_id": self.env.ref("base.USD").id}) + inv.action_account_change_currency() + self.assertEqual( + inv.amount_total, + before_amount, + "Total amount of invoice does not match to the expected value", + ) + + def test_create_invoice_update_currency(self): + inv = self.init_invoice( + "out_invoice", + products=self.product_a + self.product_b, + invoice_date=fields.Date.today(), + ) + before_amount = inv.amount_total + inv.action_account_change_currency() + self.assertEqual( + inv.amount_total, + before_amount, + "Amount must remain the same, because no currency changes", + ) + + def test_custom_rate_update_currency(self): + inv = self.init_invoice( + "out_invoice", + products=self.product_a + self.product_b, + invoice_date=fields.Date.today(), + ) + before_amount = inv.amount_total + self.assertEqual(inv.original_currency_id, self.env.ref("base.USD")) + after_curr = self.env.ref("base.EUR") + custom_rate = 1.13208 + inv.write({"currency_id": after_curr.id, "custom_rate": custom_rate}) + inv.write({"custom_rate": custom_rate}) + inv.action_account_change_currency() + expected_value = before_amount * custom_rate + self.assertEqual( + float_compare(inv.amount_total, expected_value, self.precision), + 0, + "Total amount of invoice does not match to the expected value", + ) + + def test_custom_rate_zero_update_currency(self): + inv = self.init_invoice( + "out_invoice", + products=self.product_a + self.product_b, + invoice_date=fields.Date.today(), + ) + before_amount = inv.amount_total + before_curr = inv.currency_id + custom_rate = 0.0 + usd = self.env.ref("base.USD") + eur = self.env.ref("base.EUR") + inv.write({"currency_id": usd.id, "custom_rate": custom_rate}) + inv.action_account_change_currency() + expected_value = before_curr._convert( + before_amount, usd, inv.company_id, fields.Date.today() + ) + self.assertEqual( + float_compare(inv.amount_total, expected_value, self.precision), + 0, + "Total amount of invoice does not match to the expected value", + ) + # Change currency and set custom rate 0 + inv.write({"currency_id": eur.id, "custom_rate": custom_rate}) + inv.action_account_change_currency() + self.assertEqual( + inv.amount_total, + before_amount, + "Total amount of invoice does not match to the expected value", + ) + # keep old_rate but now we update the currency.rate + # (Original currency rate can not be changed anymore) + before_amount = inv.amount_total + old_rate = custom_rate + new_rate = 1.6299 + usd_updated_rate = self.env["res.currency.rate"].create( + { + "name": fields.Date.today(), + "rate": new_rate, + "currency_id": usd.id, + "company_id": inv.company_id.id, + } + ) + rate = usd_updated_rate.rate + inv.write({"custom_rate": rate}) + inv.action_account_change_currency() + expected_value = before_amount * rate + self.assertEqual( + float_compare(inv.amount_total, expected_value, 1), + 0, + "Total amount of invoice does not match to the expected value", + ) + # change custom rate then we trigger the conversion 2 times + # The currency.rate modification above will be ignored and keep the + # custom rate + old_rate = inv.custom_rate + inv.write({"currency_id": usd.id, "custom_rate": rate}) + inv.action_account_change_currency() + before_amount = inv.amount_total + rate = usd_updated_rate.rate + inv.action_account_change_currency() + expected_value = before_amount * rate / old_rate + self.assertEqual( + float_compare(inv.amount_total, expected_value, self.precision), + 0, + "Total amount of invoice does not match to the expected value", + ) + before_amount = inv.amount_total + rate = old_rate + 1 + inv.write({"custom_rate": rate}) + inv.action_account_change_currency() + expected_value = before_amount + self.assertEqual( + float_compare(inv.amount_total, expected_value, 1), + 0, + "Total amount of invoice does not match to the expected value", + ) + inv.action_account_change_currency() + self.assertEqual( + float_compare(inv.amount_total, expected_value, 1), + 0, + "Total amount of invoice does not match to the expected value", + ) + + def test_not_currency_change(self): + inv = self.init_invoice( + "out_invoice", + products=self.product_a + self.product_b, + invoice_date=fields.Date.today(), + ) + before_amount = inv.amount_total + inv.action_account_change_currency() + self.assertEqual( + inv.amount_total, + before_amount, + "Amount must remain the same, because None change was made", + ) + + def test_old_invoices(self): + # This simulate an old invoice (no stored original values) + inv = self.init_invoice( + "out_invoice", + products=self.product_a + self.product_b, + invoice_date=fields.Date.today(), + ) + inv.write({"original_currency_id": False}) + inv.invoice_line_ids.write({"original_price_unit": False}) + self.assertFalse( + inv.original_currency_id, + "There is an original currency in the invoice", + ) + self.assertEqual( + inv.invoice_line_ids.mapped("original_price_unit"), + [0.0, 0.0], + "There are original price units in the invoice", + ) + # Now, trigger the action to store the original values to change currencies + inv.action_account_change_currency() + self.assertEqual( + inv.original_currency_id, + inv.currency_id, + "Original currency of invoice is not match to the expected value", + ) + self.assertEqual( + inv.invoice_line_ids.mapped("original_price_unit"), + inv.invoice_line_ids.mapped("price_unit"), + "Original price units of invoice do not match to the expected value", + ) diff --git a/account_invoice_change_currency/views/account_move_views.xml b/account_invoice_change_currency/views/account_move_views.xml new file mode 100644 index 00000000000..d977f601709 --- /dev/null +++ b/account_invoice_change_currency/views/account_move_views.xml @@ -0,0 +1,49 @@ + + + + + account.move.form.inherit + account.move + + + + + + + diff --git a/setup/account_invoice_change_currency/odoo/addons/account_invoice_change_currency b/setup/account_invoice_change_currency/odoo/addons/account_invoice_change_currency new file mode 120000 index 00000000000..b34414a4b15 --- /dev/null +++ b/setup/account_invoice_change_currency/odoo/addons/account_invoice_change_currency @@ -0,0 +1 @@ +../../../../account_invoice_change_currency \ No newline at end of file diff --git a/setup/account_invoice_change_currency/setup.py b/setup/account_invoice_change_currency/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/account_invoice_change_currency/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)