diff --git a/account_invoice_fixed_discount/README.rst b/account_invoice_fixed_discount/README.rst new file mode 100644 index 00000000000..366f84dec73 --- /dev/null +++ b/account_invoice_fixed_discount/README.rst @@ -0,0 +1,101 @@ +====================== +Account Fixed Discount +====================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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_fixed_discount + :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_fixed_discount + :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| + +This module extends the functionality of Invoicing to allow you to apply fixed +amount discounts at invoice line level. + +The module also extends the invoice report to show fixed discount. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +**Warning**: This module is incompatible with +``account_invoice_triple_discount`` which also belongs to `OCA/account-invoicing +`__. + +Usage +===== + +To use this module, you need to: + +#. Go to *Settings* and *Activate the developer mode* +#. Go to *Invoicing*. +#. Create a Invoice and specify a fixed discount in a line. + +Known issues / Roadmap +====================== + +* At the moment, the simultaneous use of percent and fixed discounts (at + line level) is not supported. + +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 +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* Lois Rilo +* Jordi Ballester +* Rattapong Chokmasermkul +* Kitti U. + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/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_fixed_discount/__init__.py b/account_invoice_fixed_discount/__init__.py new file mode 100644 index 00000000000..ea506a99254 --- /dev/null +++ b/account_invoice_fixed_discount/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from . import models diff --git a/account_invoice_fixed_discount/__manifest__.py b/account_invoice_fixed_discount/__manifest__.py new file mode 100644 index 00000000000..eb784cdb397 --- /dev/null +++ b/account_invoice_fixed_discount/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2017 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +{ + "name": "Account Fixed Discount", + "summary": "Allows to apply fixed amount discounts in invoices.", + "version": "16.0.1.0.0", + "category": "Accounting & Finance", + "website": "https://github.com/OCA/account-invoicing", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["account"], + "data": [ + "security/res_groups.xml", + "views/account_move_view.xml", + "reports/report_account_invoice.xml", + ], +} diff --git a/account_invoice_fixed_discount/i18n/account_invoice_fixed_discount.pot b/account_invoice_fixed_discount/i18n/account_invoice_fixed_discount.pot new file mode 100644 index 00000000000..0b065ec7525 --- /dev/null +++ b/account_invoice_fixed_discount/i18n/account_invoice_fixed_discount.pot @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_fixed_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid "Disc. Fixed Amount" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,field_description:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "Discount (Fixed)" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,help:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "Fixed amount discount." +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_invoice_fixed_discount +#: code:addons/account_invoice_fixed_discount/models/account_move.py:0 +#, python-format +msgid "You can only set one type of discount per line." +msgstr "" diff --git a/account_invoice_fixed_discount/i18n/ca.po b/account_invoice_fixed_discount/i18n/ca.po new file mode 100644 index 00000000000..5f62b077968 --- /dev/null +++ b/account_invoice_fixed_discount/i18n/ca.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_fixed_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\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" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid "Disc. Fixed Amount" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,field_description:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "Discount (Fixed)" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,help:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "Fixed amount discount." +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_invoice_fixed_discount +#: code:addons/account_invoice_fixed_discount/models/account_move.py:0 +#, python-format +msgid "You can only set one type of discount per line." +msgstr "" diff --git a/account_invoice_fixed_discount/i18n/de.po b/account_invoice_fixed_discount/i18n/de.po new file mode 100644 index 00000000000..54ad6db7104 --- /dev/null +++ b/account_invoice_fixed_discount/i18n/de.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_fixed_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-07-17 12:43+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.7.1\n" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid "Disc. Fixed Amount" +msgstr "Rabatt (abs.)" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,field_description:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "Discount (Fixed)" +msgstr "Rabatt (abs.)" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,help:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "Fixed amount discount." +msgstr "Hier kann ein absoluter Rabatt hinzugefügt werden." + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_move +msgid "Journal Entries" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_invoice_fixed_discount +#: code:addons/account_invoice_fixed_discount/models/account_move.py:0 +#, python-format +msgid "You can only set one type of discount per line." +msgstr "" +"Es kann nur eine Art von Rabatt (prozentual oder absolut) pro Zeile gesetzt " +"werden." + +#~ msgid "Invoice" +#~ msgstr "Rechnung" + +#~ msgid "Invoice Line" +#~ msgstr "Rechnungsposition" diff --git a/account_invoice_fixed_discount/i18n/es.po b/account_invoice_fixed_discount/i18n/es.po new file mode 100644 index 00000000000..08e68b3c0ac --- /dev/null +++ b/account_invoice_fixed_discount/i18n/es.po @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_fixed_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-03-10 10:46+0000\n" +"Last-Translator: Ana Suárez \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.3.2\n" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid "Disc. Fixed Amount" +msgstr "Cantidad Fija Descuento" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,field_description:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "Discount (Fixed)" +msgstr "Descuento (Fijo)" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,help:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "Fixed amount discount." +msgstr "Cantidad fija de descuento." + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_move +msgid "Journal Entries" +msgstr "Asientos contables" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_move_line +msgid "Journal Item" +msgstr "Apuntes contables" + +#. module: account_invoice_fixed_discount +#: code:addons/account_invoice_fixed_discount/models/account_move.py:0 +#, python-format +msgid "You can only set one type of discount per line." +msgstr "Solo puede establecer un tipo de descuento por línea." diff --git a/account_invoice_fixed_discount/models/__init__.py b/account_invoice_fixed_discount/models/__init__.py new file mode 100644 index 00000000000..c0f3ebfa906 --- /dev/null +++ b/account_invoice_fixed_discount/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from . import account_move_line +from . import account_tax diff --git a/account_invoice_fixed_discount/models/account_move_line.py b/account_invoice_fixed_discount/models/account_move_line.py new file mode 100644 index 00000000000..0ee54909957 --- /dev/null +++ b/account_invoice_fixed_discount/models/account_move_line.py @@ -0,0 +1,85 @@ +# Copyright 2017 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from odoo import api, fields, models +from odoo.tools.float_utils import float_is_zero + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + discount_fixed = fields.Monetary( + string="Discount (Fixed)", + default=0.0, + currency_field="currency_id", + help=( + "Apply a fixed amount discount to this line. The amount is multiplied by " + "the quantity of the product." + ), + ) + + @api.depends("quantity", "discount", "price_unit", "tax_ids", "currency_id") + def _compute_totals(self): + """Adjust the computation of the price_subtotal and price_total fields to + account for the fixed discount amount. + + By using the unrounded calculated discount value, we avoid rounding errors + in the resulting calculated totals. + We only need to do this for lines with a fixed discount. + + """ + done_lines = self.env["account.move.line"] + for line in self: + if float_is_zero( + line.discount_fixed, precision_rounding=line.currency_id.rounding + ): + continue + # Pass the actual float value of the discount to the tax computation method. + discount = line._get_discount_from_fixed_discount() + line_discount_price_unit = line.price_unit * (1 - (discount / 100.0)) + if line.tax_ids: + taxes_res = line.tax_ids.compute_all( + line_discount_price_unit, + quantity=line.quantity, + currency=line.currency_id, + product=line.product_id, + partner=line.partner_id, + is_refund=line.is_refund, + ) + line.price_subtotal = taxes_res["total_excluded"] + line.price_total = taxes_res["total_included"] + else: + # No taxes applied on the line. + subtotal = line.quantity * line_discount_price_unit + line.price_total = line.price_subtotal = subtotal + + done_lines |= line + + # Compute the regular totals for regular lines. + return super(AccountMoveLine, self - done_lines)._compute_totals() + + @api.onchange("discount_fixed") + def _onchange_discount_fixed(self): + """Compute the fixed discount based on the discount percentage.""" + if self.env.context.get("ignore_discount_onchange"): + return + self.env.context = self.with_context(ignore_discount_onchange=True).env.context + self.discount = self._get_discount_from_fixed_discount() + + @api.onchange("discount") + def _onchange_discount(self): + """Compute the discount percentage based on the fixed discount. + Ignore the onchange if the fixed discount is already set. + """ + if self.env.context.get("ignore_discount_onchange"): + return + self.env.context = self.with_context(ignore_discount_onchange=True).env.context + self.discount_fixed = 0.0 + + def _get_discount_from_fixed_discount(self): + """Calculate the discount percentage from the fixed discount amount.""" + self.ensure_one() + currency = self.currency_id or self.company_id.currency_id + if float_is_zero(self.discount_fixed, precision_rounding=currency.rounding): + return 0.0 + return (self.discount_fixed / self.price_unit) * 100 diff --git a/account_invoice_fixed_discount/models/account_tax.py b/account_invoice_fixed_discount/models/account_tax.py new file mode 100644 index 00000000000..0c20cec77a6 --- /dev/null +++ b/account_invoice_fixed_discount/models/account_tax.py @@ -0,0 +1,49 @@ +# Copyright 2017 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from odoo import api, models + + +class AccountTax(models.Model): + _inherit = "account.tax" + + @api.model + def _convert_to_tax_base_line_dict( + self, + base_line, + partner=None, + currency=None, + product=None, + taxes=None, + price_unit=None, + quantity=None, + discount=None, + account=None, + analytic_distribution=None, + price_subtotal=None, + is_refund=False, + rate=None, + handle_price_include=True, + extra_context=None, + ): + """Insert the un-rounded discount value in the resulting tax computation values.""" + res = super()._convert_to_tax_base_line_dict( + base_line, + partner=partner, + currency=currency, + product=product, + taxes=taxes, + price_unit=price_unit, + quantity=quantity, + discount=discount, + account=account, + analytic_distribution=analytic_distribution, + price_subtotal=price_subtotal, + is_refund=is_refund, + rate=rate, + handle_price_include=handle_price_include, + extra_context=extra_context, + ) + if base_line._name == "account.move.line" and base_line.discount_fixed: + res["discount"] = base_line._get_discount_from_fixed_discount() + return res diff --git a/account_invoice_fixed_discount/readme/CONTRIBUTORS.rst b/account_invoice_fixed_discount/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..44ef0c418c5 --- /dev/null +++ b/account_invoice_fixed_discount/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* Lois Rilo +* Jordi Ballester +* Rattapong Chokmasermkul +* Kitti U. +* Pieter Paulussen diff --git a/account_invoice_fixed_discount/readme/DESCRIPTION.rst b/account_invoice_fixed_discount/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..19defa557c0 --- /dev/null +++ b/account_invoice_fixed_discount/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module extends the functionality of Invoicing to allow you to apply fixed +amount discounts at invoice line level. + +The module also extends the invoice report to show fixed discount. diff --git a/account_invoice_fixed_discount/readme/INSTALL.rst b/account_invoice_fixed_discount/readme/INSTALL.rst new file mode 100644 index 00000000000..7c551f17b47 --- /dev/null +++ b/account_invoice_fixed_discount/readme/INSTALL.rst @@ -0,0 +1,3 @@ +**Warning**: This module is incompatible with +``account_invoice_triple_discount`` which also belongs to `OCA/account-invoicing +`__. diff --git a/account_invoice_fixed_discount/readme/USAGE.rst b/account_invoice_fixed_discount/readme/USAGE.rst new file mode 100644 index 00000000000..9d0cb920cbb --- /dev/null +++ b/account_invoice_fixed_discount/readme/USAGE.rst @@ -0,0 +1,5 @@ +To use this module, you need to: + +#. Go to *Settings* and *Activate the developer mode* +#. Go to *Invoicing*. +#. Create a Invoice and specify a fixed discount in a line. diff --git a/account_invoice_fixed_discount/reports/report_account_invoice.xml b/account_invoice_fixed_discount/reports/report_account_invoice.xml new file mode 100644 index 00000000000..30e3626d1f8 --- /dev/null +++ b/account_invoice_fixed_discount/reports/report_account_invoice.xml @@ -0,0 +1,35 @@ + + + + diff --git a/account_invoice_fixed_discount/security/res_groups.xml b/account_invoice_fixed_discount/security/res_groups.xml new file mode 100644 index 00000000000..5b6ef73f594 --- /dev/null +++ b/account_invoice_fixed_discount/security/res_groups.xml @@ -0,0 +1,21 @@ + + + + + + Fixed Discount + + + + + + + + + + + + diff --git a/account_invoice_fixed_discount/static/description/icon.png b/account_invoice_fixed_discount/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/account_invoice_fixed_discount/static/description/icon.png differ diff --git a/account_invoice_fixed_discount/static/description/index.html b/account_invoice_fixed_discount/static/description/index.html new file mode 100644 index 00000000000..b158f1dfbdf --- /dev/null +++ b/account_invoice_fixed_discount/static/description/index.html @@ -0,0 +1,448 @@ + + + + + + +Account Fixed Discount + + + +
+

Account Fixed Discount

+ + +

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

+

This module extends the functionality of Invoicing to allow you to apply fixed +amount discounts at invoice line level.

+

The module also extends the invoice report to show fixed discount.

+

Table of contents

+ +
+

Installation

+

Warning: This module is incompatible with +account_invoice_triple_discount which also belongs to OCA/account-invoicing.

+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Settings and Activate the developer mode
  2. +
  3. Go to Invoicing.
  4. +
  5. Create a Invoice and specify a fixed discount in a line.
  6. +
+
+
+

Known issues / Roadmap

+
    +
  • At the moment, the simultaneous use of percent and fixed discounts (at +line level) is not supported.
  • +
+
+
+

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

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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

+

This module is part of the OCA/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_fixed_discount/tests/__init__.py b/account_invoice_fixed_discount/tests/__init__.py new file mode 100644 index 00000000000..2598e9f1961 --- /dev/null +++ b/account_invoice_fixed_discount/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from . import test_account_fixed_discount diff --git a/account_invoice_fixed_discount/tests/test_account_fixed_discount.py b/account_invoice_fixed_discount/tests/test_account_fixed_discount.py new file mode 100644 index 00000000000..913886b53a1 --- /dev/null +++ b/account_invoice_fixed_discount/tests/test_account_fixed_discount.py @@ -0,0 +1,139 @@ +# Copyright 2017 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from odoo.tests import TransactionCase +from odoo.tests.common import Form + + +class TestInvoiceFixedDiscount(TransactionCase): + @classmethod + def setUpClass(cls): + super(TestInvoiceFixedDiscount, cls).setUpClass() + + cls.env.user.groups_id |= cls.env.ref("account.group_account_invoice") + cls.partner = cls.env["res.partner"].create({"name": "Test"}) + cls.product = cls.env.ref("product.product_product_3") + cls.account = cls.env["account.account"].search( + [("account_type", "=", "income")], + limit=1, + ) + cls.output_vat_acct = cls.env["account.account"].create( + {"name": "10", "code": "10", "account_type": "liability_current"} + ) + cls.tax_group_vat = cls.env["account.tax.group"].create({"name": "VAT"}) + cls.vat = cls.env["account.tax"].create( + { + "name": "TEST 10%", + "type_tax_use": "sale", + "amount_type": "percent", + "amount": 10.00, + "tax_group_id": cls.tax_group_vat.id, + "tax_exigibility": "on_invoice", + "invoice_repartition_line_ids": [ + (0, 0, {"factor_percent": 100.0, "repartition_type": "base"}), + ( + 0, + 0, + { + "factor_percent": 100.0, + "repartition_type": "tax", + "account_id": cls.output_vat_acct.id, + }, + ), + ], + } + ) + cls.invoice = cls._create_invoice() + + @classmethod + def _create_invoice(cls, discount=0.00, discount_fixed=0.00): + invoice_vals = [ + ( + 0, + 0, + { + "product_id": cls.product.id, + "quantity": 1.0, + "account_id": cls.account.id, + "name": "Line 1", + "price_unit": 200.00, + "discount_fixed": discount_fixed, + "discount": discount, + "tax_ids": [(6, 0, [cls.vat.id])], + }, + ) + ] + invoice = ( + cls.env["account.move"] + .with_context(check_move_validity=False) + .create( + { + "journal_id": cls.env["account.journal"] + .search([("type", "=", "sale")], limit=1) + .id, + "partner_id": cls.partner.id, + "move_type": "out_invoice", + "invoice_line_ids": invoice_vals, + } + ) + ) + return invoice + + def test_01_discounts_fixed_single_unit(self): + """Tests multiple discounts in line with taxes.""" + + # Fixed discount 1.0 unit at 57.00 + with Form(self.invoice) as invoice_form: + with invoice_form.invoice_line_ids.edit(0) as line: + line.discount_fixed = 57.00 + + # compute discount (57 / 200) * 100 + self.assertEqual(self.invoice.invoice_line_ids.discount, 28.5) + # compute amount total (200 - 57) * 10% + self.assertEqual(self.invoice.amount_total, 157.3) + self.assertEqual(self.invoice.invoice_line_ids.price_unit, 200.00) + self.assertEqual(self.invoice.invoice_line_ids.price_subtotal, 143.00) + + # Reset to regular discount at 20.00% + with Form(self.invoice) as invoice_form: + with invoice_form.invoice_line_ids.edit(0) as line: + # Force the fixed discount as the onchange does not + # handle the context properly + line.discount_fixed = 0.0 + line.discount = 20.0 + + self.assertEqual(self.invoice.invoice_line_ids.discount_fixed, 0.0) + self.assertEqual(self.invoice.invoice_line_ids.discount, 20.0) + self.assertEqual(self.invoice.amount_total, 176.0) + self.assertEqual(self.invoice.invoice_line_ids.price_unit, 200.00) + self.assertEqual(self.invoice.invoice_line_ids.price_subtotal, 160.00) + + def test_02_discounts_fixed_multiple_units(self): + """Tests multiple discounts in line with taxes.""" + + # Fixed discount 2.0 units at 50.00 + with Form(self.invoice) as invoice_form: + with invoice_form.invoice_line_ids.edit(0) as line: + line.discount_fixed = 25.00 + line.quantity = 2.0 + + # compute discount ((50 / 2) / 200) * 100 + self.assertEqual(self.invoice.invoice_line_ids.discount, 12.5) + self.assertEqual(self.invoice.amount_total, 385.0) + self.assertEqual(self.invoice.invoice_line_ids.price_unit, 200.00) + self.assertEqual(self.invoice.invoice_line_ids.price_subtotal, 350) + + def test_03_discount_fixed_no_tax(self): + """Tests fixed discount with no taxes.""" + + # Fixed discount 1.0 unit at 57.00 + with Form(self.invoice) as invoice_form: + with invoice_form.invoice_line_ids.edit(0) as line: + line.tax_ids.clear() + line.discount_fixed = 57.00 + + # compute discount (57 / 200) * 100 + self.assertEqual(self.invoice.invoice_line_ids.discount, 28.5) + self.assertEqual(self.invoice.amount_total, 143) + self.assertEqual(self.invoice.invoice_line_ids.price_unit, 200.00) + self.assertEqual(self.invoice.invoice_line_ids.price_subtotal, 143) diff --git a/account_invoice_fixed_discount/views/account_move_view.xml b/account_invoice_fixed_discount/views/account_move_view.xml new file mode 100644 index 00000000000..521d0d7818c --- /dev/null +++ b/account_invoice_fixed_discount/views/account_move_view.xml @@ -0,0 +1,30 @@ + + + + account.move.form - fixed_discount + account.move + + + + + + + + + + + diff --git a/setup/account_invoice_fixed_discount/odoo/addons/account_invoice_fixed_discount b/setup/account_invoice_fixed_discount/odoo/addons/account_invoice_fixed_discount new file mode 120000 index 00000000000..39b6f2dcca0 --- /dev/null +++ b/setup/account_invoice_fixed_discount/odoo/addons/account_invoice_fixed_discount @@ -0,0 +1 @@ +../../../../account_invoice_fixed_discount \ No newline at end of file diff --git a/setup/account_invoice_fixed_discount/setup.py b/setup/account_invoice_fixed_discount/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/account_invoice_fixed_discount/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)