-
-
Notifications
You must be signed in to change notification settings - Fork 273
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
[15.0][FIX] change role_line_ids default value to override create #305
base: 15.0
Are you sure you want to change the base?
[15.0][FIX] change role_line_ids default value to override create #305
Conversation
a4a829d
to
303a5b1
Compare
if not default_user: | ||
return | ||
role_lines = default_user.with_context(active_test=False).role_line_ids | ||
for user in record: |
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.
Not sure this is the most correct way todo it. But it does the job
This PR has the |
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 am not sure to understand the change.
From a UX point of view, when I create a user (through the form view) I expect to see the role lines pre-populated thanks to the default
attribute of the field, I can change them and then I expect these values to be stored as well when saving the form.
With the current changes we are losing this feature, roles will be populated when saving the form.
If your goal is to populate the roles when calling directly create
, you can rework the code without losing the existing feature. Also, you should not force the default user roles if vals
has them already set, only populate them if they were not set.
@api.model
def create(self, vals):
if "role_line_ids" not in vals:
# Populate roles from default user
return super().create(vals)
Test cases:
create({})
=> no role defined, we populate roles from the default usercreate({'role_line_ids': False})
=> we do not want to set any role on purpose, we do nothingcreate({'role_line_ids': [(6, 0, [IDs...]))}
=> roles have been defined with explicit values, same as previous example we do not add default user roles on top of that
35e4d5c
to
5b0117f
Compare
5b0117f
to
2582661
Compare
Syncing from upstream OCA/server-backend (16.0)
Populating role_line_ids this way doesn't work in this case. The previous method indeed return the right value but at creation, role_line_ids is empty in vals resulting of a new user having no role attributed even though the default_user has one.
Feature already has test. Test added for coverage.