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][ADD] partner_risk_insurance_security #403

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

toita86
Copy link
Contributor

@toita86 toita86 commented Oct 22, 2024

Currently, anyone can view and edit the Credit Insurance tab added by the module partner_risk_insurance.

Implementation: Created a group to restrict access to the fields added by the aforementioned module.

@OCA-git-bot
Copy link
Contributor

Hi @Daniel-CA, @sergio-teruel, @omar7r, @Tardo,
some modules you are maintaining are being modified, check this out!

@toita86 toita86 force-pushed the 14.0-IMP-partner_risk_insurance branch 3 times, most recently from a3f9d30 to b6084af Compare October 22, 2024 11:51
@pedrobaeza
Copy link
Member

This must be an extra module, as it's modifying current behavior heavily. The reason to not protect it is because not everyone can edit contacts, and those who can, needs a lot of times to touch these amounts (they are salesmen providing the information).

@toita86 toita86 force-pushed the 14.0-IMP-partner_risk_insurance branch 3 times, most recently from f710520 to 2df0fbd Compare October 22, 2024 14:03
@toita86 toita86 changed the title [IMP] partner_risk_insurance: Added group for field access [ADD] partner_risk_insurance_restriction Oct 22, 2024
@toita86 toita86 changed the title [ADD] partner_risk_insurance_restriction [14.0][ADD] partner_risk_insurance_restriction Oct 22, 2024
@pedrobaeza
Copy link
Member

A usual suffix is _security for this kind of things.

@toita86
Copy link
Contributor Author

toita86 commented Oct 22, 2024

A usual suffix is _security for this kind of things.

Thanks for the info!

@toita86 toita86 changed the title [14.0][ADD] partner_risk_insurance_restriction [14.0][ADD] partner_risk_insurance_security Oct 22, 2024
@toita86 toita86 force-pushed the 14.0-IMP-partner_risk_insurance branch 5 times, most recently from 024076f to 7a77449 Compare October 29, 2024 08:34
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!

store=False,
)

@api.depends("user_id")
Copy link

@aleuffre aleuffre Nov 6, 2024

Choose a reason for hiding this comment

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

issue: The field is not stored, so you don't even need to have this @api.depends at all, since it'll be recomputed every time anyway.

You can have the @api.depends if you want the field to be recomputed based on specific conditions, in addition to it being recomputed almost every time you look at the record, though.

In this case, you're asking Odoo to recompute the field based on the field user_id of res.partner, i.e. Salesman. In other words, when you change "Salesman" on a contact, recompute the value of this field.

I think what you're looking for is @api.depends_context('uid')

Comment on lines 16 to 21
partner.is_full_access_user = (
self.env.user
in self.env.ref(
"partner_risk_insurance_security.group_full_access_credit_policy_state"
).users
)
Copy link

Choose a reason for hiding this comment

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

suggestion: I think self.env.user.has_group("partner_risk_insurance_security.group_full_access_credit_policy_state") is simpler to write and read, and probably also slightly better in terms of performance.


@api.depends("user_id")
def _compute_is_full_access_user(self):
for partner in self:
Copy link

Choose a reason for hiding this comment

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

issue: You're not using any field of the partner. You don't need to recompute the value of the field for every partner, you can compute it once and then assign it to all.

Even better, you can assign it all at once for every partner:

self.is_full_access_user = ....

Comment on lines 7 to 8
<field name="inherit_id" ref="base.view_partner_form" />
<field name="priority" eval="50" />
Copy link

Choose a reason for hiding this comment

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

issue: The fields you're modifying do not exist in base.view_partner_form. I think you want to inherit from partner_risk_insurance.view_partner_form.

suggestion You can also drop the priority IMO, if you don't need it for anything in particular.

Copy link

Choose a reason for hiding this comment

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

Sorry, I realize it was ambiguous. By "drop" I meant "remove" the line where you specify the priority entirely.

Anyway, non-blocking.

@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!--Add risk insurance tab in partner form. -->
Copy link

Choose a reason for hiding this comment

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

chore: leftover comment from copy-pasting.

Comment on lines +12 to +61
<xpath expr="//field[@name='company_credit_limit']" position="attributes">
<attribute
name="attrs"
>{'readonly': [('is_full_access_user', '=', False)]}</attribute>
</xpath>
<xpath expr="//field[@name='insurance_credit_limit']" position="attributes">
<attribute
name="attrs"
>{'readonly': [('is_full_access_user', '=', False)]}</attribute>
</xpath>
<xpath
expr="//field[@name='risk_insurance_requested']"
position="attributes"
>
<attribute
name="attrs"
>{'readonly': [('is_full_access_user', '=', False)]}</attribute>
</xpath>
<xpath
expr="//field[@name='risk_insurance_grant_date']"
position="attributes"
>
<attribute
name="attrs"
>{'readonly': [('is_full_access_user', '=', False)]}</attribute>
</xpath>
<xpath
expr="//field[@name='risk_insurance_coverage_percent']"
position="attributes"
>
<attribute
name="attrs"
>{'readonly': [('is_full_access_user', '=', False)]}</attribute>
</xpath>
<xpath expr="//field[@name='risk_insurance_code']" position="attributes">
<attribute
name="attrs"
>{'readonly': [('is_full_access_user', '=', False)]}</attribute>
</xpath>
<xpath expr="//field[@name='risk_insurance_code_2']" position="attributes">
<attribute
name="attrs"
>{'readonly': [('is_full_access_user', '=', False)]}</attribute>
</xpath>
<xpath expr="//field[@name='credit_policy_state_id']" position="attributes">
<attribute
name="attrs"
>{'readonly': [('is_full_access_user', '=', False)]}</attribute>
</xpath>
<xpath expr="//field[@name='credit_policy_state_id']" position="after">
<field name="is_full_access_user" invisible="1" />
</xpath>
</field>
Copy link

Choose a reason for hiding this comment

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

question: can you add readonly directly on the <page name="credit_insurance position="attributes"> element instead of adding it on each field inside it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tried to do

<xpath expr="//page[@name='credit_insurance']" position="attributes">
                <attribute name="attrs">{'readonly': [('is_full_access_user', '=', False)]}</attribute>
            </xpath>

but it didn't work. I don't think that is possible to use the readonly attribute on a page

Copy link

Choose a reason for hiding this comment

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

Fair enough, thanks for checking!

Comment on lines 1 to 2
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_full_access_credit_policy_state,res.partner,base.model_res_partner,partner_risk_insurance_security.group_full_access_credit_policy_state,1,1,1,1
Copy link

Choose a reason for hiding this comment

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

issue: access to res.partner is already managed by other security groups, and is not strictly needed for this module to work. I'm not sure this specific groups needs to grant full CRUD access to res.partner.

My instinct would be to remove this file entirely.

@aleuffre
Copy link

aleuffre commented Nov 6, 2024

Also, not strictly needed for such a simple module IMO, but always nice to add a test, IMO.

@toita86 toita86 force-pushed the 14.0-IMP-partner_risk_insurance branch 2 times, most recently from c0fd637 to db00a4b Compare November 7, 2024 17:57
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, LGTM

0,
[
self.env.ref(
"partner_risk_insurance_security.group_full_access_credit_policy_state" # noqa: B950
Copy link

Choose a reason for hiding this comment

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

suggestion(non-blocking):

Suggested change
"partner_risk_insurance_security.group_full_access_credit_policy_state" # noqa: B950
"partner_risk_insurance_security."
"group_full_access_credit_policy_state"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion!

Copy link
Contributor

@carlosdauden carlosdauden left a comment

Choose a reason for hiding this comment

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

Code LGTM

Let's wait a bit before merging to see if the suggestions are heeded.

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@toita86 toita86 force-pushed the 14.0-IMP-partner_risk_insurance branch from db00a4b to 5ad4e88 Compare November 8, 2024 11:27
@carlosdauden
Copy link
Contributor

Thanks, ready to merge

@pedrobaeza
Copy link
Member

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 14.0-ocabot-merge-pr-403-by-pedrobaeza-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit e762825 into OCA:14.0 Nov 8, 2024
7 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 2b8623f. 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.

6 participants