mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[MIG] base_user_role: Migration to 11.0
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
:target: https://www.gnu.org/licenses/agpl
|
||||||
:alt: License: AGPL-3
|
:alt: License: AGPL-3
|
||||||
|
|
||||||
==========
|
==========
|
||||||
@@ -51,7 +51,7 @@ Bug Tracker
|
|||||||
Bugs are tracked on `GitHub Issues
|
Bugs are tracked on `GitHub Issues
|
||||||
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
|
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
|
||||||
check there if your issue has already been reported. If you spotted it first,
|
check there if your issue has already been reported. If you spotted it first,
|
||||||
help us smashing it by providing a detailed and welcomed feedback.
|
help us smash it by providing detailed and welcomed feedback.
|
||||||
|
|
||||||
Credits
|
Credits
|
||||||
=======
|
=======
|
||||||
@@ -65,6 +65,7 @@ Contributors
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
* Sébastien Alix <sebastien.alix@osiell.com>
|
* Sébastien Alix <sebastien.alix@osiell.com>
|
||||||
|
* Duc, Dao Dong <duc.dd@komit-consulting.com> (https://komit-consulting.com)
|
||||||
|
|
||||||
Maintainer
|
Maintainer
|
||||||
----------
|
----------
|
||||||
|
|||||||
@@ -1,3 +1 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright 2014 ABF OSIELL <http://osiell.com>
|
# Copyright 2014 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'User roles',
|
'name': 'User roles',
|
||||||
'version': '10.0.1.0.0',
|
'version': '11.0.1.0.0',
|
||||||
'category': 'Tools',
|
'category': 'Tools',
|
||||||
'author': 'ABF OSIELL, Odoo Community Association (OCA)',
|
'author': 'ABF OSIELL, Odoo Community Association (OCA)',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
@@ -15,8 +14,8 @@
|
|||||||
],
|
],
|
||||||
'data': [
|
'data': [
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'data/ir_module_category.xml',
|
|
||||||
'data/ir_cron.xml',
|
'data/ir_cron.xml',
|
||||||
|
'data/ir_module_category.xml',
|
||||||
'views/role.xml',
|
'views/role.xml',
|
||||||
'views/user.xml',
|
'views/user.xml',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -9,9 +9,10 @@
|
|||||||
<field name='interval_type'>hours</field>
|
<field name='interval_type'>hours</field>
|
||||||
<field name="numbercall">-1</field>
|
<field name="numbercall">-1</field>
|
||||||
<field name="active">True</field>
|
<field name="active">True</field>
|
||||||
<field name="doall" eval="False" />
|
<field name="doall" eval="False"/>
|
||||||
<field name="model">res.users.role</field>
|
<field name="model_id" ref="base_user_role.model_res_users_role"/>
|
||||||
<field name="function">cron_update_users</field>
|
<field name="state">code</field>
|
||||||
|
<field name="code">model.cron_update_users()</field>
|
||||||
<field name="args">()</field>
|
<field name="args">()</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from . import role
|
from . import role
|
||||||
from . import user
|
from . import user
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright 2014 ABF OSIELL <http://osiell.com>
|
# Copyright 2014 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@@ -17,12 +15,14 @@ class ResUsersRole(models.Model):
|
|||||||
_description = "User role"
|
_description = "User role"
|
||||||
|
|
||||||
group_id = fields.Many2one(
|
group_id = fields.Many2one(
|
||||||
'res.groups', required=True, ondelete='cascade',
|
comodel_name='res.groups', required=True, ondelete='cascade',
|
||||||
readonly=True, string=u"Associated group")
|
readonly=True, string="Associated group")
|
||||||
line_ids = fields.One2many(
|
line_ids = fields.One2many(
|
||||||
'res.users.role.line', 'role_id', string=u"Users")
|
comodel_name='res.users.role.line',
|
||||||
|
inverse_name='role_id', string="Users")
|
||||||
user_ids = fields.One2many(
|
user_ids = fields.One2many(
|
||||||
'res.users', string=u"Users", compute='_compute_user_ids')
|
comodel_name='res.users', string="Users",
|
||||||
|
compute='_compute_user_ids')
|
||||||
group_category_id = fields.Many2one(
|
group_category_id = fields.Many2one(
|
||||||
related='group_id.category_id',
|
related='group_id.category_id',
|
||||||
default=lambda cls: cls.env.ref(
|
default=lambda cls: cls.env.ref(
|
||||||
@@ -55,7 +55,7 @@ class ResUsersRole(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def cron_update_users(self):
|
def cron_update_users(self):
|
||||||
logging.info(u"Update user roles")
|
logging.info("Update user roles")
|
||||||
self.search([]).update_users()
|
self.search([]).update_users()
|
||||||
|
|
||||||
|
|
||||||
@@ -64,12 +64,13 @@ class ResUsersRoleLine(models.Model):
|
|||||||
_description = 'Users associated to a role'
|
_description = 'Users associated to a role'
|
||||||
|
|
||||||
role_id = fields.Many2one(
|
role_id = fields.Many2one(
|
||||||
'res.users.role', string=u"Role", ondelete='cascade')
|
comodel_name='res.users.role', string="Role",
|
||||||
|
ondelete='cascade')
|
||||||
user_id = fields.Many2one(
|
user_id = fields.Many2one(
|
||||||
'res.users', string=u"User")
|
comodel_name='res.users', string="User")
|
||||||
date_from = fields.Date(u"From")
|
date_from = fields.Date("From")
|
||||||
date_to = fields.Date(u"To")
|
date_to = fields.Date("To")
|
||||||
is_enabled = fields.Boolean(u"Enabled", compute='_compute_is_enabled')
|
is_enabled = fields.Boolean("Enabled", compute='_compute_is_enabled')
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.depends('date_from', 'date_to')
|
@api.depends('date_from', 'date_to')
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright 2014 ABF OSIELL <http://osiell.com>
|
# Copyright 2014 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
@@ -9,9 +7,11 @@ class ResUsers(models.Model):
|
|||||||
_inherit = 'res.users'
|
_inherit = 'res.users'
|
||||||
|
|
||||||
role_line_ids = fields.One2many(
|
role_line_ids = fields.One2many(
|
||||||
'res.users.role.line', 'user_id', string=u"Role lines")
|
comodel_name='res.users.role.line',
|
||||||
|
inverse_name='user_id', string="Role lines")
|
||||||
role_ids = fields.One2many(
|
role_ids = fields.One2many(
|
||||||
'res.users.role', string=u"Roles", compute='_compute_role_ids')
|
comodel_name='res.users.role', string="Roles",
|
||||||
|
compute='_compute_role_ids')
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.depends('role_line_ids.role_id')
|
@api.depends('role_line_ids.role_id')
|
||||||
|
|||||||
@@ -1,3 +1 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from . import test_user_role
|
from . import test_user_role
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright 2014 ABF OSIELL <http://osiell.com>
|
# Copyright 2014 ABF OSIELL <http://osiell.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
|
from odoo import fields
|
||||||
from odoo.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
|
|
||||||
|
|
||||||
@@ -16,13 +14,13 @@ class TestUserRole(TransactionCase):
|
|||||||
self.role_model = self.env['res.users.role']
|
self.role_model = self.env['res.users.role']
|
||||||
|
|
||||||
self.user_id = self.user_model.create(
|
self.user_id = self.user_model.create(
|
||||||
{'name': u"USER TEST (ROLES)", 'login': 'user_test_roles'})
|
{'name': "USER TEST (ROLES)", 'login': 'user_test_roles'})
|
||||||
|
|
||||||
# ROLE_1
|
# ROLE_1
|
||||||
self.group_user_id = self.env.ref('base.group_user')
|
self.group_user_id = self.env.ref('base.group_user')
|
||||||
self.group_no_one_id = self.env.ref('base.group_no_one')
|
self.group_no_one_id = self.env.ref('base.group_no_one')
|
||||||
vals = {
|
vals = {
|
||||||
'name': u"ROLE_1",
|
'name': "ROLE_1",
|
||||||
'implied_ids': [
|
'implied_ids': [
|
||||||
(6, 0, [self.group_user_id.id, self.group_no_one_id.id])],
|
(6, 0, [self.group_user_id.id, self.group_no_one_id.id])],
|
||||||
}
|
}
|
||||||
@@ -33,7 +31,7 @@ class TestUserRole(TransactionCase):
|
|||||||
'base.group_multi_currency')
|
'base.group_multi_currency')
|
||||||
self.group_settings_id = self.env.ref('base.group_system')
|
self.group_settings_id = self.env.ref('base.group_system')
|
||||||
vals = {
|
vals = {
|
||||||
'name': u"ROLE_2",
|
'name': "ROLE_2",
|
||||||
'implied_ids': [
|
'implied_ids': [
|
||||||
(6, 0, [self.group_multi_currency_id.id,
|
(6, 0, [self.group_multi_currency_id.id,
|
||||||
self.group_settings_id.id])],
|
self.group_settings_id.id])],
|
||||||
@@ -76,10 +74,10 @@ class TestUserRole(TransactionCase):
|
|||||||
self.assertEqual(user_group_ids, role_group_ids)
|
self.assertEqual(user_group_ids, role_group_ids)
|
||||||
|
|
||||||
def test_role_1_2_with_dates(self):
|
def test_role_1_2_with_dates(self):
|
||||||
today = datetime.date.today()
|
today_str = fields.Date.today()
|
||||||
today_str = today.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
today = fields.Date.from_string(today_str)
|
||||||
yesterday = today - datetime.timedelta(days=1)
|
yesterday = today - datetime.timedelta(days=1)
|
||||||
yesterday_str = yesterday.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
yesterday_str = fields.Date.to_string(yesterday)
|
||||||
self.user_id.write(
|
self.user_id.write(
|
||||||
{'role_line_ids': [
|
{'role_line_ids': [
|
||||||
# Role 1 should be enabled
|
# Role 1 should be enabled
|
||||||
|
|||||||
Reference in New Issue
Block a user