Stefan Rijnhart
9 years ago
12 changed files with 157 additions and 20 deletions
-
19base_technical_features/README.rst
-
8base_technical_features/__openerp__.py
-
6base_technical_features/data/res_users.xml
-
25base_technical_features/i18n/nl.po
-
1base_technical_features/models/__init__.py
-
2base_technical_features/models/basemodel_monkeypatch.py
-
4base_technical_features/models/ir_ui_menu.py
-
59base_technical_features/models/res_users.py
-
1base_technical_features/security/res_groups.xml
-
BINbase_technical_features/static/description/user_preferences.png
-
36base_technical_features/tests/test_base_technical_features.py
-
16base_technical_features/views/res_users.xml
@ -1,15 +1,17 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
# © 2016 Opener B.V. |
|
||||
|
# coding: utf-8 |
||||
|
# © 2016 Opener B.V. (<https://opener.am>) |
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
{ |
{ |
||||
"name": "Technical features group", |
"name": "Technical features group", |
||||
"summary": "Access to technical features without activating debug mode", |
"summary": "Access to technical features without activating debug mode", |
||||
"version": "9.0.1.0.0", |
"version": "9.0.1.0.0", |
||||
"category": "Usability", |
"category": "Usability", |
||||
"website": "https://odoo-community.org/", |
|
||||
|
"website": "https://github.com/oca/server-tools", |
||||
"author": "Opener B.V., Odoo Community Association (OCA)", |
"author": "Opener B.V., Odoo Community Association (OCA)", |
||||
"data": [ |
"data": [ |
||||
'security/res_groups.xml', |
'security/res_groups.xml', |
||||
|
'views/res_users.xml', |
||||
|
'data/res_users.xml', |
||||
], |
], |
||||
"license": "AGPL-3", |
"license": "AGPL-3", |
||||
"installable": True, |
"installable": True, |
||||
|
@ -0,0 +1,6 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8" ?> |
||||
|
<odoo noupdate="1"> |
||||
|
<record model="res.users" id="base.user_root"> |
||||
|
<field name="technical_features" eval="True" /> |
||||
|
</record> |
||||
|
</odoo> |
@ -1,2 +1,3 @@ |
|||||
from . import basemodel_monkeypatch |
from . import basemodel_monkeypatch |
||||
from . import ir_ui_menu |
from . import ir_ui_menu |
||||
|
from . import res_users |
@ -0,0 +1,59 @@ |
|||||
|
# coding: utf-8 |
||||
|
# © 2016 Opener B.V. (<https://opener.am>) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
from openerp import api, fields, models |
||||
|
from openerp.exceptions import AccessError |
||||
|
from openerp.tools.translate import _ |
||||
|
|
||||
|
|
||||
|
class ResUsers(models.Model): |
||||
|
_inherit = 'res.users' |
||||
|
|
||||
|
technical_features = fields.Boolean( |
||||
|
compute='get_technical_features', |
||||
|
inverse='set_technical_features') |
||||
|
show_technical_features = fields.Boolean( |
||||
|
string='Show field Technical Features', |
||||
|
compute='get_show_technical_features', |
||||
|
help=('Whether to display the technical features field in the user ' |
||||
|
'preferences.')) |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends('groups_id') |
||||
|
def get_show_technical_features(self): |
||||
|
""" Only display the technical features checkbox in the user |
||||
|
preferences if the user has access to them """ |
||||
|
users = self.env.ref('base.group_no_one').users |
||||
|
for user in self: |
||||
|
user.show_technical_features = user in users |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends('groups_id') |
||||
|
def get_technical_features(self): |
||||
|
""" Map user membership to boolean field value """ |
||||
|
users = self.env.ref( |
||||
|
'base_technical_features.group_technical_features').users |
||||
|
for user in self: |
||||
|
user.technical_features = user in users |
||||
|
|
||||
|
@api.multi |
||||
|
def set_technical_features(self): |
||||
|
""" Map boolean field value to group membership, but checking |
||||
|
access """ |
||||
|
group = self.env.ref( |
||||
|
'base_technical_features.group_technical_features') |
||||
|
for user in self: |
||||
|
if self.env.ref('base.group_no_one') not in user.groups_id: |
||||
|
raise AccessError( |
||||
|
_('The user does not have access to technical ' |
||||
|
'features.')) |
||||
|
if user.technical_features: |
||||
|
self.sudo().write({'groups_id': [(4, group.id)]}) |
||||
|
else: |
||||
|
self.sudo().write({'groups_id': [(3, group.id)]}) |
||||
|
|
||||
|
def __init__(self, pool, cr): |
||||
|
super(ResUsers, self).__init__(pool, cr) |
||||
|
self.SELF_READABLE_FIELDS += [ |
||||
|
'technical_features', 'show_technical_features'] |
||||
|
self.SELF_WRITEABLE_FIELDS.append('technical_features') |
After Width: 594 | Height: 357 | Size: 30 KiB |
@ -0,0 +1,16 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<record id="view_users_form_simple_modif" model="ir.ui.view"> |
||||
|
<field name="name">Add technical features checkbox to user preferences form</field> |
||||
|
<field name="model">res.users</field> |
||||
|
<field name="inherit_id" ref="base.view_users_form_simple_modif" /> |
||||
|
<field name="arch" type="xml"> |
||||
|
<field name="company_id" position="after"> |
||||
|
<field name="technical_features" readonly="0" |
||||
|
attrs="{'invisible': [('show_technical_features', '=', False)]}" /> |
||||
|
<field name="show_technical_features" invisible="1" /> |
||||
|
</field> |
||||
|
</field> |
||||
|
</record> |
||||
|
</odoo> |
||||
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue