Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions sale_commission_product_criteria_sections/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/commission/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 <https://github.com/OCA/commission/issues/new?body=module:%20sale_commission_product_criteria_sections%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Madooit

Contributors
~~~~~~~~~~~~

* `Madooit <https://github.com/rodmad85>`__:

* Rodrigo Madureira <rodrigo@madooit.com>

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 <https://github.com/OCA/commission/tree/16.0/sale_commission_product_criteria_sections>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions sale_commission_product_criteria_sections/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2025 Madooit
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
14 changes: 14 additions & 0 deletions sale_commission_product_criteria_sections/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
5 changes: 5 additions & 0 deletions sale_commission_product_criteria_sections/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions sale_commission_product_criteria_sections/models/commission.py
Original file line number Diff line number Diff line change
@@ -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",
)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Madooit <https://github.com/rodmad85>`__:

* Rodrigo Madureira <rodrigo@madooit.com>
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions sale_commission_product_criteria_sections/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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.
Loading
Loading