diff --git a/account_invoice_fixed_discount/README.rst b/account_invoice_fixed_discount/README.rst new file mode 100644 index 00000000000..35d81560790 --- /dev/null +++ b/account_invoice_fixed_discount/README.rst @@ -0,0 +1,103 @@ +====================== +Account Fixed Discount +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:64739ba21892bedaba82d3a159203c9da5cc352bbddd5470aa35680642d08019 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.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-18-0/account-invoicing-18-0-account_invoice_fixed_discount + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&target_branch=18.0 + :alt: Try me on Runboat + +|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: + +1. Go to *Settings* and *Activate the developer mode* +2. Go to *Invoicing*. +3. Create a Invoice and specify a fixed discount in a line. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ForgeFlow + +Contributors +------------ + +- Lois Rilo +- Jordi Ballester +- Rattapong Chokmasermkul +- Kitti U. +- Pieter Paulussen + +- OERP Canada : + + - Foram Darji + +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..f51baa199b9 --- /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": "18.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..2ad25816924 --- /dev/null +++ b/account_invoice_fixed_discount/i18n/account_invoice_fixed_discount.pot @@ -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 17.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid " %)" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid " (or" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid "Discount Amount (%)" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,help:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "" +"Apply a fixed amount discount to this line. The amount is multiplied by the " +"quantity of the product." +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:res.groups,name:account_invoice_fixed_discount.group_fixed_discount +msgid "Fixed Discount" +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 +#: model:ir.model,name:account_invoice_fixed_discount.model_account_tax +msgid "Tax" +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..b99a6443cf4 --- /dev/null +++ b/account_invoice_fixed_discount/i18n/ca.po @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_fixed_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-02-14 16:59+0000\n" +"PO-Revision-Date: 2024-02-14 16:59+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \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 " %)" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid " (or" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid "Discount Amount (%)" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,help:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "" +"Apply a fixed amount discount to this line. The amount is multiplied by the " +"quantity of the product." +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:res.groups,name:account_invoice_fixed_discount.group_fixed_discount +msgid "Fixed Discount" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_move_line +msgid "Journal Item" +msgstr "Apunt comptable" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_tax +msgid "Tax" +msgstr "Impost" diff --git a/account_invoice_fixed_discount/i18n/de.po b/account_invoice_fixed_discount/i18n/de.po new file mode 100644 index 00000000000..7048b563b93 --- /dev/null +++ b/account_invoice_fixed_discount/i18n/de.po @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_fixed_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-02-14 17:00+0000\n" +"PO-Revision-Date: 2024-02-14 17:00+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \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 " %)" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid " (or" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid "Discount Amount (%)" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,help:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "" +"Apply a fixed amount discount to this line. The amount is multiplied by the " +"quantity of the product." +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 "Rabatt (abs.)" + +#. module: account_invoice_fixed_discount +#: model:res.groups,name:account_invoice_fixed_discount.group_fixed_discount +msgid "Fixed Discount" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_move_line +msgid "Journal Item" +msgstr "Buchungszeile" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_tax +msgid "Tax" +msgstr "Steuer" diff --git a/account_invoice_fixed_discount/i18n/es.po b/account_invoice_fixed_discount/i18n/es.po new file mode 100644 index 00000000000..acd426d6387 --- /dev/null +++ b/account_invoice_fixed_discount/i18n/es.po @@ -0,0 +1,68 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_fixed_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-02-14 17:02+0000\n" +"PO-Revision-Date: 2024-04-24 10:41+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid " %)" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid " (or" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid "Discount Amount (%)" +msgstr "Importe del descuento (%)" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,help:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "" +"Apply a fixed amount discount to this line. The amount is multiplied by the " +"quantity of the product." +msgstr "" +"Aplica un descuento de importe fijo a esta línea. El importe se multiplica " +"por la cantidad del producto." + +#. 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:res.groups,name:account_invoice_fixed_discount.group_fixed_discount +msgid "Fixed Discount" +msgstr "Descuento fijo" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_move_line +msgid "Journal Item" +msgstr "Apunte contable" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_tax +msgid "Tax" +msgstr "Impuesto" + +#~ msgid "(or" +#~ msgstr "(o" + +#~ msgid "Disc. %" +#~ msgstr "Desc. %" diff --git a/account_invoice_fixed_discount/i18n/it.po b/account_invoice_fixed_discount/i18n/it.po new file mode 100644 index 00000000000..dd857de9140 --- /dev/null +++ b/account_invoice_fixed_discount/i18n/it.po @@ -0,0 +1,67 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_fixed_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-05-17 12:35+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid " %)" +msgstr " %)" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid " (or" +msgstr " (o" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid "Discount Amount (%)" +msgstr "Valore sconto (%)" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,help:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "" +"Apply a fixed amount discount to this line. The amount is multiplied by the " +"quantity of the product." +msgstr "" +"Applica un valore sconto a questa riga. Il valore è moltiplicato per la " +"quantità del prodotto." + +#. 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 "Sconto (fisso)" + +#. module: account_invoice_fixed_discount +#: model:res.groups,name:account_invoice_fixed_discount.group_fixed_discount +msgid "Fixed Discount" +msgstr "Sconto fisso" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_move_line +msgid "Journal Item" +msgstr "Movimento contabile" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_tax +msgid "Tax" +msgstr "Imposta" + +#~ msgid "(or" +#~ msgstr "(o" + +#~ msgid "Disc. %" +#~ msgstr "Sconto %" diff --git a/account_invoice_fixed_discount/i18n/pt_BR.po b/account_invoice_fixed_discount/i18n/pt_BR.po new file mode 100644 index 00000000000..88466429384 --- /dev/null +++ b/account_invoice_fixed_discount/i18n/pt_BR.po @@ -0,0 +1,67 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_fixed_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-02-14 17:04+0000\n" +"PO-Revision-Date: 2024-02-14 17:04+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \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 " %)" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid " (or" +msgstr "" + +#. module: account_invoice_fixed_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_discount.report_invoice_document +msgid "Discount Amount (%)" +msgstr "Total Desconto (%)" + +#. module: account_invoice_fixed_discount +#: model:ir.model.fields,help:account_invoice_fixed_discount.field_account_move_line__discount_fixed +msgid "" +"Apply a fixed amount discount to this line. The amount is multiplied by the " +"quantity of the product." +msgstr "" +"Aplique um desconto de valor fixo a esta linha. O valor é multiplicado pela " +"quantidade do produto." + +#. 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 "Desconto (Fixo)" + +#. module: account_invoice_fixed_discount +#: model:res.groups,name:account_invoice_fixed_discount.group_fixed_discount +msgid "Fixed Discount" +msgstr "Desconto Fixo" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_move_line +msgid "Journal Item" +msgstr "Item do diário" + +#. module: account_invoice_fixed_discount +#: model:ir.model,name:account_invoice_fixed_discount.model_account_tax +msgid "Tax" +msgstr "Imposto" + +#~ msgid "(or" +#~ msgstr "(ou" + +#~ msgid "Disc. %" +#~ msgstr "Desc. %" 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..1a472aa7ae7 --- /dev/null +++ b/account_invoice_fixed_discount/models/account_tax.py @@ -0,0 +1,15 @@ +# 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 _prepare_base_line_for_taxes_computation(self, record, **kwargs): + res = super()._prepare_base_line_for_taxes_computation(record, **kwargs) + if record and record._name == "account.move.line" and record.discount_fixed: + res["discount"] = record._get_discount_from_fixed_discount() + return res diff --git a/account_invoice_fixed_discount/pyproject.toml b/account_invoice_fixed_discount/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/account_invoice_fixed_discount/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_invoice_fixed_discount/readme/CONTRIBUTORS.md b/account_invoice_fixed_discount/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..4309e200f78 --- /dev/null +++ b/account_invoice_fixed_discount/readme/CONTRIBUTORS.md @@ -0,0 +1,7 @@ +- Lois Rilo \<\> +- Jordi Ballester \<\> +- Rattapong Chokmasermkul \<\> +- Kitti U. \<\> +- Pieter Paulussen \<\> +* OERP Canada \<\>: + - Foram Darji \<\> diff --git a/account_invoice_fixed_discount/readme/DESCRIPTION.md b/account_invoice_fixed_discount/readme/DESCRIPTION.md new file mode 100644 index 00000000000..afcd5642822 --- /dev/null +++ b/account_invoice_fixed_discount/readme/DESCRIPTION.md @@ -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.md b/account_invoice_fixed_discount/readme/INSTALL.md new file mode 100644 index 00000000000..a4484b880c0 --- /dev/null +++ b/account_invoice_fixed_discount/readme/INSTALL.md @@ -0,0 +1,3 @@ +**Warning**: This module is incompatible with +`account_invoice_triple_discount` which also belongs to +[OCA/account-invoicing](https://github.com/OCA/account-invoicing). diff --git a/account_invoice_fixed_discount/readme/USAGE.md b/account_invoice_fixed_discount/readme/USAGE.md new file mode 100644 index 00000000000..e3dafad41a0 --- /dev/null +++ b/account_invoice_fixed_discount/readme/USAGE.md @@ -0,0 +1,5 @@ +To use this module, you need to: + +1. Go to *Settings* and *Activate the developer mode* +2. Go to *Invoicing*. +3. 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..7fb377c01a5 --- /dev/null +++ b/account_invoice_fixed_discount/reports/report_account_invoice.xml @@ -0,0 +1,33 @@ + + + + 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..5af25e77587 --- /dev/null +++ b/account_invoice_fixed_discount/security/res_groups.xml @@ -0,0 +1,17 @@ + + + + + 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..1eca7b74a0b --- /dev/null +++ b/account_invoice_fixed_discount/static/description/index.html @@ -0,0 +1,450 @@ + + + + + +Account Fixed Discount + + + +
+

Account Fixed Discount

+ + +

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

+

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. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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

+

This module is part of the OCA/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..41d2fe3dc48 --- /dev/null +++ b/account_invoice_fixed_discount/tests/test_account_fixed_discount.py @@ -0,0 +1,145 @@ +# Copyright 2017 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from odoo.tests import Form, TransactionCase + + +class TestInvoiceFixedDiscount(TransactionCase): + @classmethod + def setUpClass(cls): + super().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) + + def test_04_base_line_set_to_none(self): + self.vat._prepare_base_line_for_taxes_computation( + None, + price_unit=10, + currency=1, + ) 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..000dee8a8bd --- /dev/null +++ b/account_invoice_fixed_discount/views/account_move_view.xml @@ -0,0 +1,30 @@ + + + + account.move.form - fixed_discount + account.move + + + + + + + + + + +