-
-
Notifications
You must be signed in to change notification settings - Fork 344
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 agents withs … #452
[14.0][FIX] sale_commission_product_criteria_domain: onchange agents withs … #452
Conversation
82176d7
to
472d4b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only code review:
Code looks generally ok, left some minor feedback to improve clarity and readability.
for x in rec.agent_ids.filtered( | ||
lambda x: x.commission_id.commission_type == "product_restricted" | ||
) | ||
if x not in exiting_agents.ids | ||
if x._origin.id not in exiting_agents.ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if x._origin.id not in exiting_agents.ids | |
if x not in exiting_agents |
I think this would be easier and more readable, unless it doesn't work for some reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it does not work, since x is a new instance without id.
lambda x: x.agent_id._origin.id | ||
in (set(exiting_agents.ids) - set(rec.agent_ids.ids)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there's something I'm missing, but why not work with recordsets directly?
lambda x: x.agent_id._origin.id | |
in (set(exiting_agents.ids) - set(rec.agent_ids.ids)) | |
lambda x: x.agent_id in (exiting_agents - rec.agent_ids) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. It cant be done using records. Thats why i use ids and sets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to work for me, on both existing partners and partners being created. Could you double check please?
@api.onchange("agent_ids")
def _onchange_agent_ids(self):
for rec in self:
exiting_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
]
to_delete = rec.commission_item_agent_ids.filtered(
lambda x: x.agent_id in (exiting_agents - rec.agent_ids)
)
if to_delete:
rec.update(
{"commission_item_agent_ids": [(2, dl.id, 0) for dl in to_delete]}
)
if to_create:
rec.update(
{"commission_item_agent_ids": [(0, 0, line) for line in to_create]}
)
If you confirm that it doesn't work for you I'll drop the issue, since it's no big deal either way, but I'm curious to understand why it wouldn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works indeed. Must be my mistake. Thanks!
Oh, and please follow OCA guidelines for your PR title and your commit message:
|
472d4b4
to
b4067a1
Compare
b4067a1
to
7739869
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functional ok!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ok
/ocabot merge patch |
On my way to merge this fine PR! |
Congratulations, your PR was merged at 4d535ed. Thanks a lot for contributing to OCA. ❤️ |
…restrictions