Browse Source

publish muk_utils - 12.0

pull/9/head
MuK IT GmbH 6 years ago
parent
commit
e2ea8517e3
  1. 3
      muk_utils/__manifest__.py
  2. 1
      muk_utils/models/__init__.py
  3. 110
      muk_utils/models/groups.py
  4. 96
      muk_utils/views/groups.xml

3
muk_utils/__manifest__.py

@ -20,7 +20,7 @@
{
"name": "MuK Utils",
"summary": """Utility Features""",
"version": '12.0.1.1.1',
"version": '12.0.1.1.2',
"category": 'Extra Tools',
"license": "AGPL-3",
"author": "MuK IT",
@ -33,6 +33,7 @@
"base_setup",
],
"data": [
"views/groups.xml",
"views/res_config_settings_view.xml",
],
"qweb": [

1
muk_utils/models/__init__.py

@ -17,6 +17,7 @@
#
###################################################################################
from . import groups
from . import ir_attachment
from . import res_config_settings

110
muk_utils/models/groups.py

@ -0,0 +1,110 @@
###################################################################################
#
# Copyright (C) 2017 MuK IT GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###################################################################################
from odoo import models, fields, api
class Groups(models.AbstractModel):
_name = 'muk_utils.groups'
_parent_store = True
_parent_name = "parent_group"
#----------------------------------------------------------
# Database
#----------------------------------------------------------
name = fields.Char(
string="Group Name",
required=True,
translate=True)
parent_path = fields.Char(
string="Parent Path",
index=True)
count_users = fields.Integer(
compute='_compute_users',
string="Users",
store=True)
@api.model
def _add_magic_fields(self):
super(Groups, self)._add_magic_fields()
def add(name, field):
if name not in self._fields:
self._add_field(name, field)
base, model = self._name.split(".")
add('parent_group', fields.Many2one(
_module=base,
comodel_name=self._name,
string='Parent Group',
ondelete='cascade',
auto_join=True,
index=True,
automatic=True))
add('child_groups', fields.One2many(
_module=base,
comodel_name=self._name,
inverse_name='parent_group',
string='Child Groups',
automatic=True))
add('groups', fields.Many2many(
_module=base,
comodel_name='res.groups',
relation='%s_groups_rel' % (self._table),
column1='gid',
column2='rid',
string='Groups',
automatic=True))
add('explicit_users', fields.Many2many(
_module=base,
comodel_name='res.users',
relation='%s_explicit_users_rel' % (self._table),
column1='gid',
column2='uid',
string='Explicit Users',
automatic=True))
add('users', fields.Many2many(
_module=base,
comodel_name='res.users',
relation='%s_users_rel' % (self._table),
column1='gid',
column2='uid',
string='Users',
compute='_compute_users',
store=True,
automatic=True))
_sql_constraints = [
('name_uniq', 'unique (name)', 'The name of the group must be unique!')
]
#----------------------------------------------------------
# Read, View
#----------------------------------------------------------
@api.depends('parent_group.users', 'groups', 'groups.users', 'explicit_users')
def _compute_users(self):
print(self)
for record in self:
users = record.mapped('groups.users')
users |= record.mapped('explicit_users')
users |= record.mapped('parent_group.users')
record.update({'users': users, 'count_users': len(users)})

96
muk_utils/views/groups.xml

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2017 MuK IT GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<odoo>
<record id="view_groups_tree" model="ir.ui.view">
<field name="name">muk_utils_groups.tree</field>
<field name="model">muk_utils.groups</field>
<field name="arch" type="xml">
<tree string="Groups">
<field name="name" />
<field name="count_users" />
</tree>
</field>
</record>
<record id="view_groups_form" model="ir.ui.view">
<field name="name">muk_utils_groups.form</field>
<field name="model">muk_utils.groups</field>
<field name="arch" type="xml">
<form string="Group">
<sheet>
<div class="oe_title">
<label for="name" class="oe_edit_only" />
<h1>
<field name="name" />
</h1>
</div>
<group name="group" string="Group">
<group>
<field name="parent_group" />
</group>
<group>
<field name="count_users" />
</group>
</group>
<notebook>
<page name="users" string="Users">
<field name="users">
<tree string="Users">
<field name="name" />
<field name="login" />
<field name="lang" />
<field name="login_date" />
</tree>
</field>
</page>
<page name="groups" string="Groups">
<field name="groups">
<tree string="Groups">
<field name="name" />
<field name="comment" />
</tree>
</field>
</page>
<page name="extra_users" string="Explicit Users">
<field name="explicit_users">
<tree string="Explicit Users">
<field name="name" />
<field name="login" />
<field name="lang" />
<field name="login_date" />
</tree>
</field>
</page>
<page name="childs" string="Child Groups">
<field name="child_groups">
<tree string="Groups">
<field name="name" />
<field name="count_users" />
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
</odoo>
Loading…
Cancel
Save