diff --git a/commission_delegated_partner/README.rst b/commission_delegated_partner/README.rst new file mode 100644 index 000000000..a1a603086 --- /dev/null +++ b/commission_delegated_partner/README.rst @@ -0,0 +1,89 @@ +================================ +Sale Commission Delegate Partner +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e40b02994d55831663c6b7cf7bedd9d18479d7ed07ecb9f782a1cbc3ebbf45cf + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/17.0/commission_delegated_partner + :alt: OCA/commission +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/commission-17-0/commission-17-0-commission_delegated_partner + :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=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Allows to delegate the invoice from the agent to a related partner + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +For adding delegated partner: + +1. Go to Sales > Commission Management > Agents. +2. Edit or create new record. +3. Go to the page Agent information. +4. Select or edit delegated agent. + +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 +------- + +* Creu Blanca + +Contributors +------------ + +- Enric Tobella +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +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/commission_delegated_partner/__init__.py b/commission_delegated_partner/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/commission_delegated_partner/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/commission_delegated_partner/__manifest__.py b/commission_delegated_partner/__manifest__.py new file mode 100644 index 000000000..57ebe1f5c --- /dev/null +++ b/commission_delegated_partner/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2021 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Sale Commission Delegate Partner", + "summary": """ + Allow to delegate the invoices of agent to a delegate partner""", + "version": "17.0.1.0.0", + "license": "AGPL-3", + "author": "Creu Blanca,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/commission", + "depends": ["account_commission"], + "data": ["views/res_partner.xml"], + "demo": [], +} diff --git a/commission_delegated_partner/i18n/commission_delegated_partner.pot b/commission_delegated_partner/i18n/commission_delegated_partner.pot new file mode 100644 index 000000000..aa6d57ed5 --- /dev/null +++ b/commission_delegated_partner/i18n/commission_delegated_partner.pot @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * commission_delegated_partner +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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: commission_delegated_partner +#. odoo-python +#: code:addons/commission_delegated_partner/models/commission_settlement.py:0 +#, python-format +msgid "Agent: %s" +msgstr "" + +#. module: commission_delegated_partner +#: model:ir.model,name:commission_delegated_partner.model_res_partner +msgid "Contact" +msgstr "" + +#. module: commission_delegated_partner +#: model:ir.model.fields,field_description:commission_delegated_partner.field_res_partner__delegated_agent_id +#: model:ir.model.fields,field_description:commission_delegated_partner.field_res_users__delegated_agent_id +msgid "Delegated Agent" +msgstr "" + +#. module: commission_delegated_partner +#: model:ir.model.fields,field_description:commission_delegated_partner.field_commission_settlement__invoice_partner_id +msgid "Invoice Partner" +msgstr "" + +#. module: commission_delegated_partner +#: model:ir.model,name:commission_delegated_partner.model_commission_settlement +msgid "Settlement" +msgstr "" diff --git a/commission_delegated_partner/i18n/es.po b/commission_delegated_partner/i18n/es.po new file mode 100644 index 000000000..d0e8d7216 --- /dev/null +++ b/commission_delegated_partner/i18n/es.po @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_commission_delegated_partner +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-13 11:29+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\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: commission_delegated_partner +#. odoo-python +#: code:addons/commission_delegated_partner/models/commission_settlement.py:0 +#, python-format +msgid "Agent: %s" +msgstr "Agente: %s" + +#. module: commission_delegated_partner +#: model:ir.model,name:commission_delegated_partner.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: commission_delegated_partner +#: model:ir.model.fields,field_description:commission_delegated_partner.field_res_partner__delegated_agent_id +#: model:ir.model.fields,field_description:commission_delegated_partner.field_res_users__delegated_agent_id +msgid "Delegated Agent" +msgstr "Agente delegado" + +#. module: commission_delegated_partner +#: model:ir.model.fields,field_description:commission_delegated_partner.field_commission_settlement__invoice_partner_id +msgid "Invoice Partner" +msgstr "Factura Socio" + +#. module: commission_delegated_partner +#: model:ir.model,name:commission_delegated_partner.model_commission_settlement +msgid "Settlement" +msgstr "Liquidación" + +#~ msgid "Display Name" +#~ msgstr "Mostrar Nombre" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Última Modificación el" diff --git a/commission_delegated_partner/i18n/it.po b/commission_delegated_partner/i18n/it.po new file mode 100644 index 000000000..1df68daf9 --- /dev/null +++ b/commission_delegated_partner/i18n/it.po @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_commission_delegated_partner +# +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: commission_delegated_partner +#. odoo-python +#: code:addons/commission_delegated_partner/models/commission_settlement.py:0 +#, python-format +msgid "Agent: %s" +msgstr "Agente: %s" + +#. module: commission_delegated_partner +#: model:ir.model,name:commission_delegated_partner.model_res_partner +msgid "Contact" +msgstr "Contatto" + +#. module: commission_delegated_partner +#: model:ir.model.fields,field_description:commission_delegated_partner.field_res_partner__delegated_agent_id +#: model:ir.model.fields,field_description:commission_delegated_partner.field_res_users__delegated_agent_id +msgid "Delegated Agent" +msgstr "Agente delegato" + +#. module: commission_delegated_partner +#: model:ir.model.fields,field_description:commission_delegated_partner.field_commission_settlement__invoice_partner_id +msgid "Invoice Partner" +msgstr "Partner fattura" + +#. module: commission_delegated_partner +#: model:ir.model,name:commission_delegated_partner.model_commission_settlement +msgid "Settlement" +msgstr "Liquidazione" + +#~ msgid "Display Name" +#~ msgstr "Nome visualizzato" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Ultima modifica il" diff --git a/commission_delegated_partner/i18n/pt.po b/commission_delegated_partner/i18n/pt.po new file mode 100644 index 000000000..cf80de467 --- /dev/null +++ b/commission_delegated_partner/i18n/pt.po @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_commission_delegated_partner +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-03-03 13:45+0000\n" +"Last-Translator: Pedro Castro Silva \n" +"Language-Team: none\n" +"Language: pt\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: commission_delegated_partner +#. odoo-python +#: code:addons/commission_delegated_partner/models/commission_settlement.py:0 +#, python-format +msgid "Agent: %s" +msgstr "Agente: %s" + +#. module: commission_delegated_partner +#: model:ir.model,name:commission_delegated_partner.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: commission_delegated_partner +#: model:ir.model.fields,field_description:commission_delegated_partner.field_res_partner__delegated_agent_id +#: model:ir.model.fields,field_description:commission_delegated_partner.field_res_users__delegated_agent_id +msgid "Delegated Agent" +msgstr "Agente Delegado" + +#. module: commission_delegated_partner +#: model:ir.model.fields,field_description:commission_delegated_partner.field_commission_settlement__invoice_partner_id +msgid "Invoice Partner" +msgstr "" + +#. module: commission_delegated_partner +#: model:ir.model,name:commission_delegated_partner.model_commission_settlement +msgid "Settlement" +msgstr "Comissionamento" diff --git a/commission_delegated_partner/i18n/pt_BR.po b/commission_delegated_partner/i18n/pt_BR.po new file mode 100644 index 000000000..edaed4c0c --- /dev/null +++ b/commission_delegated_partner/i18n/pt_BR.po @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_commission_delegated_partner +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-03-15 08:45+0000\n" +"Last-Translator: Marcel Savegnago \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.3.2\n" + +#. module: commission_delegated_partner +#. odoo-python +#: code:addons/commission_delegated_partner/models/commission_settlement.py:0 +#, python-format +msgid "Agent: %s" +msgstr "Agente: %s" + +#. module: commission_delegated_partner +#: model:ir.model,name:commission_delegated_partner.model_res_partner +msgid "Contact" +msgstr "Contato" + +#. module: commission_delegated_partner +#: model:ir.model.fields,field_description:commission_delegated_partner.field_res_partner__delegated_agent_id +#: model:ir.model.fields,field_description:commission_delegated_partner.field_res_users__delegated_agent_id +msgid "Delegated Agent" +msgstr "Agente Delegado" + +#. module: commission_delegated_partner +#: model:ir.model.fields,field_description:commission_delegated_partner.field_commission_settlement__invoice_partner_id +msgid "Invoice Partner" +msgstr "" + +#. module: commission_delegated_partner +#: model:ir.model,name:commission_delegated_partner.model_commission_settlement +msgid "Settlement" +msgstr "Abatimento" diff --git a/commission_delegated_partner/i18n/sale_commission_delegated_partner.pot b/commission_delegated_partner/i18n/sale_commission_delegated_partner.pot new file mode 100644 index 000000000..c069aa281 --- /dev/null +++ b/commission_delegated_partner/i18n/sale_commission_delegated_partner.pot @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_commission_delegated_partner +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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_delegated_partner +#: code:addons/sale_commission_delegated_partner/models/sale_commission_settlement.py:0 +#, python-format +msgid "Agent: %s" +msgstr "" + +#. module: sale_commission_delegated_partner +#: model:ir.model,name:sale_commission_delegated_partner.model_res_partner +msgid "Contact" +msgstr "" + +#. module: sale_commission_delegated_partner +#: model:ir.model.fields,field_description:sale_commission_delegated_partner.field_res_partner__delegated_agent_id +#: model:ir.model.fields,field_description:sale_commission_delegated_partner.field_res_users__delegated_agent_id +msgid "Delegated Agent" +msgstr "" + +#. module: sale_commission_delegated_partner +#: model:ir.model.fields,field_description:sale_commission_delegated_partner.field_res_partner__display_name +#: model:ir.model.fields,field_description:sale_commission_delegated_partner.field_sale_commission_settlement__display_name +msgid "Display Name" +msgstr "" + +#. module: sale_commission_delegated_partner +#: model:ir.model.fields,field_description:sale_commission_delegated_partner.field_res_partner__id +#: model:ir.model.fields,field_description:sale_commission_delegated_partner.field_sale_commission_settlement__id +msgid "ID" +msgstr "" + +#. module: sale_commission_delegated_partner +#: model:ir.model.fields,field_description:sale_commission_delegated_partner.field_sale_commission_settlement__invoice_partner_id +msgid "Invoice Partner" +msgstr "" + +#. module: sale_commission_delegated_partner +#: model:ir.model.fields,field_description:sale_commission_delegated_partner.field_res_partner____last_update +#: model:ir.model.fields,field_description:sale_commission_delegated_partner.field_sale_commission_settlement____last_update +msgid "Last Modified on" +msgstr "" + +#. module: sale_commission_delegated_partner +#: model:ir.model,name:sale_commission_delegated_partner.model_sale_commission_settlement +msgid "Settlement" +msgstr "" diff --git a/commission_delegated_partner/models/__init__.py b/commission_delegated_partner/models/__init__.py new file mode 100644 index 000000000..c366524b7 --- /dev/null +++ b/commission_delegated_partner/models/__init__.py @@ -0,0 +1,2 @@ +from . import res_partner +from . import commission_settlement diff --git a/commission_delegated_partner/models/commission_settlement.py b/commission_delegated_partner/models/commission_settlement.py new file mode 100644 index 000000000..1da9ffa4f --- /dev/null +++ b/commission_delegated_partner/models/commission_settlement.py @@ -0,0 +1,37 @@ +# Copyright 2021 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, fields, models + + +class CommissionSettlement(models.Model): + _inherit = "commission.settlement" + + invoice_partner_id = fields.Many2one( + "res.partner", compute="_compute_invoice_partner_id" + ) + + def _compute_invoice_partner_id(self): + for record in self: + record.invoice_partner_id = record._get_invoice_partner() + + def _get_invoice_grouping_keys(self): + res = super()._get_invoice_grouping_keys() + new_res = [] + for key in res: + if key == "agent_id": + new_res.append("invoice_partner_id") + else: + new_res.append(key) + return new_res + + def _get_invoice_partner(self): + agent = self[0].agent_id + if agent.delegated_agent_id: + return agent.delegated_agent_id + return super()._get_invoice_partner() + + def _post_process_line(self, line_form): + if self.agent_id.delegated_agent_id: + line_form.name += "\n" + _("Agent: %s") % self.agent_id.display_name + return super()._post_process_line(line_form) diff --git a/commission_delegated_partner/models/res_partner.py b/commission_delegated_partner/models/res_partner.py new file mode 100644 index 000000000..abae356f8 --- /dev/null +++ b/commission_delegated_partner/models/res_partner.py @@ -0,0 +1,10 @@ +# Copyright 2021 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + delegated_agent_id = fields.Many2one("res.partner") diff --git a/commission_delegated_partner/pyproject.toml b/commission_delegated_partner/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/commission_delegated_partner/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/commission_delegated_partner/readme/CONFIGURE.md b/commission_delegated_partner/readme/CONFIGURE.md new file mode 100644 index 000000000..2eed309bd --- /dev/null +++ b/commission_delegated_partner/readme/CONFIGURE.md @@ -0,0 +1,6 @@ +For adding delegated partner: + +1. Go to Sales \> Commission Management \> Agents. +2. Edit or create new record. +3. Go to the page Agent information. +4. Select or edit delegated agent. diff --git a/commission_delegated_partner/readme/CONTRIBUTORS.md b/commission_delegated_partner/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..d0e278554 --- /dev/null +++ b/commission_delegated_partner/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Enric Tobella \<\> +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/commission_delegated_partner/readme/DESCRIPTION.md b/commission_delegated_partner/readme/DESCRIPTION.md new file mode 100644 index 000000000..4a83cf03c --- /dev/null +++ b/commission_delegated_partner/readme/DESCRIPTION.md @@ -0,0 +1 @@ +Allows to delegate the invoice from the agent to a related partner diff --git a/commission_delegated_partner/static/description/icon.png b/commission_delegated_partner/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/commission_delegated_partner/static/description/icon.png differ diff --git a/commission_delegated_partner/static/description/index.html b/commission_delegated_partner/static/description/index.html new file mode 100644 index 000000000..e7c556b47 --- /dev/null +++ b/commission_delegated_partner/static/description/index.html @@ -0,0 +1,438 @@ + + + + + +Sale Commission Delegate Partner + + + +
+

Sale Commission Delegate Partner

+ + +

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

+

Allows to delegate the invoice from the agent to a related partner

+

Table of contents

+ +
+

Configuration

+

For adding delegated partner:

+
    +
  1. Go to Sales > Commission Management > Agents.
  2. +
  3. Edit or create new record.
  4. +
  5. Go to the page Agent information.
  6. +
  7. Select or edit delegated agent.
  8. +
+
+
+

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

+
    +
  • Creu Blanca
  • +
+
+
+

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/commission_delegated_partner/tests/__init__.py b/commission_delegated_partner/tests/__init__.py new file mode 100644 index 000000000..d0033ae78 --- /dev/null +++ b/commission_delegated_partner/tests/__init__.py @@ -0,0 +1 @@ +from . import test_commission_delegate_partner diff --git a/commission_delegated_partner/tests/test_commission_delegate_partner.py b/commission_delegated_partner/tests/test_commission_delegate_partner.py new file mode 100644 index 000000000..1f10af497 --- /dev/null +++ b/commission_delegated_partner/tests/test_commission_delegate_partner.py @@ -0,0 +1,153 @@ +# Copyright 2016-2019 Tecnativa - Pedro M. Baeza +# License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html + +import dateutil.relativedelta + +from odoo import Command, fields + +from odoo.addons.base.tests.common import BaseCommon + + +class TestSaleCommissionDelegatePartner(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.commission_model = cls.env["commission"] + cls.commission_net_invoice = cls.commission_model.create( + { + "name": "10% fixed commission (Net amount) - Invoice Based", + "fix_qty": 10.0, + "amount_base_type": "net_amount", + } + ) + cls.res_partner_model = cls.env["res.partner"] + cls.partner = cls.res_partner_model.create({"name": "Test Partner"}) + cls.partner.write({"agent": False}) + cls.settle_model = cls.env["commission.settlement"] + cls.make_settle_model = cls.env["commission.make.settle"] + cls.make_inv_model = cls.env["commission.make.invoice"] + cls.product = cls.env["product.product"].create({"name": "Test Product"}) + cls.journal = cls.env["account.journal"].search( + [("type", "=", "purchase")], limit=1 + ) + cls.delegate_agent = cls.res_partner_model.create({"name": "Delegate Agent"}) + cls.agent_monthly = cls.res_partner_model.create( + { + "name": "Test Agent - Monthly", + "agent": True, + "delegated_agent_id": cls.delegate_agent.id, + "settlement": "monthly", + "lang": "en_US", + } + ) + cls.agent_monthly_02 = cls.res_partner_model.create( + { + "name": "Test Agent 02 - Monthly", + "agent": True, + "settlement": "monthly", + "lang": "en_US", + } + ) + + def _create_invoice(self, agent, commission, date=None, currency=None): + vals = { + "move_type": "out_invoice", + "partner_id": self.partner.id, + "invoice_line_ids": [ + Command.create( + { + "product_id": self.product.id, + "agent_ids": [ + Command.create( + {"agent_id": agent.id, "commission_id": commission.id}, + ) + ], + }, + ) + ], + } + if date: + vals.update({"invoice_date": date, "date": date}) + if currency: + vals.update({"currency_id": currency.id}) + move = self.env["account.move"].create([vals]) + move.action_post() + return move + + def test_settlement(self): + self._create_invoice( + self.agent_monthly, + self.commission_net_invoice, + ) + self._create_invoice( + self.agent_monthly_02, + self.commission_net_invoice, + ) + wizard = self.make_settle_model.create( + { + "date_to": ( + fields.Datetime.from_string(fields.Datetime.now()) + + dateutil.relativedelta.relativedelta(months=1) + ), + "settlement_type": "sale_invoice", + } + ) + wizard.action_settle() + settlements = self.settle_model.search([("state", "=", "settled")]) + self.assertEqual(len(settlements), 2) + self.env["commission.make.invoice"].with_context( + settlement_ids=settlements.ids + ).create( + { + "journal_id": self.journal.id, + "product_id": self.product.id, + "date": fields.Datetime.now(), + } + ).button_create() + for settlement in settlements: + self.assertEqual(settlement.state, "invoiced") + settlement = settlements.filtered(lambda r: r.agent_id == self.agent_monthly) + self.assertTrue(settlement) + self.assertEqual(1, len(settlement)) + self.assertNotEqual(self.agent_monthly, settlement.invoice_id.partner_id) + self.assertEqual(self.delegate_agent, settlement.invoice_id.partner_id) + settlement = settlements.filtered(lambda r: r.agent_id == self.agent_monthly_02) + self.assertTrue(settlement) + self.assertEqual(1, len(settlement)) + self.assertEqual(self.agent_monthly_02, settlement.invoice_id.partner_id) + + def test_get_invoice_grouping_keys(self): + """Test that _get_invoice_grouping_keys replaces + agent_id with invoice_partner_id""" + settlement = self.settle_model.create( + { + "agent_id": self.agent_monthly.id, # Ensuring agent_id is set + "date_from": fields.Date.today(), + "date_to": fields.Date.today(), + } + ) + keys = settlement._get_invoice_grouping_keys() + self.assertIn("invoice_partner_id", keys) + self.assertNotIn("agent_id", keys) + + def test_get_invoice_partner(self): + """Test that _get_invoice_partner returns the delegated agent if present""" + settlement = self.settle_model.create( + { + "agent_id": self.agent_monthly.id, + "date_from": fields.Date.today(), + "date_to": fields.Date.today(), + } + ) + self.assertEqual(settlement._get_invoice_partner(), self.delegate_agent) + + settlement_no_delegate = self.settle_model.create( + { + "agent_id": self.agent_monthly_02.id, + "date_from": fields.Date.today(), + "date_to": fields.Date.today(), + } + ) + self.assertEqual( + settlement_no_delegate._get_invoice_partner(), self.agent_monthly_02 + ) diff --git a/commission_delegated_partner/views/res_partner.xml b/commission_delegated_partner/views/res_partner.xml new file mode 100644 index 000000000..f2d02c6c0 --- /dev/null +++ b/commission_delegated_partner/views/res_partner.xml @@ -0,0 +1,19 @@ + + + + + + res.partner.form (in sale_commission_delegate_partner) + res.partner + + + + + + + + +