diff --git a/sale_commission_product_criteria_sections/README.rst b/sale_commission_product_criteria_sections/README.rst new file mode 100644 index 000000000..d1ed73adf --- /dev/null +++ b/sale_commission_product_criteria_sections/README.rst @@ -0,0 +1,117 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +========================================= +Sale Commission Product Criteria Sections +========================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:633ef64596534a332b6fc3014f7ebc0dd3c79da3db070ed38f744d83d4351a1b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fcommission-lightgray.png?logo=github + :target: https://github.com/OCA/commission/tree/16.0/sale_commission_product_criteria_sections + :alt: OCA/commission +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/commission-16-0/commission-16-0-sale_commission_product_criteria_sections + :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/commission&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends sale_commission_product_criteria to allow configuring +section-based (tiered) commission rates per product criteria rule. + +Each commission item can define its own set of rate sections with amount +ranges and percentages, enabling complex commission structures where +different products have different tiered rates based on the order amount. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Go to Commissions > Configuration > Commission Types + +In a record of type "Product criteria", create or edit a commission item +and set "Compute Price" to "By sections". + +Define the rate tiers by adding lines with: +* **From** - lower bound of the amount range +* **To** - upper bound of the amount range +* **Percent** - commission percentage for this range + +Usage +===== + +When a sale order is confirmed, the commission for each line is calculated +by finding the matching commission item rule for the product. If the rule +uses "By sections", the commission amount is computed by selecting the +rate tier that matches the line subtotal and applying the corresponding +percentage. + +For example, a rule with sections: +* 0 - 100: 5% +* 100 - 500: 8% +* 500+: 10% + +A sale of 200 would grant 200 * 8% = 16 in commission. +A sale of 600 would grant 600 * 10% = 60 in commission. + +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 +~~~~~~~ + +* Madooit + +Contributors +~~~~~~~~~~~~ + +* `Madooit `__: + + * Rodrigo Madureira + +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/commission `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_commission_product_criteria_sections/__init__.py b/sale_commission_product_criteria_sections/__init__.py new file mode 100644 index 000000000..dfbf964a3 --- /dev/null +++ b/sale_commission_product_criteria_sections/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2025 Madooit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/sale_commission_product_criteria_sections/__manifest__.py b/sale_commission_product_criteria_sections/__manifest__.py new file mode 100644 index 000000000..d81222ad6 --- /dev/null +++ b/sale_commission_product_criteria_sections/__manifest__.py @@ -0,0 +1,14 @@ +{ + "name": "Sale Commission Product Criteria Sections", + "version": "16.0.1.0.0", + "author": "Madooit, Odoo Community Association (OCA)", + "maintainer": "rodmad85", + "license": "AGPL-3", + "category": "Sales", + "website": "https://github.com/OCA/commission", + "depends": ["sale_commission_product_criteria"], + "data": [ + "views/commission_views.xml", + ], + "installable": True, +} diff --git a/sale_commission_product_criteria_sections/models/__init__.py b/sale_commission_product_criteria_sections/models/__init__.py new file mode 100644 index 000000000..f5f922876 --- /dev/null +++ b/sale_commission_product_criteria_sections/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2025 Madooit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import commission +from . import sale_commission_line_mixin diff --git a/sale_commission_product_criteria_sections/models/commission.py b/sale_commission_product_criteria_sections/models/commission.py new file mode 100644 index 000000000..5e149a3f2 --- /dev/null +++ b/sale_commission_product_criteria_sections/models/commission.py @@ -0,0 +1,42 @@ +# Copyright 2025 Madooit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, fields, models + + +class CommissionItem(models.Model): + _inherit = "commission.item" + + commission_type = fields.Selection( + selection_add=[("section", _("By sections"))], + ondelete={"section": "set default"}, + ) + section_ids = fields.One2many( + "commission.section", + "commission_item_id", + string="Sections", + copy=True, + ) + + def _compute_commission_item_name_value(self): + res = super()._compute_commission_item_name_value() + for item in self: + if item.commission_type == "section": + item.commission_value = _("By sections") + return res + + def _calculate_section_amount(self, base): + for section in self.section_ids: + if section.amount_from <= base <= section.amount_to: + return base * section.percent / 100.0 + return 0.0 + + +class CommissionSection(models.Model): + _inherit = "commission.section" + + commission_item_id = fields.Many2one( + "commission.item", + string="Commission Item", + ondelete="cascade", + ) diff --git a/sale_commission_product_criteria_sections/models/sale_commission_line_mixin.py b/sale_commission_product_criteria_sections/models/sale_commission_line_mixin.py new file mode 100644 index 000000000..7056f682c --- /dev/null +++ b/sale_commission_product_criteria_sections/models/sale_commission_line_mixin.py @@ -0,0 +1,25 @@ +# Copyright 2025 Madooit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class SaleCommissionLineMixin(models.AbstractModel): + _inherit = "commission.line.mixin" + + def _get_single_commission_amount(self, commission, subtotal, product, quantity): + self.ensure_one() + item_ids = self._get_commission_items(commission, product) + if not item_ids: + return 0.0 + commission_item = self.env["commission.item"].browse(item_ids[0]) + if commission.amount_base_type == "net_amount": + subtotal = max([0, subtotal - product.standard_price * quantity]) + self.applied_commission_item_id = commission_item + self.applied_commission_id = commission_item.commission_id + if commission_item.commission_type == "fixed": + return commission_item.fixed_amount + elif commission_item.commission_type == "percentage": + return subtotal * (commission_item.percent_amount / 100.0) + elif commission_item.commission_type == "section": + return commission_item._calculate_section_amount(subtotal) diff --git a/sale_commission_product_criteria_sections/readme/CONFIGURE.rst b/sale_commission_product_criteria_sections/readme/CONFIGURE.rst new file mode 100644 index 000000000..8b6f9a34d --- /dev/null +++ b/sale_commission_product_criteria_sections/readme/CONFIGURE.rst @@ -0,0 +1,9 @@ +Go to Commissions > Configuration > Commission Types + +In a record of type "Product criteria", create or edit a commission item +and set "Compute Price" to "By sections". + +Define the rate tiers by adding lines with: +* **From** - lower bound of the amount range +* **To** - upper bound of the amount range +* **Percent** - commission percentage for this range diff --git a/sale_commission_product_criteria_sections/readme/CONTRIBUTORS.rst b/sale_commission_product_criteria_sections/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..ddab98859 --- /dev/null +++ b/sale_commission_product_criteria_sections/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Madooit `__: + + * Rodrigo Madureira diff --git a/sale_commission_product_criteria_sections/readme/DESCRIPTION.rst b/sale_commission_product_criteria_sections/readme/DESCRIPTION.rst new file mode 100644 index 000000000..598a86457 --- /dev/null +++ b/sale_commission_product_criteria_sections/readme/DESCRIPTION.rst @@ -0,0 +1,6 @@ +This module extends sale_commission_product_criteria to allow configuring +section-based (tiered) commission rates per product criteria rule. + +Each commission item can define its own set of rate sections with amount +ranges and percentages, enabling complex commission structures where +different products have different tiered rates based on the order amount. diff --git a/sale_commission_product_criteria_sections/readme/USAGE.rst b/sale_commission_product_criteria_sections/readme/USAGE.rst new file mode 100644 index 000000000..ce284a750 --- /dev/null +++ b/sale_commission_product_criteria_sections/readme/USAGE.rst @@ -0,0 +1,13 @@ +When a sale order is confirmed, the commission for each line is calculated +by finding the matching commission item rule for the product. If the rule +uses "By sections", the commission amount is computed by selecting the +rate tier that matches the line subtotal and applying the corresponding +percentage. + +For example, a rule with sections: +* 0 - 100: 5% +* 100 - 500: 8% +* 500+: 10% + +A sale of 200 would grant 200 * 8% = 16 in commission. +A sale of 600 would grant 600 * 10% = 60 in commission. diff --git a/sale_commission_product_criteria_sections/static/description/index.html b/sale_commission_product_criteria_sections/static/description/index.html new file mode 100644 index 000000000..a1999f573 --- /dev/null +++ b/sale_commission_product_criteria_sections/static/description/index.html @@ -0,0 +1,462 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Sale Commission Product Criteria Sections

+ +

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

+

This module extends sale_commission_product_criteria to allow configuring +section-based (tiered) commission rates per product criteria rule.

+

Each commission item can define its own set of rate sections with amount +ranges and percentages, enabling complex commission structures where +different products have different tiered rates based on the order amount.

+

Table of contents

+ +
+

Configuration

+

Go to Commissions > Configuration > Commission Types

+

In a record of type “Product criteria”, create or edit a commission item +and set “Compute Price” to “By sections”.

+

Define the rate tiers by adding lines with: +* From - lower bound of the amount range +* To - upper bound of the amount range +* Percent - commission percentage for this range

+
+
+

Usage

+

When a sale order is confirmed, the commission for each line is calculated +by finding the matching commission item rule for the product. If the rule +uses “By sections”, the commission amount is computed by selecting the +rate tier that matches the line subtotal and applying the corresponding +percentage.

+

For example, a rule with sections: +* 0 - 100: 5% +* 100 - 500: 8% +* 500+: 10%

+

A sale of 200 would grant 200 * 8% = 16 in commission. +A sale of 600 would grant 600 * 10% = 60 in commission.

+
+
+

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

+
    +
  • Madooit
  • +
+
+
+

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

+

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

+
+
+
+
+ + diff --git a/sale_commission_product_criteria_sections/views/commission_views.xml b/sale_commission_product_criteria_sections/views/commission_views.xml new file mode 100644 index 000000000..d26f47387 --- /dev/null +++ b/sale_commission_product_criteria_sections/views/commission_views.xml @@ -0,0 +1,43 @@ + + + + commission.form.product.sections.inherit + commission + + + + + {'invisible': [('commission_type', '!=', 'section')]} + + + + + + + commission.item.form.sections.inherit + commission.item + + + + + + + + + + + + + + diff --git a/setup/sale_commission_product_criteria_sections/odoo/addons/sale_commission_product_criteria_sections b/setup/sale_commission_product_criteria_sections/odoo/addons/sale_commission_product_criteria_sections new file mode 120000 index 000000000..926718909 --- /dev/null +++ b/setup/sale_commission_product_criteria_sections/odoo/addons/sale_commission_product_criteria_sections @@ -0,0 +1 @@ +../../../../sale_commission_product_criteria_sections \ No newline at end of file diff --git a/setup/sale_commission_product_criteria_sections/setup.py b/setup/sale_commission_product_criteria_sections/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/sale_commission_product_criteria_sections/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)