diff --git a/.copier-answers.yml b/.copier-answers.yml index 83e7386036f..a1bbb1d8f21 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -16,9 +16,7 @@ odoo_test_flavor: Both odoo_version: 16.0 org_name: Odoo Community Association (OCA) org_slug: OCA -rebel_module_groups: -- account_invoice_triple_discount,account_invoice_supplierinfo_update_triple_discount -- account_invoice_fixed_discount +rebel_module_groups: [] repo_description: 'TODO: add repo description.' repo_name: account-invoicing repo_slug: account-invoicing diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5095b8c2b36..5ec4eb783e9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,24 +36,8 @@ jobs: matrix: include: - container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest - include: "account_invoice_triple_discount,account_invoice_supplierinfo_update_triple_discount" name: test with Odoo - container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest - include: "account_invoice_triple_discount,account_invoice_supplierinfo_update_triple_discount" - name: test with OCB - makepot: "true" - - container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest - include: "account_invoice_fixed_discount" - name: test with Odoo - - container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest - include: "account_invoice_fixed_discount" - name: test with OCB - makepot: "true" - - container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest - exclude: "account_invoice_triple_discount,account_invoice_supplierinfo_update_triple_discount,account_invoice_fixed_discount" - name: test with Odoo - - container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest - exclude: "account_invoice_triple_discount,account_invoice_supplierinfo_update_triple_discount,account_invoice_fixed_discount" name: test with OCB makepot: "true" services: @@ -65,9 +49,6 @@ jobs: POSTGRES_DB: odoo ports: - 5432:5432 - env: - INCLUDE: "${{ matrix.include }}" - EXCLUDE: "${{ matrix.exclude }}" steps: - uses: actions/checkout@v4 with: diff --git a/README.md b/README.md index aa701ea6a98..7dd00d02c9b 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ addon | version | maintainers | summary [account_invoice_discount_display_amount](account_invoice_discount_display_amount/) | 16.0.1.1.2 | | Show total discount applied and total without discount on invoices. [account_invoice_fiscal_position_update](account_invoice_fiscal_position_update/) | 16.0.1.0.2 | alexis-via | Changing the fiscal position of an invoice will auto-update invoice lines [account_invoice_fixed_discount](account_invoice_fixed_discount/) | 16.0.2.0.0 | | Allows to apply fixed amount discounts in invoices. +[account_invoice_fixed_triple_discount](account_invoice_fixed_triple_discount/) | 16.0.1.0.0 | | Compatibility between fixed and triple discount modules [account_invoice_force_number](account_invoice_force_number/) | 16.0.1.0.1 | | Allows to force invoice numbering on specific invoices [account_invoice_google_document_ai](account_invoice_google_document_ai/) | 16.0.1.0.0 | | Allows to import data from document using Google Document AI [account_invoice_line_default_account](account_invoice_line_default_account/) | 16.0.1.0.0 | | Account Invoice Line Default Account diff --git a/account_invoice_fixed_discount/README.rst b/account_invoice_fixed_discount/README.rst index c7694bf032c..3228ec3e091 100644 --- a/account_invoice_fixed_discount/README.rst +++ b/account_invoice_fixed_discount/README.rst @@ -1,3 +1,7 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + ====================== Account Fixed Discount ====================== @@ -13,7 +17,7 @@ Account Fixed Discount .. |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 +.. |badge2| image:: https://img.shields.io/badge/license-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 @@ -33,6 +37,8 @@ amount discounts at invoice line level. The module also extends the invoice report to show fixed discount. +If the module `account_invoice_triple_discount` is installed and a fixed discount is set, it will take priority over anything set in the triple discount fields. + **Table of contents** .. contents:: diff --git a/account_invoice_fixed_discount/__manifest__.py b/account_invoice_fixed_discount/__manifest__.py index 737876e4b73..76477545b10 100644 --- a/account_invoice_fixed_discount/__manifest__.py +++ b/account_invoice_fixed_discount/__manifest__.py @@ -12,7 +12,6 @@ "application": False, "installable": True, "depends": ["account"], - "excludes": ["account_invoice_triple_discount"], "data": [ "security/res_groups.xml", "views/account_move_view.xml", diff --git a/account_invoice_fixed_discount/readme/DESCRIPTION.rst b/account_invoice_fixed_discount/readme/DESCRIPTION.rst index 19defa557c0..311a593a598 100644 --- a/account_invoice_fixed_discount/readme/DESCRIPTION.rst +++ b/account_invoice_fixed_discount/readme/DESCRIPTION.rst @@ -2,3 +2,5 @@ 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. + +If the module `account_invoice_triple_discount` is installed and a fixed discount is set, it will take priority over anything set in the triple discount fields. diff --git a/account_invoice_fixed_discount/reports/report_account_invoice.xml b/account_invoice_fixed_discount/reports/report_account_invoice.xml index 882e344c376..24fe6603fc5 100644 --- a/account_invoice_fixed_discount/reports/report_account_invoice.xml +++ b/account_invoice_fixed_discount/reports/report_account_invoice.xml @@ -8,25 +8,36 @@ t-value="any([l.discount_fixed for l in o.invoice_line_ids])" /> - - not display_discount_fixed + + + + + - + Discount Amount (%) - - + + + + + + + + (or - - - %) - + + + %) + diff --git a/account_invoice_fixed_discount/static/description/index.html b/account_invoice_fixed_discount/static/description/index.html index 6359e6828a8..e7e093dfb44 100644 --- a/account_invoice_fixed_discount/static/description/index.html +++ b/account_invoice_fixed_discount/static/description/index.html @@ -3,7 +3,7 @@ -Account Fixed Discount +README.rst -
-

Account Fixed Discount

+
+ + +Odoo Community Association + +
+

Account Fixed Discount

-

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

+

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.

+

If the module account_invoice_triple_discount is installed and a fixed discount is set, it will take priority over anything set in the triple discount fields.

Table of contents

    @@ -388,12 +394,12 @@

    Account Fixed Discount

-

Installation

+

Installation

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

-

Usage

+

Usage

To use this module, you need to:

  1. Go to Settings and Activate the developer mode
  2. @@ -402,7 +408,7 @@

    Usage

-

Bug Tracker

+

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 @@ -410,15 +416,15 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • ForgeFlow
-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -441,5 +447,6 @@

Maintainers

+
diff --git a/account_invoice_fixed_discount/tests/test_account_fixed_discount.py b/account_invoice_fixed_discount/tests/test_account_fixed_discount.py index 49c813a50ed..8aabf30fa9f 100644 --- a/account_invoice_fixed_discount/tests/test_account_fixed_discount.py +++ b/account_invoice_fixed_discount/tests/test_account_fixed_discount.py @@ -100,8 +100,8 @@ def test_01_discounts_fixed_single_unit(self): # Force the fixed discount as the onchange does not # handle the context properly line.discount_fixed = 0.0 - line.discount = 20.0 + self.invoice.invoice_line_ids[0].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) diff --git a/account_invoice_fixed_triple_discount/README.rst b/account_invoice_fixed_triple_discount/README.rst new file mode 100644 index 00000000000..4ff97badeba --- /dev/null +++ b/account_invoice_fixed_triple_discount/README.rst @@ -0,0 +1,76 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +============================= +Account Fixed Triple Discount +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:146d6ec09dd55edb8f963aab0c8cca98d2dd89e7340350c6633070022a3e026a + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/16.0/account_invoice_fixed_triple_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-16-0/account-invoicing-16-0-account_invoice_fixed_triple_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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Glue module between `account_invoice_fixed_discount` and `account_invoice_triple_discount`. +When both are used on the same line a warning will appear to alert the user that the fixed discount will take priority and it's recommended to only use one. + +**Table of contents** + +.. contents:: + :local: + +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 +======= + +Contributors +~~~~~~~~~~~~ + +* Ethan Hildick + +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_triple_discount/__init__.py b/account_invoice_fixed_triple_discount/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/account_invoice_fixed_triple_discount/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_invoice_fixed_triple_discount/__manifest__.py b/account_invoice_fixed_triple_discount/__manifest__.py new file mode 100644 index 00000000000..6d3eb83dfce --- /dev/null +++ b/account_invoice_fixed_triple_discount/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2025 Ethan Hildick +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Account Fixed Triple Discount", + "summary": "Compatibility between fixed and triple discount modules", + "version": "16.0.1.0.0", + "category": "Accounting & Finance", + "website": "https://github.com/OCA/account-invoicing", + "author": "Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["account_invoice_fixed_discount", "account_invoice_triple_discount"], + "auto_install": True, + "data": ["views/account_move_view.xml"], +} diff --git a/account_invoice_fixed_triple_discount/i18n/account_invoice_fixed_triple_discount.pot b/account_invoice_fixed_triple_discount/i18n/account_invoice_fixed_triple_discount.pot new file mode 100644 index 00000000000..59985f55213 --- /dev/null +++ b/account_invoice_fixed_triple_discount/i18n/account_invoice_fixed_triple_discount.pot @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_fixed_triple_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-09-24 14:39+0000\n" +"PO-Revision-Date: 2025-09-24 14:39+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_invoice_fixed_triple_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_triple_discount.view_move_form +msgid "" +"At least one line is using a fixed discount and a percentage discount at the same time.\n" +" This is currently not supported and will prioritise the use of the fixed discount.
\n" +" It is recommended you remove one of the discount types to avoid confusion." +msgstr "" + +#. module: account_invoice_fixed_triple_discount +#: model:ir.model,name:account_invoice_fixed_triple_discount.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_invoice_fixed_triple_discount +#: model:ir.model.fields,field_description:account_invoice_fixed_triple_discount.field_account_bank_statement_line__show_discount_warning_label +#: model:ir.model.fields,field_description:account_invoice_fixed_triple_discount.field_account_move__show_discount_warning_label +#: model:ir.model.fields,field_description:account_invoice_fixed_triple_discount.field_account_payment__show_discount_warning_label +msgid "Show Discount Warning Label" +msgstr "" + +#. module: account_invoice_fixed_triple_discount +#: model:ir.model,name:account_invoice_fixed_triple_discount.model_triple_discount_mixin +msgid "Triple discount mixin" +msgstr "" diff --git a/account_invoice_fixed_triple_discount/i18n/es.po b/account_invoice_fixed_triple_discount/i18n/es.po new file mode 100644 index 00000000000..0db469ee376 --- /dev/null +++ b/account_invoice_fixed_triple_discount/i18n/es.po @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_invoice_fixed_triple_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-09-24 14:40+0000\n" +"PO-Revision-Date: 2025-09-24 14:40+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_invoice_fixed_triple_discount +#: model_terms:ir.ui.view,arch_db:account_invoice_fixed_triple_discount.view_move_form +msgid "" +"At least one line is using a fixed discount and a percentage discount at the same time.\n" +" This is currently not supported and will prioritise the use of the fixed discount.
\n" +" It is recommended you remove one of the discount types to avoid confusion." +msgstr "Al menos una línea está utilizando un descuento fijo y un descuento porcentual al mismo tiempo.\n" +" Esto no está actualmente soportado y priorizará el uso del descuento fijo.
\n" +" Se recomienda que elimines uno de los tipos de descuento para evitar confusión." + +#. module: account_invoice_fixed_triple_discount +#: model:ir.model,name:account_invoice_fixed_triple_discount.model_account_move +msgid "Journal Entry" +msgstr "Asiento contable" + +#. module: account_invoice_fixed_triple_discount +#: model:ir.model.fields,field_description:account_invoice_fixed_triple_discount.field_account_bank_statement_line__show_discount_warning_label +#: model:ir.model.fields,field_description:account_invoice_fixed_triple_discount.field_account_move__show_discount_warning_label +#: model:ir.model.fields,field_description:account_invoice_fixed_triple_discount.field_account_payment__show_discount_warning_label +msgid "Show Discount Warning Label" +msgstr "Mostrar aviso de descuentos incompatibles" + +#. module: account_invoice_fixed_triple_discount +#: model:ir.model,name:account_invoice_fixed_triple_discount.model_triple_discount_mixin +msgid "Triple discount mixin" +msgstr "" diff --git a/account_invoice_fixed_triple_discount/models/__init__.py b/account_invoice_fixed_triple_discount/models/__init__.py new file mode 100644 index 00000000000..140ec594d11 --- /dev/null +++ b/account_invoice_fixed_triple_discount/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_move_line +from . import account_move +from . import triple_discount_mixin diff --git a/account_invoice_fixed_triple_discount/models/account_move.py b/account_invoice_fixed_triple_discount/models/account_move.py new file mode 100644 index 00000000000..97bd5cfe521 --- /dev/null +++ b/account_invoice_fixed_triple_discount/models/account_move.py @@ -0,0 +1,26 @@ +# Copyright 2025 Ethan Hildick +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + show_discount_warning_label = fields.Boolean( + compute="_compute_show_discount_warning_label" + ) + + @api.depends( + "invoice_line_ids.discount_fixed", + "invoice_line_ids.discount1", + "invoice_line_ids.discount2", + "invoice_line_ids.discount3", + ) + def _compute_show_discount_warning_label(self): + for move in self: + move.show_discount_warning_label = any( + line.discount_fixed + and (line.discount1 or line.discount2 or line.discount3) + for line in move.invoice_line_ids + ) diff --git a/account_invoice_fixed_triple_discount/models/account_move_line.py b/account_invoice_fixed_triple_discount/models/account_move_line.py new file mode 100644 index 00000000000..697323b1869 --- /dev/null +++ b/account_invoice_fixed_triple_discount/models/account_move_line.py @@ -0,0 +1,30 @@ +# Copyright 2025 Ethan Hildick +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models +from odoo.tools.float_utils import float_is_zero + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + @api.depends("discount_fixed", "price_unit") + def _compute_discount(self): + res = super()._compute_discount() + for line in self: + if not line.discount_fixed: + continue + line.discount = line._get_discount_from_fixed_discount() + return res + + def _get_lines_to_compute_discount(self): + lines = super()._get_lines_to_compute_discount() + return lines.filtered( + lambda line: float_is_zero( + line.discount_fixed, precision_rounding=line.currency_id.rounding + ) + ) + + def _onchange_discount(self): + # kill the onchange as the discount field is now readonly + return diff --git a/account_invoice_fixed_triple_discount/models/triple_discount_mixin.py b/account_invoice_fixed_triple_discount/models/triple_discount_mixin.py new file mode 100644 index 00000000000..c479f2ddbad --- /dev/null +++ b/account_invoice_fixed_triple_discount/models/triple_discount_mixin.py @@ -0,0 +1,23 @@ +# Copyright 2025 Ethan Hildick +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models +from odoo.tools.float_utils import float_is_zero + + +class TripleDiscountMixin(models.AbstractModel): + _inherit = "triple.discount.mixin" + + def _should_copy_discount_to_discount1(self, vals): + res = super()._should_copy_discount_to_discount1(vals) + currency = ( + self.env["res.currency"].browse(vals.get("currency_id")) + or self.env.company.currency_id + ) + return res and not ( + "discount_fixed" in vals + and not float_is_zero( + vals.get("discount_fixed"), + precision_rounding=currency.rounding, + ) + ) diff --git a/account_invoice_fixed_triple_discount/readme/CONTRIBUTORS.rst b/account_invoice_fixed_triple_discount/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..95d6d5c286f --- /dev/null +++ b/account_invoice_fixed_triple_discount/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Ethan Hildick diff --git a/account_invoice_fixed_triple_discount/readme/DESCRIPTION.rst b/account_invoice_fixed_triple_discount/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..a9d23e44a69 --- /dev/null +++ b/account_invoice_fixed_triple_discount/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Glue module between `account_invoice_fixed_discount` and `account_invoice_triple_discount`. +When both are used on the same line a warning will appear to alert the user that the fixed discount will take priority and it's recommended to only use one. diff --git a/account_invoice_fixed_triple_discount/static/description/icon.png b/account_invoice_fixed_triple_discount/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/account_invoice_fixed_triple_discount/static/description/icon.png differ diff --git a/account_invoice_fixed_triple_discount/static/description/index.html b/account_invoice_fixed_triple_discount/static/description/index.html new file mode 100644 index 00000000000..d22004d5b8c --- /dev/null +++ b/account_invoice_fixed_triple_discount/static/description/index.html @@ -0,0 +1,423 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Account Fixed Triple Discount

+ +

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

+

Glue module between account_invoice_fixed_discount and account_invoice_triple_discount. +When both are used on the same line a warning will appear to alert the user that the fixed discount will take priority and it’s recommended to only use one.

+

Table of contents

+ +
+

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

+
+

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_triple_discount/tests/__init__.py b/account_invoice_fixed_triple_discount/tests/__init__.py new file mode 100644 index 00000000000..f15da2000e3 --- /dev/null +++ b/account_invoice_fixed_triple_discount/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_move diff --git a/account_invoice_fixed_triple_discount/tests/test_account_move.py b/account_invoice_fixed_triple_discount/tests/test_account_move.py new file mode 100644 index 00000000000..76ea3612b17 --- /dev/null +++ b/account_invoice_fixed_triple_discount/tests/test_account_move.py @@ -0,0 +1,74 @@ +# Copyright 2025 Ethan Hildick +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import Command +from odoo.tests import TransactionCase +from odoo.tests.common import Form + + +class TestAccountMove(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") + + def _create_invoice(self, **kwargs): + invoice_vals = [ + Command.create( + { + "product_id": self.product.id, + "quantity": 1.0, + "name": "Line 1", + "price_unit": 200.00, + **kwargs, + }, + ) + ] + invoice = ( + self.env["account.move"] + .with_context(check_move_validity=False) + .create( + { + "journal_id": ( + self.env["account.journal"] + .search([("type", "=", "sale")], limit=1) + .id + ), + "partner_id": self.partner.id, + "move_type": "out_invoice", + "invoice_line_ids": invoice_vals, + } + ) + ) + return invoice + + def test_01_show_discount_warning_label(self): + invoice = self._create_invoice(discount_fixed=10.00, discount1=10.00) + self.assertTrue(invoice.show_discount_warning_label) + with Form(invoice) as invoice_form: + with invoice_form.invoice_line_ids.edit(0) as line: + line.discount_fixed = 0.0 + self.assertFalse(invoice.show_discount_warning_label) + + def test_02_get_lines_to_compute_discount(self): + invoice = self._create_invoice(discount1=10.00, discount2=10.00) + self.assertAlmostEqual(invoice.invoice_line_ids[0].discount, 19) + lines = invoice.invoice_line_ids._get_lines_to_compute_discount() + self.assertEqual(lines, invoice.invoice_line_ids) + with Form(invoice) as invoice_form: + with invoice_form.invoice_line_ids.edit(0) as line: + line.discount_fixed = 10.0 + lines = invoice.invoice_line_ids._get_lines_to_compute_discount() + self.assertEqual(lines, invoice.invoice_line_ids - invoice.invoice_line_ids[0]) + + def test_03_should_copy_discount_to_discount1(self): + invoice = self._create_invoice(discount=10.00) + self.assertAlmostEqual(invoice.invoice_line_ids[0].discount, 10) + self.assertAlmostEqual(invoice.invoice_line_ids[0].discount1, 10) + self.assertAlmostEqual(invoice.invoice_line_ids[0].discount_fixed, 0) + invoice_2 = self._create_invoice(discount=10.00, discount_fixed=10.00) + self.assertAlmostEqual(invoice_2.invoice_line_ids[0].discount, 5) # 10€ of 200€ + self.assertAlmostEqual(invoice_2.invoice_line_ids[0].discount1, 0) + self.assertAlmostEqual(invoice_2.invoice_line_ids[0].discount_fixed, 10) diff --git a/account_invoice_fixed_triple_discount/views/account_move_view.xml b/account_invoice_fixed_triple_discount/views/account_move_view.xml new file mode 100644 index 00000000000..898aff9cceb --- /dev/null +++ b/account_invoice_fixed_triple_discount/views/account_move_view.xml @@ -0,0 +1,22 @@ + + + account.move.form + account.move + + + + + + + + + diff --git a/account_invoice_triple_discount/README.rst b/account_invoice_triple_discount/README.rst index 4e5381c7faf..068e3af0798 100644 --- a/account_invoice_triple_discount/README.rst +++ b/account_invoice_triple_discount/README.rst @@ -1,3 +1,7 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + =============================== Account Invoice Triple Discount =============================== @@ -13,7 +17,7 @@ Account Invoice Triple Discount .. |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 +.. |badge2| image:: https://img.shields.io/badge/license-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 @@ -30,6 +34,8 @@ Account Invoice Triple Discount This module allows to have three successive discounts on each invoice line. +If the module `account_invoice_fixed_discount` is installed and a fixed discount is set, it will take priority over anything set in the triple discount fields. + **Table of contents** .. contents:: diff --git a/account_invoice_triple_discount/__manifest__.py b/account_invoice_triple_discount/__manifest__.py index 2aa5f17168f..076aab7a80f 100644 --- a/account_invoice_triple_discount/__manifest__.py +++ b/account_invoice_triple_discount/__manifest__.py @@ -10,7 +10,6 @@ "license": "AGPL-3", "summary": "Manage triple discount on invoice lines", "depends": ["account"], - "excludes": ["account_invoice_fixed_discount"], "post_init_hook": "post_init_hook", "data": ["report/invoice.xml", "views/account_move.xml"], "installable": True, diff --git a/account_invoice_triple_discount/hooks.py b/account_invoice_triple_discount/hooks.py index a27914aa616..312795c477e 100644 --- a/account_invoice_triple_discount/hooks.py +++ b/account_invoice_triple_discount/hooks.py @@ -8,10 +8,19 @@ def post_init_hook(cr, registry): _logger.info("Initializing column discount1 on table account_move_line") - cr.execute( - """ - UPDATE account_move_line - SET discount1 = discount - WHERE discount != 0 - """ - ) + if "discount_fixed" not in registry.models["account.move.line"]._fields: + cr.execute( + """ + UPDATE account_move_line + SET discount1 = discount + WHERE discount != 0 + """ + ) + else: + cr.execute( + """ + UPDATE account_move_line + SET discount1 = discount + WHERE discount != 0 AND discount_fixed = 0 + """ + ) diff --git a/account_invoice_triple_discount/migrations/16.0.2.0.0/pre-migrate.py b/account_invoice_triple_discount/migrations/16.0.2.0.0/pre-migrate.py index 397b6673778..36ec956cbcb 100644 --- a/account_invoice_triple_discount/migrations/16.0.2.0.0/pre-migrate.py +++ b/account_invoice_triple_discount/migrations/16.0.2.0.0/pre-migrate.py @@ -27,19 +27,36 @@ def migrate_discount_to_discount1(env): ) # if discounts are : 10% - 20% - 30% main discount is : 49.6 % # if discounts are : 05% - 09% - 13% main discount is : 24.7885 % - openupgrade.logged_query( - env.cr, - """ - UPDATE account_move_line - SET discount = 100 * ( - 1 - ( - (100 - COALESCE(discount1, 0.0)) / 100 - * (100 - COALESCE(discount2, 0.0)) / 100 - * (100 - COALESCE(discount3, 0.0)) / 100 - ) - ); - """, - ) + if "discount_fixed" not in env.registry.models["account.move.line"]._fields: + openupgrade.logged_query( + env.cr, + """ + UPDATE account_move_line + SET discount = 100 * ( + 1 - ( + (100 - COALESCE(discount1, 0.0)) / 100 + * (100 - COALESCE(discount2, 0.0)) / 100 + * (100 - COALESCE(discount3, 0.0)) / 100 + ) + ); + """, + ) + else: + # don't touch lines with fixed discount + openupgrade.logged_query( + env.cr, + """ + UPDATE account_move_line + SET discount = 100 * ( + 1 - ( + (100 - COALESCE(discount1, 0.0)) / 100 + * (100 - COALESCE(discount2, 0.0)) / 100 + * (100 - COALESCE(discount3, 0.0)) / 100 + ) + ) + WHERE discount_fixed == 0; + """, + ) @openupgrade.migrate() diff --git a/account_invoice_triple_discount/models/triple_discount_mixin.py b/account_invoice_triple_discount/models/triple_discount_mixin.py index 3e76da12da4..93473442031 100644 --- a/account_invoice_triple_discount/models/triple_discount_mixin.py +++ b/account_invoice_triple_discount/models/triple_discount_mixin.py @@ -49,12 +49,19 @@ class TripleDiscountMixin(models.AbstractModel): ), ] + def _get_lines_to_compute_discount(self): + return self + @api.depends(lambda self: self._get_multiple_discount_field_names()) def _compute_discount(self): - for line in self: + res = True + if hasattr(super(), "_compute_discount"): + res = super()._compute_discount() + for line in self._get_lines_to_compute_discount(): line.discount = line._get_aggregated_multiple_discounts( [line[x] for x in line._get_multiple_discount_field_names()] ) + return res def _get_aggregated_multiple_discounts(self, discounts): """ @@ -74,16 +81,29 @@ def _get_aggregated_multiple_discounts(self, discounts): def _get_multiple_discount_field_names(self): return ["discount1", "discount2", "discount3"] + @api.model + def _should_copy_discount_to_discount1(self, vals): + """ + Primarily used to not break the functionality of other modules that write to + the discount field that don't know/care of this modules existence. + """ + return ( + "discount" in vals + and "discount1" not in vals + and "discount2" not in vals + and "discount3" not in vals + ) + @api.model_create_multi def create(self, vals_list): for vals in vals_list: - if "discount" in vals and "discount1" not in vals: + if self._should_copy_discount_to_discount1(vals): vals["discount1"] = vals.pop("discount") return super().create(vals_list) def write(self, vals): discount_fields = self._get_multiple_discount_field_names() - if "discount" in vals: + if self._should_copy_discount_to_discount1(vals): vals["discount1"] = vals.pop("discount") vals.update({field: 0 for field in discount_fields[1:]}) return super().write(vals) diff --git a/account_invoice_triple_discount/readme/DESCRIPTION.rst b/account_invoice_triple_discount/readme/DESCRIPTION.rst index d61e4eee1fd..9f8e61f22df 100644 --- a/account_invoice_triple_discount/readme/DESCRIPTION.rst +++ b/account_invoice_triple_discount/readme/DESCRIPTION.rst @@ -1 +1,3 @@ This module allows to have three successive discounts on each invoice line. + +If the module `account_invoice_fixed_discount` is installed and a fixed discount is set, it will take priority over anything set in the triple discount fields. diff --git a/account_invoice_triple_discount/report/invoice.xml b/account_invoice_triple_discount/report/invoice.xml index b8984c65535..d58eb8fd075 100644 --- a/account_invoice_triple_discount/report/invoice.xml +++ b/account_invoice_triple_discount/report/invoice.xml @@ -6,7 +6,7 @@ priority="100" > - False + False -Account Invoice Triple Discount +README.rst -
-

Account Invoice Triple Discount

+
+ + +Odoo Community Association + +
+

Account Invoice Triple Discount

-

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

+

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

This module allows to have three successive discounts on each invoice line.

+

If the module account_invoice_fixed_discount is installed and a fixed discount is set, it will take priority over anything set in the triple discount fields.

Table of contents

    @@ -385,7 +391,7 @@

    Account Invoice Triple Discount

-

Usage

+

Usage

Create a new invoice and add discounts in any of the three discount fields given. They go in order of precedence so discount 2 will be calculated over discount 1 and discount 3 over the result of discount 2. For example, let’s @@ -408,7 +414,7 @@

Usage

-

Bug Tracker

+

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 @@ -416,9 +422,9 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • QubiQ
  • Tecnativa
  • @@ -426,7 +432,7 @@

    Authors

-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -453,5 +459,6 @@

Maintainers

+
diff --git a/account_invoice_triple_discount/views/account_move.xml b/account_invoice_triple_discount/views/account_move.xml index e0a2908cd7d..0d7106a3994 100644 --- a/account_invoice_triple_discount/views/account_move.xml +++ b/account_invoice_triple_discount/views/account_move.xml @@ -11,6 +11,7 @@ > hide Total discount + 1