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

[15.0][FIX] change role_line_ids default value to override create #305

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from

Conversation

PaoloYam
Copy link

@PaoloYam PaoloYam commented Aug 21, 2024

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.

@OCA-git-bot
Copy link
Contributor

Hi @novawish, @sebalix, @jcdrubay,
some modules you are maintaining are being modified, check this out!

@PaoloYam PaoloYam force-pushed the 15.0-change-default-value-role-line-ids-for-override-create branch 8 times, most recently from a4a829d to 303a5b1 Compare August 21, 2024 11:54
if not default_user:
return
role_lines = default_user.with_context(active_test=False).role_line_ids
for user in record:

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

@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). 🤖

Copy link
Contributor

@sebalix sebalix left a 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 user
  • create({'role_line_ids': False}) => we do not want to set any role on purpose, we do nothing
  • create({'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

@PaoloYam PaoloYam force-pushed the 15.0-change-default-value-role-line-ids-for-override-create branch 2 times, most recently from 35e4d5c to 5b0117f Compare September 2, 2024 12:41
@PaoloYam PaoloYam force-pushed the 15.0-change-default-value-role-line-ids-for-override-create branch from 5b0117f to 2582661 Compare September 2, 2024 12:51
SiesslPhillip pushed a commit to grueneerde/OCA-server-backend that referenced this pull request Nov 20, 2024
Syncing from upstream OCA/server-backend (16.0)
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.

5 participants