Skip to content

Commit

Permalink
[FIX] sale_commission_product_criteria_domain: onchange partner agents
Browse files Browse the repository at this point in the history
  • Loading branch information
aleuffre committed Nov 26, 2024
1 parent e787296 commit 7499f8a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions sale_commission_product_criteria_domain/models/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,24 @@ def _compute_allowed_commission_group_ids_domain(self):
@api.onchange("agent_ids")
def _onchange_agent_ids(self):
for rec in self:
exiting_agents = rec.commission_item_agent_ids.mapped("agent_id")
# ._origin avoids an issue with NewId
# res.partner(<NewId origin=1>,) != res.partner(1,)
# but we also need to preserve virtual records (which ._origin discards)
current_agents = tuple(x._origin or x for x in rec.agent_ids)
existing_commission_agents = rec.commission_item_agent_ids.mapped(
"agent_id"
)
to_create = [
{
"agent_id": x.id,
"group_ids": [(6, 0, x.allowed_commission_group_ids.ids)],
}
for x in rec.agent_ids.filtered(
lambda x: x.commission_id.commission_type == "product_restricted"
)
if x not in exiting_agents
for x in current_agents
if (x not in existing_commission_agents)
and (x.commission_id.commission_type == "product_restricted")
]
to_delete = rec.commission_item_agent_ids.filtered(
lambda x: x.agent_id in (exiting_agents - rec.agent_ids)
lambda x: x.agent_id not in current_agents
)
if to_delete:
rec.update(
Expand Down

0 comments on commit 7499f8a

Please sign in to comment.