-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by pedrobaeza
- Loading branch information
Showing
19 changed files
with
1,014 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
================================== | ||
Sales commissions based on product | ||
================================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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%2Fcommission-lightgray.png?logo=github | ||
:target: https://github.com/OCA/commission/tree/12.0/sale_commission_product_based | ||
:alt: OCA/commission | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/commission-12-0/commission-12-0-sale_commission_product_based | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/165/12.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows to have commissions based on a product or a product category. | ||
|
||
In the commission, it will be possible to configure a set of rules that refer to a product or a product category, and a fallback percentage. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
In order to create a commission based on products, set "Commission type" to "Based on Product with Fallback Percentage". | ||
|
||
Configure then the "Product rules" and the "Fallback Percentage" as desired. | ||
|
||
Each rule is evaluated based on its sequence. | ||
|
||
A rule is matched when the product involved is the product of the rule, or has the rule's category. | ||
|
||
The commission percentage is the "Percentage" of the matching rule, if any, or the "Fallback Percentage". | ||
|
||
Usage | ||
===== | ||
|
||
1. Create a commission having "Commission type" set to "Based on Product with Fallback Percentage", see `Configuration` for further details. | ||
2. Create a sale order using that commission, see the module "Sales commissions" for the instructions on how to do that | ||
|
||
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 smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/commission/issues/new?body=module:%20sale_commission_product_based%0Aversion:%2012.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 | ||
~~~~~~~ | ||
|
||
* TAKOBI | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `TAKOBI <https://takobi.online>`_: | ||
|
||
* Simone Rubino <[email protected]> | ||
|
||
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/12.0/sale_commission_product_based>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2022 Simone Rubino - TAKOBI | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
'name': "Sales commissions based on product", | ||
'summary': "Create commissions based on product", | ||
'author': "TAKOBI, Odoo Community Association (OCA)", | ||
'website': "https://github.com/OCA/commission", | ||
'license': "AGPL-3", | ||
'category': 'Sales', | ||
'version': '12.0.1.0.0', | ||
'depends': [ | ||
'sale_commission', | ||
], | ||
'data': [ | ||
'security/ir.model.access.csv', | ||
'views/sale_commission_views.xml', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * sale_commission_product_based | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 12.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2022-08-03 14:01+0000\n" | ||
"PO-Revision-Date: 2022-08-03 14:01+0000\n" | ||
"Last-Translator: Simone Rubino <[email protected]>\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_commission_product_based | ||
#: selection:sale.commission,commission_type:0 | ||
msgid "Based on Product with Fallback Percentage" | ||
msgstr "Percentuale basata su prodotto con alternativa" | ||
|
||
#. module: sale_commission_product_based | ||
#: selection:sale.commission,commission_type:0 | ||
msgid "By sections" | ||
msgstr "Per Sezioni" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission_product_rule__commission_id | ||
msgid "Commission" | ||
msgstr "Provvigione" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model,name:sale_commission_product_based.model_sale_commission | ||
msgid "Commission in sales" | ||
msgstr "Provvigione in vendite" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model,name:sale_commission_product_based.model_sale_commission_product_rule | ||
msgid "Commission rule for product" | ||
msgstr "Regola per commissioni di prodotto" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission_product_rule__create_uid | ||
msgid "Created by" | ||
msgstr "Creato da" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission_product_rule__create_date | ||
msgid "Created on" | ||
msgstr "Creato il" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission_product_rule__display_name | ||
msgid "Display Name" | ||
msgstr "Nome visualizzato" | ||
|
||
#. module: sale_commission_product_based | ||
#: sql_constraint:sale.commission.product_rule:0 | ||
msgid "Exactly one of 'Product' and 'Product Category' must have a value." | ||
msgstr "Esattamente uno tra 'Prodotto' e 'Categoria prodotto' deve avere un valore." | ||
|
||
#. module: sale_commission_product_based | ||
#: model_terms:ir.ui.view,arch_db:sale_commission_product_based.sale_commission_form | ||
msgid "Fallback Percentage" | ||
msgstr "Percentuale alternativa" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission__product_fallback_amount | ||
msgid "Fallback Percentage for Product" | ||
msgstr "Percentuale alternativa per prodotto" | ||
|
||
#. module: sale_commission_product_based | ||
#: selection:sale.commission,commission_type:0 | ||
msgid "Fixed percentage" | ||
msgstr "Percentuale Fissa" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission_product_rule__id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission_product_rule____last_update | ||
msgid "Last Modified on" | ||
msgstr "Ultima modifica il" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission_product_rule__write_uid | ||
msgid "Last Updated by" | ||
msgstr "Ultimo aggiornamento di" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission_product_rule__write_date | ||
msgid "Last Updated on" | ||
msgstr "Ultimo aggiornamento il" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model,name:sale_commission_product_based.model_sale_commission_line_mixin | ||
msgid "Mixin model for having commission agent lines in any object inheriting from this one" | ||
msgstr "Modello Mixin per avere righe di commissione per agenti in qualsiasi oggetto che erediti da questo" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission_product_rule__amount | ||
msgid "Percentage" | ||
msgstr "Percentuale" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission_product_rule__product_id | ||
msgid "Product" | ||
msgstr "Prodotto" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission_product_rule__product_category_id | ||
msgid "Product Category" | ||
msgstr "Categoria prodotto" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission__product_rule_ids | ||
msgid "Product rules" | ||
msgstr "Regole prodotto" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission_product_rule__sequence | ||
msgid "Sequence" | ||
msgstr "Sequenza" | ||
|
||
#. module: sale_commission_product_based | ||
#: model:ir.model.fields,field_description:sale_commission_product_based.field_sale_commission__commission_type | ||
msgid "Type" | ||
msgstr "Tipologia" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from . import product_rule | ||
from . import sale_commission | ||
from . import sale_commission_line_mixin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright 2022 Simone Rubino - TAKOBI | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class ProductRule (models.Model): | ||
_name = 'sale.commission.product_rule' | ||
_description = "Commission rule for product" | ||
_order = 'sequence' | ||
|
||
sequence = fields.Integer() | ||
product_category_id = fields.Many2one( | ||
comodel_name='product.category', | ||
) | ||
product_id = fields.Many2one( | ||
comodel_name='product.product', | ||
) | ||
commission_id = fields.Many2one( | ||
comodel_name='sale.commission', | ||
required=True, | ||
ondelete='cascade', | ||
) | ||
amount = fields.Float( | ||
string="Percentage", | ||
) | ||
|
||
_sql_constraints = [ | ||
( | ||
'check_product_xor_category', | ||
""" | ||
CHECK( | ||
(product_id IS NOT NULL AND product_category_id IS NULL) | ||
OR | ||
(product_id IS NULL AND product_category_id IS NOT NULL) | ||
) | ||
""", | ||
"Exactly one of 'Product' " | ||
"and 'Product Category' must have a value."), | ||
] | ||
|
||
@api.multi | ||
def match_product(self, product): | ||
""" | ||
Find which rule in self is a match for `product`. | ||
Rules are evaluated based on their `sequence`. | ||
A rule is a match for a product when the product is | ||
either the rule's product | ||
or has the rule's category. | ||
""" | ||
for rule in self: | ||
if product == rule.product_id \ | ||
or product.categ_id == rule.product_category_id: | ||
break | ||
else: | ||
rule = self.browse() | ||
return rule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2022 Simone Rubino - TAKOBI | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class SaleCommission (models.Model): | ||
_inherit = 'sale.commission' | ||
|
||
commission_type = fields.Selection( | ||
selection_add=[ | ||
("product_fallback", "Based on Product with Fallback Percentage"), | ||
], | ||
) | ||
product_fallback_amount = fields.Float( | ||
string="Fallback Percentage for Product", | ||
) | ||
product_rule_ids = fields.One2many( | ||
comodel_name='sale.commission.product_rule', | ||
inverse_name='commission_id', | ||
string="Product rules", | ||
) | ||
|
||
def calculate_product_fallback(self, base, product): | ||
""" | ||
Calculate amount for type 'Fixed and Based on Product Percentage'. | ||
""" | ||
self.ensure_one() | ||
|
||
product_rules = self.product_rule_ids | ||
rule_match = product_rules.match_product(product) | ||
if rule_match: | ||
amount = rule_match.amount | ||
else: | ||
amount = self.product_fallback_amount | ||
|
||
return base * amount / 100.0 |
17 changes: 17 additions & 0 deletions
17
sale_commission_product_based/models/sale_commission_line_mixin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2022 Simone Rubino - TAKOBI | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class SaleCommissionLineMixin (models.AbstractModel): | ||
_inherit = 'sale.commission.line.mixin' | ||
|
||
def _get_commission_amount(self, commission, subtotal, product, quantity): | ||
self.ensure_one() | ||
if not product.commission_free \ | ||
and commission.commission_type == 'product_fallback': | ||
return commission.calculate_product_fallback(subtotal, product) | ||
return super()._get_commission_amount( | ||
commission, subtotal, product, quantity, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
In order to create a commission based on products, set "Commission type" to "Based on Product with Fallback Percentage". | ||
|
||
Configure then the "Product rules" and the "Fallback Percentage" as desired. | ||
|
||
Each rule is evaluated based on its sequence. | ||
|
||
A rule is matched when the product involved is the product of the rule, or has the rule's category. | ||
|
||
The commission percentage is the "Percentage" of the matching rule, if any, or the "Fallback Percentage". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* `TAKOBI <https://takobi.online>`_: | ||
|
||
* Simone Rubino <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This module allows to have commissions based on a product or a product category. | ||
|
||
In the commission, it will be possible to configure a set of rules that refer to a product or a product category, and a fallback percentage. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1. Create a commission having "Commission type" set to "Based on Product with Fallback Percentage", see `Configuration` for further details. | ||
2. Create a sale order using that commission, see the module "Sales commissions" for the instructions on how to do that |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_product_commission_rule_manager,Manager access to product commission rule,model_sale_commission_product_rule,sales_team.group_sale_manager,1,1,1,1 | ||
access_product_commission_rule_salesman,Salesman access to product commission rule,model_sale_commission_product_rule,sales_team.group_sale_salesman,1,0,0,0 | ||
access_product_commission_rule_user,User access to product commission rule,model_sale_commission_product_rule,base.group_user,1,0,0,0 |
Oops, something went wrong.