Browse Source

[IMP] Some improvements and fixes

pull/340/head
mreficent 6 years ago
parent
commit
a53d1551fb
  1. 70
      mail_activity_team/models/mail_activity.py
  2. 69
      mail_activity_team/models/mail_activity_team.py
  3. 8
      mail_activity_team/models/res_users.py
  4. 2
      mail_activity_team/security/ir.model.access.csv
  5. 4
      mail_activity_team/security/mail_activity_team_security.xml
  6. 16
      mail_activity_team/views/mail_activity_team_views.xml

70
mail_activity_team/models/mail_activity.py

@ -1,34 +1,66 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models, fields
from odoo import api, models, fields, _
from odoo.exceptions import ValidationError
class MailActivity(models.Model):
_inherit = "mail.activity"
def _get_default_team_id(self):
res_model = self.env.context.get('default_res_model', False)
model = self.env['ir.model'].search([('model', '=', res_model)],
limit=1)
domain = [('member_ids', 'in', [self.env.uid])]
def _get_default_team_id(self, user_id=None):
if not user_id:
user_id = self.env.uid
res_model = self.env.context.get('default_res_model')
model = self.env['ir.model'].search(
[('model', '=', res_model)], limit=1)
domain = [('member_ids', 'in', [user_id])]
if res_model:
domain.extend(['|', ('res_model_ids', '=', False),
('res_model_ids', 'in', model.ids)])
return self.env['mail.activity.team'].search(domain, limit=1)
team_id = fields.Many2one('mail.activity.team',
default=lambda s: s._get_default_team_id(),)
team_id = fields.Many2one(
comodel_name='mail.activity.team',
default=lambda s: s._get_default_team_id(),
)
@api.onchange('res_model_id', 'user_id')
def _onchange_model_user(self):
@api.onchange('user_id')
def _onchange_user_id(self):
res = {'domain': {'team_id': []}}
if self.team_id:
if self.user_id not in self.team_id.member_ids:
self.team_id = False
if self.res_model_id:
res['domain']['team_id'] = [
('res_model_ids', 'in', self.res_model_id.ids)]
if self.user_id:
res['domain']['team_id'] = [
('member_ids', 'in', self.user_id.ids)]
if not self.user_id:
return res
res['domain']['team_id'] = [
'|',
('res_model_ids', '=', False),
('res_model_ids', 'in', self.res_model_id.ids)]
if self.team_id and self.user_id in self.team_id.member_ids:
return res
self.team_id = self.with_context(
default_res_model=self.res_model_id.id).\
_get_default_team_id(user_id=self.user_id.id)
return res
@api.onchange('team_id')
def _onchange_team_id(self):
res = {'domain': {'user_id': []}}
if not self.team_id:
return res
res['domain']['user_id'] = [('id', 'in', self.team_id.member_ids.ids)]
if self.user_id and self.user_id in self.team_id.member_ids:
return res
if self.team_id.user_id:
self.user_id = self.team_id.user_id
elif self.env.user in self.team_id.member_ids.ids:
self.user_id = self.env.user
else:
self.user_id = self.env['res.users']
return res
@api.multi
@api.constrains('team_id', 'user_id')
def _check_team_and_user(self):
for activity in self:
if activity.team_id and activity.user_id and \
activity.user_id not in self.team_id.member_ids:
raise ValidationError(
_('The assigned user is not member of the team.'))

69
mail_activity_team/models/mail_activity_team.py

@ -1,14 +1,71 @@
# Copyright 2018 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
from odoo import api, fields, models
class MailActivityTeam(models.Model):
_name = "mail.activity.team"
_description = 'Mail Activity Team'
name = fields.Char(string='Name', required=True, translate=True)
active = fields.Boolean(string='Active', default=True)
res_model_ids = fields.Many2many('ir.model', string='Used models')
member_ids = fields.Many2many('res.users', 'mail_activity_team_users_rel',
string="Team Members")
@api.depends('res_model_ids', 'member_ids')
def _compute_missing_activities(self):
activity_model = self.env['mail.activity']
for team in self:
domain = [('team_id', '=', False)]
if team.member_ids:
domain.append(('user_id', 'in', team.member_ids.ids))
if team.res_model_ids:
domain.append(('res_model_id', 'in', team.res_model_ids.ids))
team.count_missing_activities = activity_model.search(
domain, count=True)
name = fields.Char(
string='Name',
required=True,
translate=True,
)
active = fields.Boolean(
string='Active',
default=True,
)
res_model_ids = fields.Many2many(
comodel_name='ir.model',
string='Used models',
domain=lambda self: [
('model', 'in',
[k for k in self.env.registry if issubclass(
type(self.env[k]), type(self.env['mail.activity.mixin']))
and self.env[k]._auto])
],
)
member_ids = fields.Many2many(
comodel_name='res.users',
relation='mail_activity_team_users_rel',
string="Team Members",
)
user_id = fields.Many2one(
comodel_name='res.users',
string='Team Leader',
domain="[('id', 'in', member_ids)]",
)
count_missing_activities = fields.Integer(
string="Missing Activities",
compute='_compute_missing_activities',
default=0,
)
@api.onchange('member_ids')
def _onchange_member_ids(self):
if self.user_id and self.user_id not in self.member_ids:
self.user_id = False
def assign_team_to_unassigned_activities(self):
activity_model = self.env['mail.activity']
for team in self:
domain = [('team_id', '=', False)]
if team.member_ids:
domain.append(('user_id', 'in', team.member_ids.ids))
if team.res_model_ids:
domain.append(('res_model_id', 'in', team.res_model_ids.ids))
missing_activities = activity_model.search(domain)
missing_activities.write({'team_id': team.id})

8
mail_activity_team/models/res_users.py

@ -6,6 +6,8 @@ from odoo import models, fields
class ResUsers(models.Model):
_inherit = "res.users"
activity_team_ids = fields.Many2many('mail.activity.team',
'mail_activity_team_users_rel',
string="Activity Teams")
activity_team_ids = fields.Many2many(
comodel_name='mail.activity.team',
relation='mail_activity_team_users_rel',
string="Activity Teams",
)

2
mail_activity_team/security/ir.model.access.csv

@ -1,4 +1,4 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
access_mail_activity_team_all,mail.activity.team.all,model_mail_activity_team,,1,0,0,0
access_mail_activity_team_user,mail.activity.team.user,model_mail_activity_team,base.group_user,1,1,0,0
access_mail_activity_team_system_user,mail.activity.team.system.user,model_mail_activity_team,base.group_system_user,1,1,1,1
access_mail_activity_team_system_user,mail.activity.team.system.user,model_mail_activity_team,base.group_system,1,1,1,1

4
mail_activity_team/security/mail_activity_team_security.xml

@ -4,10 +4,10 @@
<record id="mail_activity_rule_my_team" model="ir.rule">
<field name="name">mail.activity: user: my team</field>
<field name="model_id" ref="mail.model_mail_activity"/>
<field name="domain_force">['|', '&amp;'('team_id', '=', False),('user_id', '=', user.id),('team_id', '=', user.team_ids.ids)]</field>
<field name="domain_force">["|", ('team_id', 'in', user.activity_team_ids.ids), "&amp;", ('team_id', '=', False), ('user_id', '=', user.id)]</field>
<field name="groups" eval="[(4, ref('base.group_user'))]"/>
<field name="perm_create" eval="True"/>
<field name="perm_read" eval="True"/>
<field name="perm_read" eval="False"/>
<field name="perm_write" eval="True"/>
<field name="perm_unlink" eval="True"/>
</record>

16
mail_activity_team/views/mail_activity_team_views.xml

@ -4,26 +4,34 @@
VIEWS
-->
<!-- FORM VIEW -->
<record id="mail_activity_team_view_form" model="ir.ui.view">
<field name="name">mail.activity.team.view.form</field>
<field name="model">mail.activity.team</field>
<field name="arch" type="xml">
<form string="Activity Team">
<header>
<field name="count_missing_activities" invisible="1"/>
<button name="assign_team_to_unassigned_activities" string="Assign to missing activities"
type="object" class="oe_highlight"
groups="base.group_no_one"
attrs="{'invisible': [('count_missing_activities', '=', 0)]}"/>
</header>
<sheet string="Activity Team">
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object"
class="oe_stat_button" icon="fa-archive">
class="oe_stat_button" icon="fa-archive">
<field name="active" widget="boolean_button"
options='{"terminology": "archive"}'/></button>
options='{"terminology": "archive"}'/></button>
</div>
<group>
<group name="base">
<field name="name"/>
<field name="user_id" attrs="{'invisible': [('member_ids', '=', [])]}"/>
</group>
<group name="models">
<field name="res_model_ids" widget="many2many_tags"/>
<field name="res_model_ids" widget="many2many_tags"
options="{'no_create': True, 'no_open': True}"/>
</group>
</group>
<notebook>

Loading…
Cancel
Save