diff --git a/sale_commission_delivery_partner/README.rst b/sale_commission_delivery_partner/README.rst new file mode 100644 index 000000000..531ef32ae --- /dev/null +++ b/sale_commission_delivery_partner/README.rst @@ -0,0 +1,91 @@ +=========================== +Commission Delivery Partner +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:64fbc27f93c0a21e84b27ee30b1a1ce3713b17b3a816c677eacf1f86f8b2fb98 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/14.0/sale_commission_delivery_partner + :alt: OCA/commission +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/commission-14-0/commission-14-0-sale_commission_delivery_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=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module addresses the use case where the same customer has different agents/commissions according to SO/Invoice delivery address. + +In SO and invoice, commission is calculated based on agents set in the "delivery address" contact rather than on "customer" contact's agents. + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~ + +* Ooops +* PyTech SRL + +Contributors +~~~~~~~~~~~~ + +* `PyTech SRL `_: + * Sebastiano Picchi + +* `Ooops404 `_: + * Eduard Brahas + +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. + +.. |maintainer-PicchiSeba| image:: https://github.com/PicchiSeba.png?size=40px + :target: https://github.com/PicchiSeba + :alt: PicchiSeba + +Current `maintainer `__: + +|maintainer-PicchiSeba| + +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_delivery_partner/__init__.py b/sale_commission_delivery_partner/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/sale_commission_delivery_partner/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_commission_delivery_partner/__manifest__.py b/sale_commission_delivery_partner/__manifest__.py new file mode 100644 index 000000000..13e20a6d1 --- /dev/null +++ b/sale_commission_delivery_partner/__manifest__.py @@ -0,0 +1,17 @@ +{ + "name": "Commission Delivery Partner", + "summary": "Commissions based on delivery address", + "version": "14.0.1.0.0", + "author": "Ooops, " "PyTech SRL," "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/commission", + "category": "Sales Management", + "license": "AGPL-3", + "depends": [ + "sale_commission", + ], + "data": [], + "demo": [], + "maintainers": ["PicchiSeba"], + "application": False, + "installable": True, +} diff --git a/sale_commission_delivery_partner/models/__init__.py b/sale_commission_delivery_partner/models/__init__.py new file mode 100644 index 000000000..f8e68897c --- /dev/null +++ b/sale_commission_delivery_partner/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_move_line +from . import sale_order_line diff --git a/sale_commission_delivery_partner/models/account_move_line.py b/sale_commission_delivery_partner/models/account_move_line.py new file mode 100644 index 000000000..1495ae743 --- /dev/null +++ b/sale_commission_delivery_partner/models/account_move_line.py @@ -0,0 +1,14 @@ +from odoo import api, models + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + @api.depends("move_id", "move_id.partner_shipping_id") + def _compute_agent_ids(self): + self.agent_ids = False + for record in self.filtered(lambda x: x.move_id.partner_shipping_id): + if not record.commission_free: + record.agent_ids = record._prepare_agents_vals_partner( + record.move_id.partner_shipping_id + ) diff --git a/sale_commission_delivery_partner/models/sale_order_line.py b/sale_commission_delivery_partner/models/sale_order_line.py new file mode 100644 index 000000000..c2940f4fb --- /dev/null +++ b/sale_commission_delivery_partner/models/sale_order_line.py @@ -0,0 +1,14 @@ +from odoo import api, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + @api.depends("order_id", "order_id.partner_shipping_id") + def _compute_agent_ids(self): + self.agent_ids = False + for record in self.filtered(lambda x: x.order_id.partner_shipping_id): + if not record.commission_free: + record.agent_ids = record._prepare_agents_vals_partner( + record.order_id.partner_shipping_id + ) diff --git a/sale_commission_delivery_partner/readme/CONTRIBUTORS.rst b/sale_commission_delivery_partner/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..bcd1459e2 --- /dev/null +++ b/sale_commission_delivery_partner/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* `PyTech SRL `_: + * Sebastiano Picchi + +* `Ooops404 `_: + * Eduard Brahas diff --git a/sale_commission_delivery_partner/readme/DESCRIPTION.rst b/sale_commission_delivery_partner/readme/DESCRIPTION.rst new file mode 100644 index 000000000..1cfddfda4 --- /dev/null +++ b/sale_commission_delivery_partner/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module addresses the use case where the same customer has different agents/commissions according to SO/Invoice delivery address. + +In SO and invoice, commission is calculated based on agents set in the "delivery address" contact rather than on "customer" contact's agents. diff --git a/sale_commission_delivery_partner/static/description/icon.png b/sale_commission_delivery_partner/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/sale_commission_delivery_partner/static/description/icon.png differ diff --git a/sale_commission_delivery_partner/static/description/index.html b/sale_commission_delivery_partner/static/description/index.html new file mode 100644 index 000000000..072dc4d7e --- /dev/null +++ b/sale_commission_delivery_partner/static/description/index.html @@ -0,0 +1,430 @@ + + + + + +Commission Delivery Partner + + + +
+

Commission Delivery Partner

+ + +

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

+

This module addresses the use case where the same customer has different agents/commissions according to SO/Invoice delivery address.

+

In SO and invoice, commission is calculated based on agents set in the “delivery address” contact rather than on “customer” contact’s agents.

+

Table of contents

+ +
+

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

+
    +
  • Ooops
  • +
  • PyTech SRL
  • +
+
+
+

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.

+

Current maintainer:

+

PicchiSeba

+

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_delivery_partner/tests/__init__.py b/sale_commission_delivery_partner/tests/__init__.py new file mode 100644 index 000000000..f95df182c --- /dev/null +++ b/sale_commission_delivery_partner/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_commission_delivery_partner diff --git a/sale_commission_delivery_partner/tests/test_sale_commission_delivery_partner.py b/sale_commission_delivery_partner/tests/test_sale_commission_delivery_partner.py new file mode 100644 index 000000000..58ad9dd01 --- /dev/null +++ b/sale_commission_delivery_partner/tests/test_sale_commission_delivery_partner.py @@ -0,0 +1,106 @@ +from odoo.tests.common import TransactionCase + + +class TestSaleCommissionDeliveryPartner(TransactionCase): + def setUp(self): + super(TestSaleCommissionDeliveryPartner, self).setUp() + + self.user = self.env["res.users"].create( + { + "name": "Test User", + "login": "test_user", + "email": "test_user@example.com", + "groups_id": [ + ( + 6, + 0, + [ + self.env.ref("base.group_user").id, + self.env.ref("sale.group_delivery_invoice_address").id, + self.env.ref("sales_team.group_sale_manager").id, + ], + ) + ], + } + ) + + self.partner = self.env["res.partner"].create( + { + "name": "Test Partner", + "email": "test@partner.com", + } + ) + self.product = self.env["product.product"].create( + { + "name": "Test Product", + "list_price": 100.0, + "standard_price": 50.0, + "invoice_policy": "order", + "type": "consu", + } + ) + + def test_create_sale_order(self): + sale_order = ( + self.env["sale.order"] + .with_user(self.user.id) + .create( + { + "partner_id": self.partner.id, + "order_line": [ + ( + 0, + 0, + { + "product_id": self.product.id, + "product_uom_qty": 5, + "price_unit": self.product.list_price, + }, + ) + ], + } + ) + ) + + sale_order.action_confirm() + self.assertEqual(sale_order.state, "sale") + + context = {"active_model": "sale.order", "active_ids": sale_order.ids} + invoice_so_wizard = ( + self.env["sale.advance.payment.inv"] + .with_context(context) + .create( + { + "advance_payment_method": "delivered", + } + ) + ) + invoice_so_wizard.create_invoices() + + invoice_so = self.env["account.move"].search( + [("invoice_origin", "=", sale_order.name)], limit=1 + ) + + self.assertEqual(sale_order.partner_shipping_id, invoice_so.partner_shipping_id) + + new_shipping_partner = self.env["res.partner"].create( + { + "name": "New Shipping Partner", + "email": "new_shipping@partner.com", + } + ) + sale_order.partner_shipping_id = new_shipping_partner.id + + for line in sale_order.order_line: + for agent in line.agent_ids: + self.assertEqual(agent.partner_id, new_shipping_partner) + + invoice_so.refresh() + + invoice_so.partner_shipping_id = new_shipping_partner.id + + for line in invoice_so.invoice_line_ids: + for agent in line.agent_ids: + self.assertEqual(agent.partner_id, new_shipping_partner) + + self.assertEqual(sale_order.partner_shipping_id, invoice_so.partner_shipping_id) diff --git a/setup/sale_commission_delivery_partner/odoo/addons/sale_commission_delivery_partner b/setup/sale_commission_delivery_partner/odoo/addons/sale_commission_delivery_partner new file mode 120000 index 000000000..f501c07aa --- /dev/null +++ b/setup/sale_commission_delivery_partner/odoo/addons/sale_commission_delivery_partner @@ -0,0 +1 @@ +../../../../sale_commission_delivery_partner \ No newline at end of file diff --git a/setup/sale_commission_delivery_partner/setup.py b/setup/sale_commission_delivery_partner/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/sale_commission_delivery_partner/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)