Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD] sale_commission_delivery_partner: Use Delivery Address Agents #593

Open
wants to merge 3 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions sale_commission/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,19 @@ def _compute_any_settled(self):
for record in self:
record.any_settled = any(record.mapped("agent_ids.settled"))

def _get_partner_for_commission(self):
return self.move_id.partner_id

@api.depends("move_id.partner_id")
def _compute_agent_ids(self):
self.agent_ids = False # for resetting previous agents
for record in self.filtered(
lambda x: x.move_id.partner_id and x.move_id.move_type[:3] == "out"
lambda x: x._get_partner_for_commission()
and x.move_id.move_type[:3] == "out"
):
if not record.commission_free and record.product_id:
record.agent_ids = record._prepare_agents_vals_partner(
record.move_id.partner_id
record._get_partner_for_commission()
)

def _copy_data_extend_business_fields(self, values):
Expand Down
3 changes: 3 additions & 0 deletions sale_commission/models/sale_commission_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class SaleCommissionMixin(models.AbstractModel):
string="Commission",
)

def _get_partner_for_commission(self):
raise NotImplementedError()

def _prepare_agent_vals(self, agent):
return {"agent_id": agent.id, "commission_id": agent.commission_id.id}

Expand Down
7 changes: 5 additions & 2 deletions sale_commission/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ class SaleOrderLine(models.Model):

agent_ids = fields.One2many(comodel_name="sale.order.line.agent")

def _get_partner_for_commission(self):
return self.order_id.partner_id

@api.depends("order_id.partner_id")
def _compute_agent_ids(self):
self.agent_ids = False # for resetting previous agents
for record in self.filtered(lambda x: x.order_id.partner_id):
for record in self.filtered(lambda x: x._get_partner_for_commission()):
if not record.commission_free:
record.agent_ids = record._prepare_agents_vals_partner(
record.order_id.partner_id
record._get_partner_for_commission()
)

def _prepare_invoice_line(self, **optional_values):
Expand Down
5 changes: 4 additions & 1 deletion sale_commission_advance/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ def has_related_sale_with_down_payment(self):
class AccountMoveLine(models.Model):
_inherit = "account.move.line"

def _get_partner_for_commission(self):
return self.move_id.partner_id

@api.depends("move_id.partner_id")
def _compute_agent_ids(self):
self.agent_ids = False # for resetting previous agents
down_payment_items = self.filtered(
lambda x: x.move_id.partner_id
lambda x: x._get_partner_for_commission()
and x.move_id.move_type[:3] == "out"
and x.sale_line_ids.is_downpayment
)
Expand Down
7 changes: 5 additions & 2 deletions sale_commission_advance/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

def _get_partner_for_commission(self):
return self.order_id.partner_id

@api.depends("order_id.partner_id")
def _compute_agent_ids(self):
self.agent_ids = False # for resetting previous agents
down_payment_items = self.filtered(
lambda x: x.order_id.partner_id and x.is_downpayment
lambda x: x._get_partner_for_commission() and x.is_downpayment
)
for record in down_payment_items:
agent_ids = record._prepare_agents_vals_partner_down_payment(
record.order_id.partner_id
record._get_partner_for_commission()
)
record.update({"agent_ids": agent_ids})
regular_items = self - down_payment_items
Expand Down
91 changes: 91 additions & 0 deletions sale_commission_delivery_partner/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/commission/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/commission/issues/new?body=module:%20sale_commission_delivery_partner%0Aversion:%2014.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
~~~~~~~

* Ooops
* PyTech SRL

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

* `PyTech SRL <https://www.pytech.it>`_:
* Sebastiano Picchi <[email protected]>

* `Ooops404 <https://www.ooops404.com>`_:
* Eduard Brahas <[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.

.. |maintainer-PicchiSeba| image:: https://github.com/PicchiSeba.png?size=40px
:target: https://github.com/PicchiSeba
:alt: PicchiSeba

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-PicchiSeba|

This module is part of the `OCA/commission <https://github.com/OCA/commission/tree/14.0/sale_commission_delivery_partner>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions sale_commission_delivery_partner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions sale_commission_delivery_partner/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
2 changes: 2 additions & 0 deletions sale_commission_delivery_partner/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_move_line
from . import sale_order_line
17 changes: 17 additions & 0 deletions sale_commission_delivery_partner/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from odoo import api, models


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

def _get_partner_for_commission(self):
return self.move_id.partner_shipping_id

@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._get_partner_for_commission()):
if not record.commission_free:
record.agent_ids = record._prepare_agents_vals_partner(
record._get_partner_for_commission()
)
17 changes: 17 additions & 0 deletions sale_commission_delivery_partner/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from odoo import api, models


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

def _get_partner_for_commission(self):
return self.order_id.partner_shipping_id

@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._get_partner_for_commission()):
if not record.commission_free:
record.agent_ids = record._prepare_agents_vals_partner(
record._get_partner_for_commission()
)
5 changes: 5 additions & 0 deletions sale_commission_delivery_partner/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* `PyTech SRL <https://www.pytech.it>`_:
* Sebastiano Picchi <[email protected]>

* `Ooops404 <https://www.ooops404.com>`_:
* Eduard Brahas <[email protected]>
3 changes: 3 additions & 0 deletions sale_commission_delivery_partner/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading