OCA / operating-unit

Manage Operating Units in Odoo
GNU Affero General Public License v3.0
72 stars 237 forks source link

16.0-operating_unit: All OU addes to res users when groups_id change. #628

Closed jado95 closed 4 months ago

jado95 commented 10 months ago

All operating units added to res.user when edit any group. PR: #629

Module

operating_unit

Describe the bug

Odoo v16, multicompany database. On user form, when change group for that user, all operating unit are automatically added to field operating_unit_ids (Allowed Operating Units). I debug this code:

@api.depends("groups_id", "assigned_operating_unit_ids")
    def _compute_operating_unit_ids(self):
        for user in self:
            if user.has_group("operating_unit.group_manager_operating_unit"):
                dom = []
                if self.env.context.get("allowed_company_ids"):
                    dom = [
                        "|",
                        ("company_id", "=", False),
                        ("company_id", "in", self.env.context["allowed_company_ids"]),
                    ]
                else:
                    dom = []
                user.operating_unit_ids = self.env["operating.unit"].sudo().search(dom)
            else:
                user.operating_unit_ids = user.assigned_operating_unit_ids

And user = res.users(,). With this result, has_group("operating_unit.group_manager_operating_unit") always return True. I don't know why the result of user is this, but with user._origin.has_group("operating_unit.group_manager_operating_unit") everything seems to work. Anyone encountering the same problem?

github-actions[bot] commented 4 months ago

There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. If you want this issue to never become stale, please ask a PSC member to apply the "no stale" label.