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 agents withs … #452

Conversation

ilyasProgrammer
Copy link
Member

…restrictions

@ilyasProgrammer ilyasProgrammer force-pushed the 14.0-sale_commission_product_criteria_domain-fixes branch from 82176d7 to 472d4b4 Compare September 15, 2023 03:37
Copy link

@aleuffre aleuffre left a 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

Copy link
Member Author

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.

Comment on lines 54 to 55
lambda x: x.agent_id._origin.id
in (set(exiting_agents.ids) - set(rec.agent_ids.ids))

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?

Suggested change
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)

Copy link
Member Author

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.

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.

Copy link
Member Author

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!

@aleuffre
Copy link

Oh, and please follow OCA guidelines for your PR title and your commit message:

  • PR title has to indicate the Odoo version at the start `[14.0] (your commit message should not)
  • Commit message's first line should not be longer than 80 characters

https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#commit-message

@ilyasProgrammer ilyasProgrammer changed the title [FIX] sale_commission_product_criteria_domain: onchange agents withs … [14.0][FIX] sale_commission_product_criteria_domain: onchange agents withs … Sep 18, 2023
@ilyasProgrammer ilyasProgrammer force-pushed the 14.0-sale_commission_product_criteria_domain-fixes branch from 472d4b4 to b4067a1 Compare September 18, 2023 01:46
@ilyasProgrammer ilyasProgrammer force-pushed the 14.0-sale_commission_product_criteria_domain-fixes branch from b4067a1 to 7739869 Compare September 19, 2023 01:39
Copy link
Contributor

@francesco-ooops francesco-ooops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional ok!

Copy link

@aleuffre aleuffre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ok

@ilyasProgrammer
Copy link
Member Author

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 14.0-ocabot-merge-pr-452-by-ilyasProgrammer-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 34e8929 into OCA:14.0 Sep 20, 2023
5 of 6 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 4d535ed. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants