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][FIX] sale_commission_product_criteria_domain: onchange partner agents #580

Merged
merged 1 commit into from
Nov 26, 2024
Merged
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
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
Loading