diff --git a/sale_commission_salesman/README.rst b/sale_commission_salesman/README.rst new file mode 100644 index 000000000..a8542653b --- /dev/null +++ b/sale_commission_salesman/README.rst @@ -0,0 +1,122 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +=============================== +Sales commissions from salesman +=============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ba31b1a5050119c8e6c5131c1c014ac4b82839834d368be7b34bd7eedff3f23d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/19.0/sale_commission_salesman + :alt: OCA/commission +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/commission-19-0/commission-19-0-sale_commission_salesman + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of sale_commission to allow you to +auto-populate salesmen as commission agents without setting explicitly +them on the customer. + +**IMPORTANT**: The salesman will be only populated if no other +commission agent is set via other method, to assure that there's no +overlapping commissions. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +1. Go to *Contacts*. +2. Search for the contact linked to the salesman user and open it. +3. If it's actually linked to a user, you'll see a new check in the + *Agent information* page, called "Convert salesman into agent". +4. Check it for having that salesman automatically populated as agent. + You need to assign a commission to that agent as well. + +Usage +===== + +To use this module, you need to: + +1. Go to *Sales > Orders > Quotations* and create a new one. +2. Fill the customer with one with no agents set. +3. Select a salesman with the mark checked. +4. Add a line in the quotation, and you will see the salesman populated + as commission agent. + +Known issues / Roadmap +====================== + +- This module can be split into 2: account_commission_salesman and + sale_commission_salesman. + +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 +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - Pedro M. Baeza + +Other credits +------------- + +- Part of the icon made from Icon Fonts is licensed + by CC BY 3.0 + +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_salesman/__init__.py b/sale_commission_salesman/__init__.py new file mode 100644 index 000000000..31660d6a9 --- /dev/null +++ b/sale_commission_salesman/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/sale_commission_salesman/__manifest__.py b/sale_commission_salesman/__manifest__.py new file mode 100644 index 000000000..c7177361d --- /dev/null +++ b/sale_commission_salesman/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2020 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Sales commissions from salesman", + "version": "19.0.1.0.0", + "author": "Tecnativa, Odoo Community Association (OCA)", + "category": "Sales", + "website": "https://github.com/OCA/commission", + "license": "AGPL-3", + "depends": ["sale_commission_oca"], + "data": ["views/res_partner_views.xml"], + "installable": True, +} diff --git a/sale_commission_salesman/i18n/ca.po b/sale_commission_salesman/i18n/ca.po new file mode 100644 index 000000000..86668a8ff --- /dev/null +++ b/sale_commission_salesman/i18n/ca.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_commission_salesman +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-06-04 10:48+0000\n" +"Last-Translator: jabelchi \n" +"Language-Team: none\n" +"Language: ca\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.3.2\n" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_res_partner +msgid "Contact" +msgstr "Contacte" + +#. module: sale_commission_salesman +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "Convert salesman into agent" +msgstr "Convertir venedor en agent" + +#. module: sale_commission_salesman +#: model:ir.model.fields,help:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,help:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "" +"If the user linked to this partner is put as salesman and no other " +"commission rule is triggered, this agent will be added as the commission " +"agent" +msgstr "" +"Si l'usuari enllaçat a aquest contacte es posa com a comercial i no s'activa " +"cap altra regla de comissions, aquest agent s'afegirà com a comissionista" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_account_move_line +msgid "Journal Item" +msgstr "Apunt comptable" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_sale_order_line +msgid "Sales Order Line" +msgstr "Línia de comanda de venda" + +#. module: sale_commission_salesman +#. odoo-python +#: code:addons/sale_commission_salesman/models/res_partner.py:0 +#, python-format +msgid "You can't have a salesman auto-agent without commission." +msgstr "No podeu tenir un comercial auto-agent sense comissió." diff --git a/sale_commission_salesman/i18n/es.po b/sale_commission_salesman/i18n/es.po new file mode 100644 index 000000000..edfa087b5 --- /dev/null +++ b/sale_commission_salesman/i18n/es.po @@ -0,0 +1,60 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_commission_salesman +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-06-12 14:51+0000\n" +"PO-Revision-Date: 2021-03-17 15:45+0000\n" +"Last-Translator: Ana Suárez \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: sale_commission_salesman +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "Convert salesman into agent" +msgstr "Convertir comercial a agente" + +#. module: sale_commission_salesman +#: model:ir.model.fields,help:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,help:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "" +"If the user linked to this partner is put as salesman and no other " +"commission rule is triggered, this agent will be added as the commission " +"agent" +msgstr "" +"Si el usuario enlazado con este contacto se coloca como comercial y no hay " +"otra regla de comisión, este agente se añadirá como comisionista" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_account_move_line +msgid "Journal Item" +msgstr "Apunte contable" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_sale_order_line +msgid "Sales Order Line" +msgstr "Línea de pedido de ventas" + +#. module: sale_commission_salesman +#. odoo-python +#: code:addons/sale_commission_salesman/models/res_partner.py:0 +#, python-format +msgid "You can't have a salesman auto-agent without commission." +msgstr "No puede tener un comercial auto-agente sin comisión definida." + +#~ msgid "Invoice Line" +#~ msgstr "Linea de la Factura" diff --git a/sale_commission_salesman/i18n/es_AR.po b/sale_commission_salesman/i18n/es_AR.po new file mode 100644 index 000000000..1ee1711a5 --- /dev/null +++ b/sale_commission_salesman/i18n/es_AR.po @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_commission_salesman +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-10-05 20:16+0000\n" +"Last-Translator: Ignacio Buioli \n" +"Language-Team: none\n" +"Language: es_AR\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 3.10\n" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: sale_commission_salesman +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "Convert salesman into agent" +msgstr "Convertir vendedor en agente" + +#. module: sale_commission_salesman +#: model:ir.model.fields,help:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,help:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "" +"If the user linked to this partner is put as salesman and no other " +"commission rule is triggered, this agent will be added as the commission " +"agent" +msgstr "" +"Si el usuario vinculado a este socio se pone como vendedor y no se activa " +"ninguna otra regla de comisión, este agente se agregará como el agente de " +"comisión" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_account_move_line +msgid "Journal Item" +msgstr "Apunte contable" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_sale_order_line +msgid "Sales Order Line" +msgstr "Línea de Orden de Ventas" + +#. module: sale_commission_salesman +#. odoo-python +#: code:addons/sale_commission_salesman/models/res_partner.py:0 +#, python-format +msgid "You can't have a salesman auto-agent without commission." +msgstr "No puede tener un agente automático de ventas sin comisión." diff --git a/sale_commission_salesman/i18n/it.po b/sale_commission_salesman/i18n/it.po new file mode 100644 index 000000000..77221d901 --- /dev/null +++ b/sale_commission_salesman/i18n/it.po @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_commission_salesman +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-01-20 11:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\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 5.6.2\n" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_res_partner +msgid "Contact" +msgstr "Contatto" + +#. module: sale_commission_salesman +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "Convert salesman into agent" +msgstr "Converti addetto alle vendite in agente" + +#. module: sale_commission_salesman +#: model:ir.model.fields,help:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,help:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "" +"If the user linked to this partner is put as salesman and no other " +"commission rule is triggered, this agent will be added as the commission " +"agent" +msgstr "" +"Se l'utente collegato a questo partner è inserito come venditore e non " +"vengono attivare altre regole di provvigione, questo agente verrà aggiunto " +"come agente della provvigione" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_account_move_line +msgid "Journal Item" +msgstr "Movimento contabile" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_sale_order_line +msgid "Sales Order Line" +msgstr "Riga ordine di vendita" + +#. module: sale_commission_salesman +#. odoo-python +#: code:addons/sale_commission_salesman/models/res_partner.py:0 +#, python-format +msgid "You can't have a salesman auto-agent without commission." +msgstr "Non si può avere un venditore auto-agente senza provvigione." diff --git a/sale_commission_salesman/i18n/pt_BR.po b/sale_commission_salesman/i18n/pt_BR.po new file mode 100644 index 000000000..3ce3280f8 --- /dev/null +++ b/sale_commission_salesman/i18n/pt_BR.po @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_commission_salesman +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-10-30 00:46+0000\n" +"Last-Translator: Adriano Prado \n" +"Language-Team: none\n" +"Language: pt_BR\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_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_res_partner +msgid "Contact" +msgstr "Contato" + +#. module: sale_commission_salesman +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "Convert salesman into agent" +msgstr "Transforme vendedor em representante" + +#. module: sale_commission_salesman +#: model:ir.model.fields,help:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,help:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "" +"If the user linked to this partner is put as salesman and no other " +"commission rule is triggered, this agent will be added as the commission " +"agent" +msgstr "" +"Caso o usuário vinculado a este parceiro seja colocado como vendedor e " +"nenhuma outra regra de comissão seja acionada, este representante será " +"adicionado como representante comissionado" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_account_move_line +msgid "Journal Item" +msgstr "Item Diário" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_sale_order_line +msgid "Sales Order Line" +msgstr "Item do pedido de vendas" + +#. module: sale_commission_salesman +#. odoo-python +#: code:addons/sale_commission_salesman/models/res_partner.py:0 +#, python-format +msgid "You can't have a salesman auto-agent without commission." +msgstr "Você não pode ter um vendedor representante sem comissão." diff --git a/sale_commission_salesman/i18n/sale_commission_salesman.pot b/sale_commission_salesman/i18n/sale_commission_salesman.pot new file mode 100644 index 000000000..18773c1ef --- /dev/null +++ b/sale_commission_salesman/i18n/sale_commission_salesman.pot @@ -0,0 +1,50 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_commission_salesman +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.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_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_res_partner +msgid "Contact" +msgstr "" + +#. module: sale_commission_salesman +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "Convert salesman into agent" +msgstr "" + +#. module: sale_commission_salesman +#: model:ir.model.fields,help:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,help:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "" +"If the user linked to this partner is put as salesman and no other " +"commission rule is triggered, this agent will be added as the commission " +"agent" +msgstr "" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_sale_order_line +msgid "Sales Order Line" +msgstr "" + +#. module: sale_commission_salesman +#. odoo-python +#: code:addons/sale_commission_salesman/models/res_partner.py:0 +msgid "You can't have a salesman auto-agent without commission." +msgstr "" diff --git a/sale_commission_salesman/i18n/tr.po b/sale_commission_salesman/i18n/tr.po new file mode 100644 index 000000000..f13e18eae --- /dev/null +++ b/sale_commission_salesman/i18n/tr.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_commission_salesman +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-08-26 11:06+0000\n" +"Last-Translator: Metin GÜLSOY \n" +"Language-Team: none\n" +"Language: tr\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 5.6.2\n" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_res_partner +msgid "Contact" +msgstr "Kontak" + +#. module: sale_commission_salesman +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,field_description:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "Convert salesman into agent" +msgstr "Satıcıyı temsilciye çevirin" + +#. module: sale_commission_salesman +#: model:ir.model.fields,help:sale_commission_salesman.field_res_partner__salesman_as_agent +#: model:ir.model.fields,help:sale_commission_salesman.field_res_users__salesman_as_agent +msgid "" +"If the user linked to this partner is put as salesman and no other " +"commission rule is triggered, this agent will be added as the commission " +"agent" +msgstr "" +"Bu ortağa bağlı kullanıcı satıcı olarak belirlenmişse ve başka bir komisyon\n" +"kuralı tetiklenmemişse, bu temsilci komisyon temsilcisi olarak eklenecektir" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_account_move_line +msgid "Journal Item" +msgstr "Yevmiye Öğesi" + +#. module: sale_commission_salesman +#: model:ir.model,name:sale_commission_salesman.model_sale_order_line +msgid "Sales Order Line" +msgstr "Satış Sipariş Satırı" + +#. module: sale_commission_salesman +#. odoo-python +#: code:addons/sale_commission_salesman/models/res_partner.py:0 +#, python-format +msgid "You can't have a salesman auto-agent without commission." +msgstr "" diff --git a/sale_commission_salesman/models/__init__.py b/sale_commission_salesman/models/__init__.py new file mode 100644 index 000000000..50fe8eac5 --- /dev/null +++ b/sale_commission_salesman/models/__init__.py @@ -0,0 +1,5 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import account_move +from . import res_partner +from . import sale_order diff --git a/sale_commission_salesman/models/account_move.py b/sale_commission_salesman/models/account_move.py new file mode 100644 index 000000000..0e90dedeb --- /dev/null +++ b/sale_commission_salesman/models/account_move.py @@ -0,0 +1,24 @@ +# Copyright 2020 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + def _compute_agent_ids(self): + """Add salesman agent if configured so and no other commission + already populated. + """ + result = super()._compute_agent_ids() + for record in self.filtered( + lambda x: x.move_id.partner_id + and x.move_id.move_type[:3] == "out" + and x.product_id + and not x.agent_ids + ): + partner = record.move_id.invoice_user_id.partner_id + if partner.agent and partner.salesman_as_agent: + record.agent_ids = [(0, 0, record._prepare_agent_vals(partner))] + return result diff --git a/sale_commission_salesman/models/res_partner.py b/sale_commission_salesman/models/res_partner.py new file mode 100644 index 000000000..312dda0a3 --- /dev/null +++ b/sale_commission_salesman/models/res_partner.py @@ -0,0 +1,25 @@ +# Copyright 2020 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, exceptions, fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + salesman_as_agent = fields.Boolean( + string="Convert salesman into agent", + help="If the user linked to this partner is put as salesman and no " + "other commission rule is triggered, this agent will be " + "added as the commission agent", + ) + + @api.constrains("salesman_as_agent", "commission_id") + def _check_salesman_as_agent(self): + for record in self: + if record.salesman_as_agent and not record.commission_id: + raise exceptions.ValidationError( + self.env._( + "You can't have a salesman auto-agent without commission." + ) + ) diff --git a/sale_commission_salesman/models/sale_order.py b/sale_commission_salesman/models/sale_order.py new file mode 100644 index 000000000..822df325e --- /dev/null +++ b/sale_commission_salesman/models/sale_order.py @@ -0,0 +1,19 @@ +# Copyright 2020 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class SaleOrdeLine(models.Model): + _inherit = "sale.order.line" + + def _compute_agent_ids(self): + """Add salesman agent if configured so and no other commission + already populated. + """ + result = super()._compute_agent_ids() + for record in self.filtered(lambda x: x.order_id.partner_id): + partner = record.order_id.user_id.partner_id + if not record.agent_ids and partner.agent and partner.salesman_as_agent: + record.agent_ids = [(0, 0, record._prepare_agent_vals(partner))] + return result diff --git a/sale_commission_salesman/pyproject.toml b/sale_commission_salesman/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/sale_commission_salesman/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_commission_salesman/readme/CONFIGURE.md b/sale_commission_salesman/readme/CONFIGURE.md new file mode 100644 index 000000000..dea0eef47 --- /dev/null +++ b/sale_commission_salesman/readme/CONFIGURE.md @@ -0,0 +1,6 @@ +1. Go to *Contacts*. +2. Search for the contact linked to the salesman user and open it. +3. If it's actually linked to a user, you'll see a new check in the + *Agent information* page, called "Convert salesman into agent". +4. Check it for having that salesman automatically populated as agent. + You need to assign a commission to that agent as well. diff --git a/sale_commission_salesman/readme/CONTRIBUTORS.md b/sale_commission_salesman/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..9f68fe41c --- /dev/null +++ b/sale_commission_salesman/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Tecnativa](https://www.tecnativa.com): + - Pedro M. Baeza diff --git a/sale_commission_salesman/readme/CREDITS.md b/sale_commission_salesman/readme/CREDITS.md new file mode 100644 index 000000000..ff8b73024 --- /dev/null +++ b/sale_commission_salesman/readme/CREDITS.md @@ -0,0 +1,3 @@ +- Part of the icon made from \Icon Fonts\ is + licensed by CC BY 3.0 diff --git a/sale_commission_salesman/readme/DESCRIPTION.md b/sale_commission_salesman/readme/DESCRIPTION.md new file mode 100644 index 000000000..ce8d938a9 --- /dev/null +++ b/sale_commission_salesman/readme/DESCRIPTION.md @@ -0,0 +1,7 @@ +This module extends the functionality of sale_commission to allow you to +auto-populate salesmen as commission agents without setting explicitly +them on the customer. + +**IMPORTANT**: The salesman will be only populated if no other +commission agent is set via other method, to assure that there's no +overlapping commissions. diff --git a/sale_commission_salesman/readme/ROADMAP.md b/sale_commission_salesman/readme/ROADMAP.md new file mode 100644 index 000000000..aae31fa73 --- /dev/null +++ b/sale_commission_salesman/readme/ROADMAP.md @@ -0,0 +1,2 @@ +- This module can be split into 2: account_commission_salesman and + sale_commission_salesman. diff --git a/sale_commission_salesman/readme/USAGE.md b/sale_commission_salesman/readme/USAGE.md new file mode 100644 index 000000000..1c5bb9f07 --- /dev/null +++ b/sale_commission_salesman/readme/USAGE.md @@ -0,0 +1,7 @@ +To use this module, you need to: + +1. Go to *Sales \> Orders \> Quotations* and create a new one. +2. Fill the customer with one with no agents set. +3. Select a salesman with the mark checked. +4. Add a line in the quotation, and you will see the salesman populated + as commission agent. diff --git a/sale_commission_salesman/static/description/icon.png b/sale_commission_salesman/static/description/icon.png new file mode 100644 index 000000000..5135a9130 Binary files /dev/null and b/sale_commission_salesman/static/description/icon.png differ diff --git a/sale_commission_salesman/static/description/icon.svg b/sale_commission_salesman/static/description/icon.svg new file mode 100644 index 000000000..3cd27c8bc --- /dev/null +++ b/sale_commission_salesman/static/description/icon.svg @@ -0,0 +1,106 @@ + + diff --git a/sale_commission_salesman/static/description/index.html b/sale_commission_salesman/static/description/index.html new file mode 100644 index 000000000..b149ab022 --- /dev/null +++ b/sale_commission_salesman/static/description/index.html @@ -0,0 +1,478 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Sales commissions from salesman

+ +

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

+

This module extends the functionality of sale_commission to allow you to +auto-populate salesmen as commission agents without setting explicitly +them on the customer.

+

IMPORTANT: The salesman will be only populated if no other +commission agent is set via other method, to assure that there’s no +overlapping commissions.

+

Table of contents

+ +
+

Configuration

+
    +
  1. Go to Contacts.
  2. +
  3. Search for the contact linked to the salesman user and open it.
  4. +
  5. If it’s actually linked to a user, you’ll see a new check in the +Agent information page, called “Convert salesman into agent”.
  6. +
  7. Check it for having that salesman automatically populated as agent. +You need to assign a commission to that agent as well.
  8. +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Sales > Orders > Quotations and create a new one.
  2. +
  3. Fill the customer with one with no agents set.
  4. +
  5. Select a salesman with the mark checked.
  6. +
  7. Add a line in the quotation, and you will see the salesman populated +as commission agent.
  8. +
+
+
+

Known issues / Roadmap

+
    +
  • This module can be split into 2: account_commission_salesman and +sale_commission_salesman.
  • +
+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+ +
+
+

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_salesman/tests/__init__.py b/sale_commission_salesman/tests/__init__.py new file mode 100644 index 000000000..673e9d887 --- /dev/null +++ b/sale_commission_salesman/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_sale_commission_salesman diff --git a/sale_commission_salesman/tests/test_sale_commission_salesman.py b/sale_commission_salesman/tests/test_sale_commission_salesman.py new file mode 100644 index 000000000..99038789a --- /dev/null +++ b/sale_commission_salesman/tests/test_sale_commission_salesman.py @@ -0,0 +1,90 @@ +# Copyright 2020 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import exceptions +from odoo.tests import Form + +from odoo.addons.base.tests.common import BaseCommon + + +class TestSaleCommissionSalesman(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product = cls.env["product.product"].create( + {"name": "Test Product 1", "list_price": 100} + ) + SaleCommission = cls.env["commission"] + cls.commission_1 = SaleCommission.create( + {"name": "1% commission", "fix_qty": 1.0} + ) + Partner = cls.env["res.partner"] + cls.salesman = cls.env["res.users"].create( + {"name": "Test agent", "login": "sale_comission_salesman_test"} + ) + cls.agent = cls.salesman.partner_id + cls.agent.write( + { + "agent": True, + "salesman_as_agent": True, + "commission_id": cls.commission_1.id, + } + ) + cls.other_agent = Partner.create( + { + "name": "Test other agent", + "agent": True, + "commission_id": cls.commission_1.id, + } + ) + cls.partner = Partner.create({"name": "Partner test"}) + cls.sale_order = cls.env["sale.order"].create( + {"partner_id": cls.partner.id, "user_id": cls.salesman.id} + ) + cls.invoice = cls.env["account.move"].create( + { + "partner_id": cls.partner.id, + "invoice_user_id": cls.salesman.id, + "move_type": "out_invoice", + } + ) + + def test_check_salesman_commission(self): + with self.assertRaises(exceptions.ValidationError): + self.agent.commission_id = False + + def test_sale_commission_salesman(self): + line = self.env["sale.order.line"].create( + {"order_id": self.sale_order.id, "product_id": self.product.id} + ) + self.assertTrue(line.agent_ids) + self.assertTrue(line.agent_ids.agent_id, self.agent) + self.assertTrue(line.agent_ids.commission_id, self.commission_1) + + def test_sale_commission_salesman_no_population(self): + self.partner.commission_agent_ids = [(4, self.other_agent.id)] + line = self.env["sale.order.line"].create( + {"order_id": self.sale_order.id, "product_id": self.product.id} + ) + self.assertTrue(len(line.agent_ids), 1) + self.assertTrue(line.agent_ids.agent_id, self.other_agent) + + def test_invoice_commission_salesman(self): + invoice_form = Form(self.invoice) + with invoice_form.invoice_line_ids.new() as line_form: + line_form.product_id = self.product + invoice_form.save() + line = self.invoice.invoice_line_ids + self.assertTrue(line.agent_ids) + self.assertTrue(line.agent_ids.agent_id, self.agent) + self.assertTrue(line.agent_ids.commission_id, self.commission_1) + + def test_invoice_commission_salesman_no_population(self): + self.partner.commission_agent_ids = [(4, self.other_agent.id)] + invoice_form = Form(self.invoice) + with invoice_form.invoice_line_ids.new() as line_form: + line_form.product_id = self.product + invoice_form.save() + line = self.invoice.invoice_line_ids + self.assertTrue(line.agent_ids) + self.assertTrue(line.agent_ids.agent_id, self.other_agent) diff --git a/sale_commission_salesman/views/res_partner_views.xml b/sale_commission_salesman/views/res_partner_views.xml new file mode 100644 index 000000000..42267c53d --- /dev/null +++ b/sale_commission_salesman/views/res_partner_views.xml @@ -0,0 +1,14 @@ + + + + + res.partner + + + + + + + +