diff --git a/sale_fixed_discount/README.rst b/sale_fixed_discount/README.rst new file mode 100644 index 00000000000..34758219e2c --- /dev/null +++ b/sale_fixed_discount/README.rst @@ -0,0 +1,113 @@ +=================== +Sale Fixed Discount +=================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:6b49ea689315a0a5b3c5db1dbd0a6ea8c2400faad3943a6da1a547d929d4360d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/18.0/sale_fixed_discount + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-18-0/sale-workflow-18-0-sale_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/sale-workflow&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of Sales to allow you to apply +fixed amount discount at sales order line level. + +The module also extends the sales order report to show fixed discount. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +This module depends on module 'account_invoice_fixed_discount', +available in +https://github.com/OCA/account-invoicing/tree/17.0/account_invoice_fixed_discount + +Configuration +============= + +To configure this module, you need to: + +1. Go to *Sales > Configuration > Settings*. +2. In the *Pricing* section select *Discounts* option to grant discounts + on sales order lines. + +Usage +===== + +To use this module, you need to: + +1. Go to *Sales*. +2. Create a Sales Order and specify the type of discount and + fixed/percent 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 + (`www.forgeflow.com `__) +- Jordi Ballester + (`www.forgeflow.com `__) +- Pieter Paulussen + (`www.code-source.be `__) + +- 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/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_fixed_discount/__init__.py b/sale_fixed_discount/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/sale_fixed_discount/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_fixed_discount/__manifest__.py b/sale_fixed_discount/__manifest__.py new file mode 100644 index 00000000000..79ecbfa3158 --- /dev/null +++ b/sale_fixed_discount/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2017-20 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Sale Fixed Discount", + "summary": "Allows to apply fixed amount discounts in sales orders.", + "version": "18.0.1.0.0", + "category": "Sales", + "website": "https://github.com/OCA/sale-workflow", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["sale", "account_invoice_fixed_discount"], + "data": [ + "security/res_groups.xml", + "reports/report_sale_order.xml", + "views/account_invoice_views.xml", + "views/sale_order_views.xml", + "views/sale_portal_templates.xml", + ], +} diff --git a/sale_fixed_discount/i18n/es.po b/sale_fixed_discount/i18n/es.po new file mode 100644 index 00000000000..7496a1b4cb6 --- /dev/null +++ b/sale_fixed_discount/i18n/es.po @@ -0,0 +1,78 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_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:32+0000\n" +"PO-Revision-Date: 2024-04-23 08:39+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: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid " %)" +msgstr "" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid " (or" +msgstr "" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.sale_order_portal_content +msgid "Disc. Fixed Amount" +msgstr "Desc. Monto fijo" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid "Discount Amount (%)" +msgstr "Importe del descuento (%)" + +#. module: sale_fixed_discount +#: model:ir.model.fields,field_description:sale_fixed_discount.field_sale_order_line__discount_fixed +msgid "Discount (Fixed)" +msgstr "Descuento (Fijo)" + +#. module: sale_fixed_discount +#: model:ir.model.fields,help:sale_fixed_discount.field_sale_order_line__discount_fixed +msgid "Fixed amount discount." +msgstr "Importe fijo de descuento." + +#. module: sale_fixed_discount +#: model:ir.model,name:sale_fixed_discount.model_sale_order_line +msgid "Sales Order Line" +msgstr "Línea Pedido de Venta" + +#. module: sale_fixed_discount +#. odoo-python +#: code:addons/sale_fixed_discount/models/sale_order_line.py:0 +#, python-format +msgid "" +"The fixed discount %(fixed)s does not match the calculateddiscount " +"%(discount)s %%.Please correct one of the discounts." +msgstr "" +"El descuento fijo %(fixed)s no coincide con el descuento calculado " +"%(discount)s %%.Por favor, corrija uno de los descuentos." + +#~ msgid "(or" +#~ msgstr "(o" + +#~ msgid "Disc. %" +#~ msgstr "Desc. %" + +#, python-format +#~ msgid "" +#~ "The fixed discount %(fixed)s does not match the calculated discount " +#~ "%(discount)s %%. Please correct one of the discounts." +#~ msgstr "" +#~ "El descuento fijo %(fixed)s no coincide con el descuento calculado " +#~ "%(discount)s %%. Por favor, corrija uno de los descuentos." diff --git a/sale_fixed_discount/i18n/fr.po b/sale_fixed_discount/i18n/fr.po new file mode 100644 index 00000000000..278b970b0d8 --- /dev/null +++ b/sale_fixed_discount/i18n/fr.po @@ -0,0 +1,61 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_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:31+0000\n" +"PO-Revision-Date: 2024-02-14 17:31+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: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid " %)" +msgstr "" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid " (or" +msgstr "" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.sale_order_portal_content +msgid "Disc. Fixed Amount" +msgstr "Remise en montant fixe" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid "Discount Amount (%)" +msgstr "" + +#. module: sale_fixed_discount +#: model:ir.model.fields,field_description:sale_fixed_discount.field_sale_order_line__discount_fixed +msgid "Discount (Fixed)" +msgstr "Remise (fixe)" + +#. module: sale_fixed_discount +#: model:ir.model.fields,help:sale_fixed_discount.field_sale_order_line__discount_fixed +msgid "Fixed amount discount." +msgstr "Remise en montant fixe." + +#. module: sale_fixed_discount +#: model:ir.model,name:sale_fixed_discount.model_sale_order_line +msgid "Sales Order Line" +msgstr "Ligne de bons de commande" + +#. module: sale_fixed_discount +#. odoo-python +#: code:addons/sale_fixed_discount/models/sale_order_line.py:0 +#, python-format +msgid "" +"The fixed discount %(fixed)s does not match the calculateddiscount " +"%(discount)s %%.Please correct one of the discounts." +msgstr "" diff --git a/sale_fixed_discount/i18n/it.po b/sale_fixed_discount/i18n/it.po new file mode 100644 index 00000000000..06296b7211f --- /dev/null +++ b/sale_fixed_discount/i18n/it.po @@ -0,0 +1,78 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_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:30+0000\n" +"PO-Revision-Date: 2024-06-12 16:38+0000\n" +"Last-Translator: mymage \n" +"Language-Team: \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: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid " %)" +msgstr " %)" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid " (or" +msgstr " (o" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.sale_order_portal_content +msgid "Disc. Fixed Amount" +msgstr "Importo sconto fisso" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid "Discount Amount (%)" +msgstr "Valore sconto (%)" + +#. module: sale_fixed_discount +#: model:ir.model.fields,field_description:sale_fixed_discount.field_sale_order_line__discount_fixed +msgid "Discount (Fixed)" +msgstr "Sconto (fisso)" + +#. module: sale_fixed_discount +#: model:ir.model.fields,help:sale_fixed_discount.field_sale_order_line__discount_fixed +msgid "Fixed amount discount." +msgstr "Importo sconto fisso." + +#. module: sale_fixed_discount +#: model:ir.model,name:sale_fixed_discount.model_sale_order_line +msgid "Sales Order Line" +msgstr "Riga ordine di vendita" + +#. module: sale_fixed_discount +#. odoo-python +#: code:addons/sale_fixed_discount/models/sale_order_line.py:0 +#, python-format +msgid "" +"The fixed discount %(fixed)s does not match the calculateddiscount " +"%(discount)s %%.Please correct one of the discounts." +msgstr "" +"Lo sconto fisso %(fixed)s non corrisponde allo sconto calcolato %(discount)s " +"%%. Correggere uno degli sconti." + +#~ msgid "(or" +#~ msgstr "(o" + +#~ msgid "Disc. %" +#~ msgstr "Sconto %" + +#, python-format +#~ msgid "" +#~ "The fixed discount %(fixed)s does not match the calculated discount " +#~ "%(discount)s %%. Please correct one of the discounts." +#~ msgstr "" +#~ "Lo sconto fisso %(fixed)s non corrisponde allo sconto calcolato " +#~ "%(discount)s %%. Correggere uno degli sconti." diff --git a/sale_fixed_discount/i18n/pt_BR.po b/sale_fixed_discount/i18n/pt_BR.po new file mode 100644 index 00000000000..622573af69a --- /dev/null +++ b/sale_fixed_discount/i18n/pt_BR.po @@ -0,0 +1,75 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_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:29+0000\n" +"PO-Revision-Date: 2024-02-14 17:29+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: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid " %)" +msgstr "" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid " (or" +msgstr "" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.sale_order_portal_content +msgid "Disc. Fixed Amount" +msgstr "Desc. Valor" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid "Discount Amount (%)" +msgstr "Valor Desconto (%)" + +#. module: sale_fixed_discount +#: model:ir.model.fields,field_description:sale_fixed_discount.field_sale_order_line__discount_fixed +msgid "Discount (Fixed)" +msgstr "Desconto (Fixo)" + +#. module: sale_fixed_discount +#: model:ir.model.fields,help:sale_fixed_discount.field_sale_order_line__discount_fixed +msgid "Fixed amount discount." +msgstr "Desconto Valor Fixo." + +#. module: sale_fixed_discount +#: model:ir.model,name:sale_fixed_discount.model_sale_order_line +msgid "Sales Order Line" +msgstr "Linha Pedido de Venda" + +#. module: sale_fixed_discount +#. odoo-python +#: code:addons/sale_fixed_discount/models/sale_order_line.py:0 +#, python-format +msgid "" +"The fixed discount %(fixed)s does not match the calculateddiscount " +"%(discount)s %%.Please correct one of the discounts." +msgstr "" + +#~ msgid "(or" +#~ msgstr "(ou" + +#~ msgid "Disc. %" +#~ msgstr "Desc. %" + +#, python-format +#~ msgid "" +#~ "The fixed discount %(fixed)s does not match the calculated discount " +#~ "%(discount)s %%. Please correct one of the discounts." +#~ msgstr "" +#~ "O desconto fixo %(fixed)s não corresponde ao desconto calculado " +#~ "%(discount)s %%. Corrija um dos descontos." diff --git a/sale_fixed_discount/i18n/sale_fixed_discount.pot b/sale_fixed_discount/i18n/sale_fixed_discount.pot new file mode 100644 index 00000000000..0de06706e60 --- /dev/null +++ b/sale_fixed_discount/i18n/sale_fixed_discount.pot @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_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: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid " %)" +msgstr "" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid " (or" +msgstr "" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.sale_order_portal_content +msgid "Disc. Fixed Amount" +msgstr "" + +#. module: sale_fixed_discount +#: model_terms:ir.ui.view,arch_db:sale_fixed_discount.report_saleorder_document +msgid "Discount Amount (%)" +msgstr "" + +#. module: sale_fixed_discount +#: model:ir.model.fields,field_description:sale_fixed_discount.field_sale_order_line__discount_fixed +msgid "Discount (Fixed)" +msgstr "" + +#. module: sale_fixed_discount +#: model:ir.model.fields,help:sale_fixed_discount.field_sale_order_line__discount_fixed +msgid "Fixed amount discount." +msgstr "" + +#. module: sale_fixed_discount +#: model:ir.model,name:sale_fixed_discount.model_sale_order_line +msgid "Sales Order Line" +msgstr "" + +#. module: sale_fixed_discount +#. odoo-python +#: code:addons/sale_fixed_discount/models/sale_order_line.py:0 +#, python-format +msgid "" +"The fixed discount %(fixed)s does not match the calculateddiscount " +"%(discount)s %%.Please correct one of the discounts." +msgstr "" diff --git a/sale_fixed_discount/models/__init__.py b/sale_fixed_discount/models/__init__.py new file mode 100644 index 00000000000..8eb9d1d4046 --- /dev/null +++ b/sale_fixed_discount/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order_line diff --git a/sale_fixed_discount/models/sale_order_line.py b/sale_fixed_discount/models/sale_order_line.py new file mode 100644 index 00000000000..93141fd41cb --- /dev/null +++ b/sale_fixed_discount/models/sale_order_line.py @@ -0,0 +1,102 @@ +# Copyright 2017-20 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError +from odoo.tools.float_utils import float_compare, float_round + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + discount_fixed = fields.Float( + string="Discount (Fixed)", + digits="Product Price", + help="Fixed amount discount.", + ) + + @api.constrains("discount_fixed", "discount") + def _check_discounts(self): + """Check that the fixed discount and the discount percentage are consistent.""" + for line in self: + if line.discount_fixed and line.discount: + currency = line.currency_id + calculated_fixed_discount = float_round( + line._get_discount_from_fixed_discount(), + precision_rounding=currency.rounding, + ) + + if ( + float_compare( + calculated_fixed_discount, + line.discount, + precision_rounding=currency.rounding, + ) + != 0 + ): + raise ValidationError( + _( + "The fixed discount %(fixed)s does not match the calculated" + "discount %(discount)s %%." + "Please correct one of the discounts." + ) + % { + "fixed": line.discount_fixed, + "discount": line.discount, + } + ) + + def _prepare_base_line_for_taxes_computation(self, **kwargs): + """Prior to calculating the tax toals for a line, update the discount value + used in the tax calculation to the full float value. Otherwise, we get rounding + errors in the resulting calculated totals. + + For example: + - price_unit = 750.0 + - discount_fixed = 100.0 + - discount = 13.33 + => price_subtotal = 650.03 + + :return: A python dictionary. + """ + self.ensure_one() + # Accurately pass along the fixed discount amount to the tax computation method. + if self.discount_fixed: + return self.env["account.tax"]._prepare_base_line_for_taxes_computation( + self, + **{ + "tax_ids": self.tax_id, + "quantity": self.product_uom_qty, + "partner_id": self.order_id.partner_id, + "currency_id": self.order_id.currency_id + or self.order_id.company_id.currency_id, + "rate": self.order_id.currency_rate, + "discount": self._get_discount_from_fixed_discount(), + **kwargs, + }, + ) + return super()._prepare_base_line_for_taxes_computation(**kwargs) + + @api.depends("discount_fixed", "price_unit") + def _compute_discount(self): + lines_with_discount_fixed = self.filtered(lambda sol: sol.discount_fixed) + for line in lines_with_discount_fixed: + line.discount = line._get_discount_from_fixed_discount() + return super(SaleOrderLine, self - lines_with_discount_fixed) + + def _get_discount_from_fixed_discount(self): + """Calculate the discount percentage from the fixed discount amount.""" + self.ensure_one() + if not self.discount_fixed: + return 0.0 + + return ( + (self.price_unit != 0) + and ((self.discount_fixed) / self.price_unit) * 100 + or 0.00 + ) + + def _prepare_invoice_line(self, **optional_values): + res = super()._prepare_invoice_line(**optional_values) + res.update({"discount_fixed": self.discount_fixed}) + return res diff --git a/sale_fixed_discount/pyproject.toml b/sale_fixed_discount/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/sale_fixed_discount/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_fixed_discount/readme/CONFIGURE.md b/sale_fixed_discount/readme/CONFIGURE.md new file mode 100644 index 00000000000..7a476924702 --- /dev/null +++ b/sale_fixed_discount/readme/CONFIGURE.md @@ -0,0 +1,5 @@ +To configure this module, you need to: + +1. Go to *Sales \> Configuration \> Settings*. +2. In the *Pricing* section select *Discounts* option to grant + discounts on sales order lines. diff --git a/sale_fixed_discount/readme/CONTRIBUTORS.md b/sale_fixed_discount/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..cb8bc816ef2 --- /dev/null +++ b/sale_fixed_discount/readme/CONTRIBUTORS.md @@ -0,0 +1,7 @@ +- Lois Rilo \<\> (www.forgeflow.com) +- Jordi Ballester \<\> + (www.forgeflow.com) +- Pieter Paulussen \<\> + (www.code-source.be) +* OERP Canada \<\>: + - Foram Darji \<\> diff --git a/sale_fixed_discount/readme/DESCRIPTION.md b/sale_fixed_discount/readme/DESCRIPTION.md new file mode 100644 index 00000000000..27ffb7f35b8 --- /dev/null +++ b/sale_fixed_discount/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +This module extends the functionality of Sales to allow you to apply +fixed amount discount at sales order line level. + +The module also extends the sales order report to show fixed discount. diff --git a/sale_fixed_discount/readme/INSTALL.md b/sale_fixed_discount/readme/INSTALL.md new file mode 100644 index 00000000000..903fee03aa1 --- /dev/null +++ b/sale_fixed_discount/readme/INSTALL.md @@ -0,0 +1,3 @@ +This module depends on module 'account_invoice_fixed_discount', +available in + diff --git a/sale_fixed_discount/readme/USAGE.md b/sale_fixed_discount/readme/USAGE.md new file mode 100644 index 00000000000..e9078d4736b --- /dev/null +++ b/sale_fixed_discount/readme/USAGE.md @@ -0,0 +1,5 @@ +To use this module, you need to: + +1. Go to *Sales*. +2. Create a Sales Order and specify the type of discount and + fixed/percent discount in a line. diff --git a/sale_fixed_discount/reports/report_sale_order.xml b/sale_fixed_discount/reports/report_sale_order.xml new file mode 100644 index 00000000000..a5d9d938474 --- /dev/null +++ b/sale_fixed_discount/reports/report_sale_order.xml @@ -0,0 +1,37 @@ + + + + + diff --git a/sale_fixed_discount/security/res_groups.xml b/sale_fixed_discount/security/res_groups.xml new file mode 100644 index 00000000000..c37b3d0ce50 --- /dev/null +++ b/sale_fixed_discount/security/res_groups.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/sale_fixed_discount/static/description/icon.png b/sale_fixed_discount/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_fixed_discount/static/description/icon.png differ diff --git a/sale_fixed_discount/static/description/index.html b/sale_fixed_discount/static/description/index.html new file mode 100644 index 00000000000..b2f61bc7feb --- /dev/null +++ b/sale_fixed_discount/static/description/index.html @@ -0,0 +1,461 @@ + + + + + +Sale Fixed Discount + + + +
+

Sale Fixed Discount

+ + +

Beta License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runboat

+

This module extends the functionality of Sales to allow you to apply +fixed amount discount at sales order line level.

+

The module also extends the sales order report to show fixed discount.

+

Table of contents

+ +
+

Installation

+

This module depends on module ‘account_invoice_fixed_discount’, +available in +https://github.com/OCA/account-invoicing/tree/17.0/account_invoice_fixed_discount

+
+
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Go to Sales > Configuration > Settings.
  2. +
  3. In the Pricing section select Discounts option to grant discounts +on sales order lines.
  4. +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Sales.
  2. +
  3. Create a Sales Order and specify the type of discount and +fixed/percent discount in a line.
  4. +
+
+
+

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

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/sale-workflow project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_fixed_discount/tests/__init__.py b/sale_fixed_discount/tests/__init__.py new file mode 100644 index 00000000000..73fd17b7425 --- /dev/null +++ b/sale_fixed_discount/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_fixed_discount diff --git a/sale_fixed_discount/tests/test_sale_fixed_discount.py b/sale_fixed_discount/tests/test_sale_fixed_discount.py new file mode 100644 index 00000000000..6bfba8c5b7f --- /dev/null +++ b/sale_fixed_discount/tests/test_sale_fixed_discount.py @@ -0,0 +1,135 @@ +# Copyright 2017-18 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.exceptions import ValidationError +from odoo.tests import Form, TransactionCase + + +class TestSaleFixedDiscount(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env.user.groups_id |= cls.env.ref("sale.group_discount_per_so_line") + cls.partner = cls.env["res.partner"].create({"name": "Test"}) + cls.tax = cls.env["account.tax"].create( + { + "name": "TAX 15%", + "amount_type": "percent", + "type_tax_use": "sale", + "amount": 15.0, + } + ) + cls.product = cls.env["product.product"].create( + {"name": "Test product", "type": "consu"} + ) + cls.product2 = cls.env["product.product"].create( + {"name": "Test product 2", "type": "consu"} + ) + cls.sale = cls.env["sale.order"].create( + {"name": "Test Sale Order", "partner_id": cls.partner.id} + ) + cls.so_line = cls.env["sale.order.line"] + cls.sale_line1 = cls.so_line.create( + { + "order_id": cls.sale.id, + "name": "Line 1", + "price_unit": 200.0, + "product_uom_qty": 1, + "product_id": cls.product.id, + "tax_id": [(6, 0, [cls.tax.id])], + } + ) + + def test_01_discounts(self): + """Tests multiple discounts in line with taxes.""" + with Form(self.sale) as sale_order: + with sale_order.order_line.edit(0) as line: + line.discount_fixed = 20.0 + self.assertEqual(line.discount, 10.0) + self.assertEqual(line.price_subtotal, 180.0) + + self.assertEqual(self.sale.amount_total, 207.00) + + with Form(self.sale) as sale_order: + with sale_order.order_line.edit(0) as line: + line.product_uom_qty = 2 + line.price_unit = 200.0 + self.assertEqual(line.discount, 10.0) + self.assertEqual(line.price_subtotal, 360.0) + + self.assertEqual(self.sale.amount_total, 414.00) + + with Form(self.sale) as sale_order: + with sale_order.order_line.edit(0) as line: + line.product_uom_qty = 1 + line.price_unit = 200.0 + line.discount_fixed = 0.0 + line.discount = 50.0 + self.assertEqual(line.price_subtotal, 100.0) + + self.assertEqual(self.sale.amount_total, 115.00) + + with Form(self.sale) as sale_order: + with sale_order.order_line.new() as line2: + line2.product_id = self.product2 + line2.product_uom_qty = 1 + line2.price_unit = 100.0 + line2.discount_fixed = 5.0 + self.assertEqual(line2.discount, 5.0) + self.assertEqual(line2.price_subtotal, 95.0) + + # + self.assertEqual(self.sale.amount_total, 224.25) + + def test_02_fixed_discount_mismatch(self): + """Tests fixed discount mismatch.""" + with self.assertRaisesRegex( + ValidationError, + "Please correct one of the discounts", + ): + with Form(self.sale) as sale_order: + with sale_order.order_line.edit(0) as line: + line.discount_fixed = 20.0 + line.discount = 5.0 + + def test_03_fixed_discount_invoice(self): + """Test discount_fixed value propagation to account.move. + Case of editing order line by using UI. + """ + with Form(self.sale) as sale_order: + with sale_order.order_line.edit(0) as line: + line.discount_fixed = 20.0 + + self.sale.action_confirm() + self.sale._create_invoices() + + self.assertEqual(self.sale.invoice_ids.invoice_line_ids.discount_fixed, 20.0) + self.assertEqual(self.sale.invoice_ids.invoice_line_ids.discount, 10.0) + + self.assertEqual(self.sale.invoice_ids.tax_totals["base_amount"], 180.0) + self.assertEqual(self.sale.invoice_ids.tax_totals["total_amount"], 207.0) + + def test_04_fixed_discount_without_price(self): + with Form(self.sale) as sale_order: + with sale_order.order_line.edit(0) as line: + line.product_uom_qty = 1.0 + line.price_unit = 0.0 + line.discount_fixed = 50.0 + self.assertEqual(line.discount, 0.0) + self.assertEqual(line.price_subtotal, 0.0) + self.assertEqual(self.sale.amount_total, 0.0) + + def test_05_fixed_discount_invoice(self): + """Test discount_fixed value propagation to account.move. + Case of editing order line without using UI (onchange would be not triggered). + """ + self.sale.order_line.discount_fixed = 20.0 + + self.sale.action_confirm() + self.sale._create_invoices() + + self.assertEqual(self.sale.invoice_ids.invoice_line_ids.discount_fixed, 20.0) + self.assertEqual(self.sale.invoice_ids.invoice_line_ids.discount, 10.0) + + self.assertEqual(self.sale.invoice_ids.tax_totals["base_amount"], 180.0) + self.assertEqual(self.sale.invoice_ids.tax_totals["total_amount"], 207.0) diff --git a/sale_fixed_discount/views/account_invoice_views.xml b/sale_fixed_discount/views/account_invoice_views.xml new file mode 100644 index 00000000000..fe0c8ede7e7 --- /dev/null +++ b/sale_fixed_discount/views/account_invoice_views.xml @@ -0,0 +1,14 @@ + + + + + account.move - + account.move + + + + sale.group_discount_per_so_line + + + + diff --git a/sale_fixed_discount/views/sale_order_views.xml b/sale_fixed_discount/views/sale_order_views.xml new file mode 100644 index 00000000000..28e59813b47 --- /dev/null +++ b/sale_fixed_discount/views/sale_order_views.xml @@ -0,0 +1,24 @@ + + + + + sale.order.form - sale_fixed_discount + sale.order + + + + + + + + + + + diff --git a/sale_fixed_discount/views/sale_portal_templates.xml b/sale_fixed_discount/views/sale_portal_templates.xml new file mode 100644 index 00000000000..e9c6927a08e --- /dev/null +++ b/sale_fixed_discount/views/sale_portal_templates.xml @@ -0,0 +1,56 @@ + + + + diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000000..abf3a74472f --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-account_invoice_fixed_discount @ git+https://github.com/OCA/account-invoicing.git@refs/pull/1847/head#subdirectory=account_invoice_fixed_discount