Browse Source

[MIG] base_user_role_profile: Migration to 14.0

14.0
Pierrick Brun 4 years ago
committed by KevinKhao
parent
commit
ab546ebbd1
  1. 1
      base_user_role_profile/__init__.py
  2. 3
      base_user_role_profile/__manifest__.py
  3. 12
      base_user_role_profile/hooks.py
  4. 12
      base_user_role_profile/models/user.py
  5. 1
      base_user_role_profile/views/profile.xml

1
base_user_role_profile/__init__.py

@ -1 +1,2 @@
from . import models
from .hooks import post_init_hook

3
base_user_role_profile/__manifest__.py

@ -2,12 +2,13 @@
{
"name": "User profiles",
"version": "12.0.1.0.0",
"version": "14.0.1.0.0",
"category": "Tools",
"author": "Akretion, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/server-backend",
"depends": ["base_user_role", "web"],
"post_init_hook": "post_init_hook",
"data": [
"data/data.xml",
"security/ir.model.access.csv",

12
base_user_role_profile/hooks.py

@ -0,0 +1,12 @@
# Copyright 2020 Akretion (https://www.akretion.com).
# @author Pierrick Brun <pierrick.brun@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import SUPERUSER_ID, api
def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env["res.users"].search([("profile_id", "=", False)]).profile_id = env.ref(
"base_user_role_profile.default_profile"
)

12
base_user_role_profile/models/user.py

@ -6,12 +6,14 @@ class ResUsers(models.Model):
_inherit = "res.users"
def _get_default_profile(self):
return self.env.ref("base_user_role_profile.default_profile")
return self.env.ref(
"base_user_role_profile.default_profile", raise_if_not_found=False
)
profile_id = fields.Many2one(
"res.users.profile",
"Current profile",
default=lambda self: self._get_default_profile,
default=lambda self: self._get_default_profile(),
)
profile_ids = fields.Many2many(
@ -53,15 +55,15 @@ class ResUsers(models.Model):
self.sudo()._compute_profile_ids()
return res
def _get_applicable_roles(self):
res = super()._get_applicable_roles()
def _get_enabled_roles(self):
res = super()._get_enabled_roles()
res = res.filtered(
lambda r: not r.profile_id or (r.profile_id.id == r.user_id.profile_id.id)
)
return res
def _update_profile_id(self):
default_profile = self.env.ref("base_user_role_profile.default_profile")
default_profile = self._get_default_profile()
if not self.profile_ids:
if self.profile_id != default_profile:
self.profile_id = default_profile

1
base_user_role_profile/views/profile.xml

@ -31,7 +31,6 @@
<field name="name">User Profiles</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.users.profile</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_res_users_profile_tree" />
</record>

Loading…
Cancel
Save