Skip to content

Commit

Permalink
[IMP] sale_commision: improved partner selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Chionne27 committed Feb 6, 2025
1 parent 3d9ac59 commit 8a933ae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 6 additions & 2 deletions sale_commission/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class AccountMoveLine(models.Model):
copy=False,
)

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

@api.depends("agent_ids", "agent_ids.settled")
def _compute_any_settled(self):
for record in self:
Expand All @@ -121,11 +124,12 @@ def _compute_any_settled(self):
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()

Check warning on line 36 in sale_commission/models/sale_commission_mixin.py

View check run for this annotation

Codecov / codecov/patch

sale_commission/models/sale_commission_mixin.py#L36

Added line #L36 was not covered by tests

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

Expand Down
8 changes: 6 additions & 2 deletions sale_commission/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ 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._get_partner_for_commission()
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

0 comments on commit 8a933ae

Please sign in to comment.