diff --git a/account_invoice_show_currency_rate/README.rst b/account_invoice_show_currency_rate/README.rst new file mode 100644 index 00000000000..cd072a6c1a9 --- /dev/null +++ b/account_invoice_show_currency_rate/README.rst @@ -0,0 +1,111 @@ +================================== +Account Invoice Show Currency Rate +================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/13.0/account_invoice_show_currency_rate + :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-13-0/account-invoicing-13-0-account_invoice_show_currency_rate + :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/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module shows the currency rate applied in invoices, so you can visually verify what is going to be applied for the exchange, or which one was applied once converted to company currency. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Enable the option for multiple currencies in your instance: + +#. Go to Invoicing > Configuration > Settings > Currencies > Multi-Currencies +#. Go to any draft invoice +#. Change the invoice currency +#. The proper currency rate, based on the invoice date and the selected currency, will be shown. +#. Add any invoice line. +#. Odoo has already generated the journal item lines with the rate applied, so the currency rate shown is get from the division between the amount in currency by the amount in company currency. + +Some rates must be defined (and be distinct to 1.0) for currencies different from the company default. + +#. Go to Invoicing > Configuration > Currencies and go to EUR +#. Go to Rates smart-button +#. Update 01/01/2010 record and change rate to 1.5 + +Usage +===== + +To use this module, you need to: + +#. Go to Invoicing > Customer > Invoice +#. Create Invoice and set Currency distinct to company currency (EUR for example) +#. Rate account show according to currency defined. + +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 +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Pedro M. Baeza + * Víctor Martínez + +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-victoralmau| image:: https://github.com/victoralmau.png?size=40px + :target: https://github.com/victoralmau + :alt: victoralmau + +Current `maintainer `__: + +|maintainer-victoralmau| + +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_show_currency_rate/__init__.py b/account_invoice_show_currency_rate/__init__.py new file mode 100644 index 00000000000..69f7babdfb1 --- /dev/null +++ b/account_invoice_show_currency_rate/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/account_invoice_show_currency_rate/__manifest__.py b/account_invoice_show_currency_rate/__manifest__.py new file mode 100644 index 00000000000..0ab6b411af7 --- /dev/null +++ b/account_invoice_show_currency_rate/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2021 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Account Invoice Show Currency Rate", + "summary": "Show currency rate in invoices.", + "version": "16.0.1.0.0", + "category": "Accounting & Finance", + "website": "https://github.com/OCA/account-invoicing", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["account"], + "maintainers": ["victoralmau"], + "data": ["views/account_move_view.xml"], +} diff --git a/account_invoice_show_currency_rate/i18n/account_invoice_show_currency_rate.pot b/account_invoice_show_currency_rate/i18n/account_invoice_show_currency_rate.pot new file mode 100644 index 00000000000..3699b5ef83c --- /dev/null +++ b/account_invoice_show_currency_rate/i18n/account_invoice_show_currency_rate.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_show_currency_rate +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.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: account_invoice_show_currency_rate +#: model:ir.model,name:account_invoice_show_currency_rate.model_account_move +msgid "Journal Entries" +msgstr "" + +#. module: account_invoice_show_currency_rate +#: model:ir.model.fields,field_description:account_invoice_show_currency_rate.field_account_move__currency_rate_amount +msgid "Rate amount" +msgstr "" + +#. module: account_invoice_show_currency_rate +#: model:ir.model.fields,field_description:account_invoice_show_currency_rate.field_account_move__show_currency_rate_amount +msgid "Show Currency Rate Amount" +msgstr "" diff --git a/account_invoice_show_currency_rate/i18n/es.po b/account_invoice_show_currency_rate/i18n/es.po new file mode 100644 index 00000000000..8e0f5ec4383 --- /dev/null +++ b/account_invoice_show_currency_rate/i18n/es.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_show_currency_rate +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-07-09 11:07+0000\n" +"PO-Revision-Date: 2021-07-09 13:09+0200\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 2.3\n" + +#. module: account_invoice_show_currency_rate +#: model:ir.model,name:account_invoice_show_currency_rate.model_account_move +msgid "Journal Entries" +msgstr "Asientos contables" + +#. module: account_invoice_show_currency_rate +#: model:ir.model.fields,field_description:account_invoice_show_currency_rate.field_account_move__currency_rate_amount +msgid "Rate amount" +msgstr "Valor de cambio de moneda" diff --git a/account_invoice_show_currency_rate/models/__init__.py b/account_invoice_show_currency_rate/models/__init__.py new file mode 100644 index 00000000000..9c0a4213854 --- /dev/null +++ b/account_invoice_show_currency_rate/models/__init__.py @@ -0,0 +1 @@ +from . import account_move diff --git a/account_invoice_show_currency_rate/models/account_move.py b/account_invoice_show_currency_rate/models/account_move.py new file mode 100644 index 00000000000..62e2efc770b --- /dev/null +++ b/account_invoice_show_currency_rate/models/account_move.py @@ -0,0 +1,51 @@ +# Copyright 2021 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + currency_rate_amount = fields.Float( + string="Rate amount", + compute="_compute_currency_rate_amount", + digits=0, + ) + show_currency_rate_amount = fields.Boolean( + compute="_compute_show_currency_rate_amount", readonly=True + ) + + @api.depends( + "state", + "date", + "line_ids.amount_currency", + "company_id", + "currency_id", + "show_currency_rate_amount", + ) + def _compute_currency_rate_amount(self): + """It's necessary to define value according to some cases: + - Case A: Currency is equal to company currency (Value = 1) + - Case B: Move exist previously (posted) and get real rate according to lines + - Case C: Get expected rate (according to date) to show some value in creation. + """ + self.currency_rate_amount = 1 + for item in self.filtered("show_currency_rate_amount"): + lines = item.line_ids.filtered(lambda x: x.amount_currency > 0) + if item.state == "posted" and lines: + amount_currency_positive = sum(lines.mapped("amount_currency")) + total_debit = sum(item.line_ids.mapped("debit")) + item.currency_rate_amount = item.currency_id.round( + amount_currency_positive / total_debit + ) + else: + rates = item.currency_id._get_rates(item.company_id, item.date) + item.currency_rate_amount = rates.get(item.currency_id.id) + + @api.depends("currency_id", "currency_id.rate_ids", "company_id") + def _compute_show_currency_rate_amount(self): + for item in self: + item.show_currency_rate_amount = ( + item.currency_id and item.currency_id != item.company_id.currency_id + ) diff --git a/account_invoice_show_currency_rate/readme/CONFIGURE.rst b/account_invoice_show_currency_rate/readme/CONFIGURE.rst new file mode 100644 index 00000000000..db058a17232 --- /dev/null +++ b/account_invoice_show_currency_rate/readme/CONFIGURE.rst @@ -0,0 +1,14 @@ +Enable the option for multiple currencies in your instance: + +#. Go to Invoicing > Configuration > Settings > Currencies > Multi-Currencies +#. Go to any draft invoice +#. Change the invoice currency +#. The proper currency rate, based on the invoice date and the selected currency, will be shown. +#. Add any invoice line. +#. Odoo has already generated the journal item lines with the rate applied, so the currency rate shown is get from the division between the amount in currency by the amount in company currency. + +Some rates must be defined (and be distinct to 1.0) for currencies different from the company default. + +#. Go to Invoicing > Configuration > Currencies and go to EUR +#. Go to Rates smart-button +#. Update 01/01/2010 record and change rate to 1.5 diff --git a/account_invoice_show_currency_rate/readme/CONTRIBUTORS.rst b/account_invoice_show_currency_rate/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..18d463ed537 --- /dev/null +++ b/account_invoice_show_currency_rate/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Pedro M. Baeza + * Víctor Martínez diff --git a/account_invoice_show_currency_rate/readme/DESCRIPTION.rst b/account_invoice_show_currency_rate/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..9af418f03f0 --- /dev/null +++ b/account_invoice_show_currency_rate/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module shows the currency rate applied in invoices, so you can visually verify what is going to be applied for the exchange, or which one was applied once converted to company currency. diff --git a/account_invoice_show_currency_rate/readme/USAGE.rst b/account_invoice_show_currency_rate/readme/USAGE.rst new file mode 100644 index 00000000000..db83bb5e5ad --- /dev/null +++ b/account_invoice_show_currency_rate/readme/USAGE.rst @@ -0,0 +1,5 @@ +To use this module, you need to: + +#. Go to Invoicing > Customer > Invoice +#. Create Invoice and set Currency distinct to company currency (EUR for example) +#. Rate account show according to currency defined. diff --git a/account_invoice_show_currency_rate/static/description/icon.png b/account_invoice_show_currency_rate/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/account_invoice_show_currency_rate/static/description/icon.png differ diff --git a/account_invoice_show_currency_rate/static/description/index.html b/account_invoice_show_currency_rate/static/description/index.html new file mode 100644 index 00000000000..7379bd4e891 --- /dev/null +++ b/account_invoice_show_currency_rate/static/description/index.html @@ -0,0 +1,454 @@ + + + + + + +Account Invoice Show Currency Rate + + + +
+

Account Invoice Show Currency Rate

+ + +

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

+

This module shows the currency rate applied in invoices, so you can visually verify what is going to be applied for the exchange, or which one was applied once converted to company currency.

+

Table of contents

+ +
+

Configuration

+

Enable the option for multiple currencies in your instance:

+
    +
  1. Go to Invoicing > Configuration > Settings > Currencies > Multi-Currencies
  2. +
  3. Go to any draft invoice
  4. +
  5. Change the invoice currency
  6. +
  7. The proper currency rate, based on the invoice date and the selected currency, will be shown.
  8. +
  9. Add any invoice line.
  10. +
  11. Odoo has already generated the journal item lines with the rate applied, so the currency rate shown is get from the division between the amount in currency by the amount in company currency.
  12. +
+

Some rates must be defined (and be distinct to 1.0) for currencies different from the company default.

+
    +
  1. Go to Invoicing > Configuration > Currencies and go to EUR
  2. +
  3. Go to Rates smart-button
  4. +
  5. Update 01/01/2010 record and change rate to 1.5
  6. +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Invoicing > Customer > Invoice
  2. +
  3. Create Invoice and set Currency distinct to company currency (EUR for example)
  4. +
  5. Rate account show according to currency defined.
  6. +
+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Pedro M. Baeza
    • +
    • Víctor Martínez
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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

+

Current maintainer:

+

victoralmau

+

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_show_currency_rate/tests/__init__.py b/account_invoice_show_currency_rate/tests/__init__.py new file mode 100644 index 00000000000..d41173dbebe --- /dev/null +++ b/account_invoice_show_currency_rate/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from . import test_account_move diff --git a/account_invoice_show_currency_rate/tests/test_account_move.py b/account_invoice_show_currency_rate/tests/test_account_move.py new file mode 100644 index 00000000000..ce99766ca9a --- /dev/null +++ b/account_invoice_show_currency_rate/tests/test_account_move.py @@ -0,0 +1,90 @@ +# Copyright 2021 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from odoo import fields +from odoo.tests import Form, common + + +class TestAccountMove(common.SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + usd = cls.env.ref("base.USD") + eur = cls.env.ref("base.EUR") + cls.currency = cls.env.ref("base.main_company").currency_id + cls.currency_extra = eur if cls.currency == usd else usd + cls.account_tax = cls.env["account.tax"].create( + {"name": "0%", "amount_type": "fixed", "type_tax_use": "sale", "amount": 0} + ) + cls.partner = cls.env["res.partner"].create({"name": "Partner test"}) + cls.product = cls.env["product.product"].create( + { + "name": "Product Test", + "list_price": 10, + "taxes_id": [(6, 0, [cls.account_tax.id])], + } + ) + + cls.account = cls.env["account.account"].create( + { + "name": "Test Account", + "code": "TEST", + "account_type": "asset_receivable", + "reconcile": True, + } + ) + cls.other_account = cls.env["account.account"].create( + { + "name": "Test Account", + "code": "ACC", + "account_type": "income_other", + "reconcile": True, + } + ) + cls.journal = cls.env["account.journal"].create( + {"name": "Test sale journal", "type": "sale", "code": "TEST-SALE"} + ) + cls.pricelist_currency = cls.env["product.pricelist"].create( + {"name": "Pricelist Currency", "currency_id": cls.currency.id} + ) + cls.pricelist_currency_extra = cls.env["product.pricelist"].create( + {"name": "Pricelist Currency Extra", "currency_id": cls.currency_extra.id} + ) + # Create custom rates to currency + currency_extra + cls._create_currency_rate(cls, cls.currency, "2000-01-01", 1.0) + cls._create_currency_rate(cls, cls.currency_extra, "2000-01-01", 2.0) + + def _create_currency_rate(self, currency_id, name, rate): + self.env["res.currency.rate"].create( + {"currency_id": currency_id.id, "name": name, "rate": rate} + ) + + def _create_invoice(self, currency_id): + move_form = Form( + self.env["account.move"].with_context(default_move_type="out_invoice") + ) + move_form.partner_id = self.partner + move_form.invoice_date = fields.Date.from_string("2000-01-01") + move_form.currency_id = currency_id + with move_form.invoice_line_ids.new() as line_form: + line_form.product_id = self.product + invoice = move_form.save() + invoice.action_post() + return invoice + + def test_01_invoice_currency(self): + self.partner.property_product_pricelist = self.pricelist_currency + invoice = self._create_invoice(self.currency) + self.assertAlmostEqual(invoice.currency_rate_amount, 1.0, 2) + + def test_02_invoice_currency_extra(self): + self.partner.property_product_pricelist = self.pricelist_currency_extra + invoice = self._create_invoice(self.currency_extra) + self.assertAlmostEqual(invoice.currency_rate_amount, 2.0, 2) + rate_custom = self.currency_extra.rate_ids.filtered( + lambda x: x.name == fields.Date.from_string("2000-01-01") + ) + rate_custom.rate = 3.0 + self.assertAlmostEqual(invoice.currency_rate_amount, 2.0, 2) + invoice.button_draft() + self.assertAlmostEqual(invoice.currency_rate_amount, 3.0, 2) diff --git a/account_invoice_show_currency_rate/views/account_move_view.xml b/account_invoice_show_currency_rate/views/account_move_view.xml new file mode 100644 index 00000000000..1cbeac424f5 --- /dev/null +++ b/account_invoice_show_currency_rate/views/account_move_view.xml @@ -0,0 +1,22 @@ + + + + + account.move.form + account.move + + + + + + + + + diff --git a/setup/account_invoice_show_currency_rate/odoo/addons/account_invoice_show_currency_rate b/setup/account_invoice_show_currency_rate/odoo/addons/account_invoice_show_currency_rate new file mode 120000 index 00000000000..98ecca15838 --- /dev/null +++ b/setup/account_invoice_show_currency_rate/odoo/addons/account_invoice_show_currency_rate @@ -0,0 +1 @@ +../../../../account_invoice_show_currency_rate \ No newline at end of file diff --git a/setup/account_invoice_show_currency_rate/setup.py b/setup/account_invoice_show_currency_rate/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/account_invoice_show_currency_rate/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)