mreficent
6 years ago
6 changed files with 134 additions and 35 deletions
-
66mail_activity_team/models/mail_activity.py
-
69mail_activity_team/models/mail_activity_team.py
-
8mail_activity_team/models/res_users.py
-
2mail_activity_team/security/ir.model.access.csv
-
4mail_activity_team/security/mail_activity_team_security.xml
-
12mail_activity_team/views/mail_activity_team_views.xml
@ -1,34 +1,66 @@ |
|||||
# Copyright 2018 Eficent Business and IT Consulting Services, S.L. |
# Copyright 2018 Eficent Business and IT Consulting Services, S.L. |
||||
# 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). |
||||
from odoo import api, models, fields |
|
||||
|
from odoo import api, models, fields, _ |
||||
|
from odoo.exceptions import ValidationError |
||||
|
|
||||
|
|
||||
class MailActivity(models.Model): |
class MailActivity(models.Model): |
||||
_inherit = "mail.activity" |
_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: |
if res_model: |
||||
domain.extend(['|', ('res_model_ids', '=', False), |
domain.extend(['|', ('res_model_ids', '=', False), |
||||
('res_model_ids', 'in', model.ids)]) |
('res_model_ids', 'in', model.ids)]) |
||||
return self.env['mail.activity.team'].search(domain, limit=1) |
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': []}} |
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: |
|
||||
|
if not self.user_id: |
||||
|
return res |
||||
res['domain']['team_id'] = [ |
res['domain']['team_id'] = [ |
||||
|
'|', |
||||
|
('res_model_ids', '=', False), |
||||
('res_model_ids', 'in', self.res_model_id.ids)] |
('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 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 |
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.')) |
@ -1,14 +1,71 @@ |
|||||
# Copyright 2018 Eficent Business and IT Consulting Services, S.L. |
# Copyright 2018 Eficent Business and IT Consulting Services, S.L. |
||||
# 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). |
||||
from odoo import fields, models |
|
||||
|
from odoo import api, fields, models |
||||
|
|
||||
|
|
||||
class MailActivityTeam(models.Model): |
class MailActivityTeam(models.Model): |
||||
_name = "mail.activity.team" |
_name = "mail.activity.team" |
||||
_description = '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}) |
@ -1,4 +1,4 @@ |
|||||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" |
"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_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_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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue