-
-
Notifications
You must be signed in to change notification settings - Fork 199
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
Conversation
Hi @Daniel-CA, @sergio-teruel, @omar7r, @Tardo, |
a3f9d30
to
b6084af
Compare
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). |
f710520
to
2df0fbd
Compare
A usual suffix is |
Thanks for the info! |
024076f
to
7a77449
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!
store=False, | ||
) | ||
|
||
@api.depends("user_id") |
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.
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')
partner.is_full_access_user = ( | ||
self.env.user | ||
in self.env.ref( | ||
"partner_risk_insurance_security.group_full_access_credit_policy_state" | ||
).users | ||
) |
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.
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: |
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.
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 = ....
<field name="inherit_id" ref="base.view_partner_form" /> | ||
<field name="priority" eval="50" /> |
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.
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.
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.
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. --> |
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.
chore: leftover comment from copy-pasting.
<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> |
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.
question: can you add readonly
directly on the <page name="credit_insurance position="attributes">
element instead of adding it on each field inside it?
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.
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
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.
Fair enough, thanks for checking!
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 |
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.
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.
Also, not strictly needed for such a simple module IMO, but always nice to add a test, IMO. |
c0fd637
to
db00a4b
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.
Code review, LGTM
0, | ||
[ | ||
self.env.ref( | ||
"partner_risk_insurance_security.group_full_access_credit_policy_state" # noqa: B950 |
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.
suggestion(non-blocking):
"partner_risk_insurance_security.group_full_access_credit_policy_state" # noqa: B950 | |
"partner_risk_insurance_security." | |
"group_full_access_credit_policy_state" |
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.
Thank you for the suggestion!
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 LGTM
Let's wait a bit before merging to see if the suggestions are heeded.
This PR has the |
db00a4b
to
5ad4e88
Compare
Thanks, ready to merge |
/ocabot merge nobump |
What a great day to merge this nice PR. Let's do it! |
Congratulations, your PR was merged at 2b8623f. Thanks a lot for contributing to OCA. ❤️ |
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.