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

[17.0][MIG] sales_team_security_crm: Migration to 17.0 #3429

Open
wants to merge 8 commits into
base: 17.0
Choose a base branch
from

Conversation

lef-adhoc
Copy link

@lef-adhoc lef-adhoc commented Nov 25, 2024

I migrated the module through this PR #2461

@lef-adhoc lef-adhoc force-pushed the 17.0-mig-sales_team_security_crm branch from b4b9174 to 5dbaa96 Compare December 12, 2024 13:36
Copy link

@cvinh cvinh left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@carlos-lopez-tecnativa carlos-lopez-tecnativa left a comment

Choose a reason for hiding this comment

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

LGTM just a minor change

TT52441

@Tecnativa

<field name="model_id" ref="crm.model_crm_lead" />
<field
name="domain_force"
>['|', '|', ('user_id', '=', user.id), ('user_id', '=', False), '|', ('team_id', '=', user.sale_team_id.id),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be simplified to: What do you think?

Suggested change
>['|', '|', ('user_id', '=', user.id), ('user_id', '=', False), '|', ('team_id', '=', user.sale_team_id.id),
>['|', ('user_id', 'in', [user.id, False]), ('team_id', 'in', [user.sale_team_id.id, False]),

Copy link

@cvinh cvinh Jan 8, 2025

Choose a reason for hiding this comment

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

Moreover, you must take into account the multi team that has been introduced in odoo v15. In that case, user.sale_team_id can be false if a user is in several teams (ie https://github.com/odoo/odoo/blob/b7abee1f64d6812d66c5ac61d1d8f841310c81d7/addons/sales_team/models/res_users.py#L32)
IMHO the correct rule should be
['|', '|', ('user_id', 'in', [user.id, False]), ('team_id', '=', user.sale_team_id.id), ('team_id', 'in', user.crm_team_ids.ids)]

Copy link

Choose a reason for hiding this comment

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

in our case, we did not want the users in Team Only group to access to leads without a user_id so we finally did
['|', '|', ('user_id', '=', user.id), ('team_id', '=', user.sale_team_id.id), ('team_id', 'in', user.crm_team_ids.ids)]

Copy link
Member

Choose a reason for hiding this comment

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

The original module should include leads without user.

Copy link

@cvinh cvinh Jan 9, 2025

Choose a reason for hiding this comment

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

The original module should include leads without user.

You are right considering that odoo standard has the same policy with crm ('my document only' group includes lead without user)
Anyway, the rule can be customized after on.
But natively, please include crm_team_ids because if not, the rule does not work out of the box in multi-team configuration

<field name="model_id" ref="crm.model_crm_activity_report" />
<field
name="domain_force"
>['|', '|', ('user_id', '=', user.id), ('user_id', '=', False), '|', ('team_id', '=', user.sale_team_id.id),
Copy link
Contributor

Choose a reason for hiding this comment

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

the same here

Copy link

@cvinh cvinh Jan 8, 2025

Choose a reason for hiding this comment

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

same here
['|', '|', ('user_id', 'in', [user.id, False]), ('team_id', '=', user.sale_team_id.id), ('team_id', 'in', user.crm_team_ids.ids)]

<field name="model_id" ref="crm.model_crm_lead" />
<field
name="domain_force"
>['|', '|', ('user_id', '=', user.id), ('user_id', '=', False), '|', ('team_id', '=', user.sale_team_id.id),
Copy link

@cvinh cvinh Jan 8, 2025

Choose a reason for hiding this comment

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

Moreover, you must take into account the multi team that has been introduced in odoo v15. In that case, user.sale_team_id can be false if a user is in several teams (ie https://github.com/odoo/odoo/blob/b7abee1f64d6812d66c5ac61d1d8f841310c81d7/addons/sales_team/models/res_users.py#L32)
IMHO the correct rule should be
['|', '|', ('user_id', 'in', [user.id, False]), ('team_id', '=', user.sale_team_id.id), ('team_id', 'in', user.crm_team_ids.ids)]

<field name="model_id" ref="crm.model_crm_activity_report" />
<field
name="domain_force"
>['|', '|', ('user_id', '=', user.id), ('user_id', '=', False), '|', ('team_id', '=', user.sale_team_id.id),
Copy link

@cvinh cvinh Jan 8, 2025

Choose a reason for hiding this comment

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

same here
['|', '|', ('user_id', 'in', [user.id, False]), ('team_id', '=', user.sale_team_id.id), ('team_id', 'in', user.crm_team_ids.ids)]

<record id="sales_team_team_rule" model="ir.rule">
<field name="name">Own Sale Teams</field>
<field name="model_id" ref="sales_team.model_crm_team" />
<field name="domain_force">[('id', '=', user.sale_team_id.id)]</field>
Copy link

@cvinh cvinh Jan 8, 2025

Choose a reason for hiding this comment

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

and here
['|', ('id', '=', user.sale_team_id.id), ('id', 'in', user.crm_team_ids.ids)]

@lef-adhoc lef-adhoc force-pushed the 17.0-mig-sales_team_security_crm branch 3 times, most recently from 205ce85 to 4cd5e82 Compare January 9, 2025 16:40
@lef-adhoc
Copy link
Author

@cvinh the tests fail with the domains you gave me, could you check it?

@cvinh
Copy link

cvinh commented Jan 9, 2025

@cvinh the tests fail with the domains you gave me, could you check it?

Humm there should be something to do in sales_team_security

"team_id": cls.team.id,
}
)

Copy link

Choose a reason for hiding this comment

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

Tests with the case multi-team should be added and see why this one fails

@cvinh
Copy link

cvinh commented Jan 9, 2025

@cvinh the tests fail with the domains you gave me, could you check it?

Can you commit again to see where it fails ?

@lef-adhoc
Copy link
Author

lef-adhoc commented Jan 9, 2025

@cvinh The failure occurs in the following line https://github.com/adhoc-dev/sale-workflow/blob/4cd5e8211dceceece3b54121c9b0e6c7c7420e63/sales_team_security/tests/common.py#L88

When searching with the self.user in the following line it does not find anything https://github.com/adhoc-dev/sale-workflow/blob/4cd5e8211dceceece3b54121c9b0e6c7c7420e63/sales_team_security/tests/common.py#L69

@lef-adhoc lef-adhoc force-pushed the 17.0-mig-sales_team_security_crm branch from 4cd5e82 to f0d2461 Compare January 10, 2025 11:51
@lef-adhoc
Copy link
Author

@cvinh I think that's it, I also added a multi-team test, what do you think?

@lef-adhoc lef-adhoc force-pushed the 17.0-mig-sales_team_security_crm branch from f0d2461 to 5825dd1 Compare January 10, 2025 12:11
Copy link

@cvinh cvinh left a comment

Choose a reason for hiding this comment

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

I think if a user is in one team only, the crm_team_ids are empty
If I'm wrong then it's ok as you did

<record id="sales_team_team_rule" model="ir.rule">
<field name="name">Own Sale Teams</field>
<field name="model_id" ref="sales_team.model_crm_team" />
<field name="domain_force">[('id', 'in', user.crm_team_ids.ids)]</field>
Copy link

@cvinh cvinh Jan 10, 2025

Choose a reason for hiding this comment

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

Suggested change
<field name="domain_force">[('id', 'in', user.crm_team_ids.ids)]</field>
<field name="domain_force">['|', ('id', '=', 'user.sale_team_id.id'), ('id', 'in', user.crm_team_ids.ids)]</field>

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

Successfully merging this pull request may close these issues.

8 participants