diff --git a/mail_activity_team/README.rst b/mail_activity_team/README.rst new file mode 100644 index 00000000..ae233e3b --- /dev/null +++ b/mail_activity_team/README.rst @@ -0,0 +1,99 @@ +================== +Mail Activity Team +================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/12.0/mail_activity_team + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-12-0/social-12-0-mail_activity_team + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/205/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds the possibility to assign teams to activities. + + + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To set up new teams: + +#. Go to *Settings / Activate developer mode* +#. Go to *Settings / Technical / Email / Activity Teams* +#. Create a new Team and assign (optionally) the models in which it will + be used, and the members of the team. + +You can also assign a user to Activity teams going to +*Settings / Users & Companies / Users*, and in the *Preferences* tab, field +Activity Teams. + +When you create a new activity the application will propose the user's +assigned team. + +You can report on the activities assigned to a team going to +*Dashboards / Activities*, and then filter by a specific team or group by +teams. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Eficent + +Contributors +~~~~~~~~~~~~ + +* `Eficent `_: + + * Jordi Ballester Alomar (jordi.ballester@eficent.com) + * Miquel Raïch (miquel.raich@eficent.com) + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_activity_team/__init__.py b/mail_activity_team/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/mail_activity_team/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_activity_team/__manifest__.py b/mail_activity_team/__manifest__.py new file mode 100644 index 00000000..b4f77335 --- /dev/null +++ b/mail_activity_team/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2018 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': 'Mail Activity Team', + 'summary': 'Add Teams to Activities', + 'version': '12.0.1.0.0', + 'development_status': 'Beta', + 'category': 'Social Network', + 'website': 'https://github.com/OCA/social', + 'author': 'Eficent, Odoo Community Association (OCA)', + 'license': 'AGPL-3', + 'installable': True, + 'depends': [ + 'mail_activity_board', + ], + 'data': [ + 'security/ir.model.access.csv', + 'security/mail_activity_team_security.xml', + 'views/mail_activity_team_views.xml', + 'views/mail_activity_views.xml', + 'views/res_users_views.xml', + ], +} diff --git a/mail_activity_team/models/__init__.py b/mail_activity_team/models/__init__.py new file mode 100644 index 00000000..2f37e6cc --- /dev/null +++ b/mail_activity_team/models/__init__.py @@ -0,0 +1,3 @@ +from . import mail_activity_team +from . import mail_activity +from . import res_users diff --git a/mail_activity_team/models/mail_activity.py b/mail_activity_team/models/mail_activity.py new file mode 100644 index 00000000..1fccf746 --- /dev/null +++ b/mail_activity_team/models/mail_activity.py @@ -0,0 +1,65 @@ +# 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.exceptions import ValidationError + + +class MailActivity(models.Model): + _inherit = "mail.activity" + + 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( + comodel_name='mail.activity.team', + default=lambda s: s._get_default_team_id(), + ) + + @api.onchange('user_id') + def _onchange_user_id(self): + res = {'domain': {'team_id': []}} + 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 not in self.team_id.member_ids: + if self.team_id.user_id: + self.user_id = self.team_id.user_id + elif len(self.team_id.member_ids) == 1: + self.user_id = self.team_id.member_ids + 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.')) diff --git a/mail_activity_team/models/mail_activity_team.py b/mail_activity_team/models/mail_activity_team.py new file mode 100644 index 00000000..1e44e0d7 --- /dev/null +++ b/mail_activity_team/models/mail_activity_team.py @@ -0,0 +1,78 @@ +# 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, fields, models + + +class MailActivityTeam(models.Model): + _name = "mail.activity.team" + _description = 'Mail Activity Team' + + @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', + ) + 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 + + @api.onchange('user_id') + def _onchange_user_id(self): + if self.user_id and self.user_id not in self.member_ids: + members_ids = self.member_ids.ids + members_ids.append(self.user_id.id) + self.member_ids = [(4, member) for member in members_ids] + + 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) + for missing_activity in missing_activities: + missing_activity.write({'team_id': team.id}) diff --git a/mail_activity_team/models/res_users.py b/mail_activity_team/models/res_users.py new file mode 100644 index 00000000..e1f9cc33 --- /dev/null +++ b/mail_activity_team/models/res_users.py @@ -0,0 +1,13 @@ +# 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 models, fields + + +class ResUsers(models.Model): + _inherit = "res.users" + + activity_team_ids = fields.Many2many( + comodel_name='mail.activity.team', + relation='mail_activity_team_users_rel', + string="Activity Teams", + ) diff --git a/mail_activity_team/readme/CONTRIBUTORS.rst b/mail_activity_team/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..6bb24056 --- /dev/null +++ b/mail_activity_team/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Eficent `_: + + * Jordi Ballester Alomar (jordi.ballester@eficent.com) + * Miquel Raïch (miquel.raich@eficent.com) diff --git a/mail_activity_team/readme/DESCRIPTION.rst b/mail_activity_team/readme/DESCRIPTION.rst new file mode 100644 index 00000000..c0a2e3ae --- /dev/null +++ b/mail_activity_team/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module adds the possibility to assign teams to activities. + + diff --git a/mail_activity_team/readme/USAGE.rst b/mail_activity_team/readme/USAGE.rst new file mode 100644 index 00000000..a9b4344f --- /dev/null +++ b/mail_activity_team/readme/USAGE.rst @@ -0,0 +1,17 @@ +To set up new teams: + +#. Go to *Settings / Activate developer mode* +#. Go to *Settings / Technical / Email / Activity Teams* +#. Create a new Team and assign (optionally) the models in which it will + be used, and the members of the team. + +You can also assign a user to Activity teams going to +*Settings / Users & Companies / Users*, and in the *Preferences* tab, field +Activity Teams. + +When you create a new activity the application will propose the user's +assigned team. + +You can report on the activities assigned to a team going to +*Dashboards / Activities*, and then filter by a specific team or group by +teams. diff --git a/mail_activity_team/security/ir.model.access.csv b/mail_activity_team/security/ir.model.access.csv new file mode 100644 index 00000000..0a9918d6 --- /dev/null +++ b/mail_activity_team/security/ir.model.access.csv @@ -0,0 +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,1,1,1,1 diff --git a/mail_activity_team/security/mail_activity_team_security.xml b/mail_activity_team/security/mail_activity_team_security.xml new file mode 100644 index 00000000..e19398ab --- /dev/null +++ b/mail_activity_team/security/mail_activity_team_security.xml @@ -0,0 +1,15 @@ + + + + + mail.activity: user: my team + + ["|", ('team_id', 'in', user.activity_team_ids.ids), "&", ('team_id', '=', False), ('user_id', '=', user.id)] + + + + + + + + diff --git a/mail_activity_team/static/description/icon.png b/mail_activity_team/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/mail_activity_team/static/description/icon.png differ diff --git a/mail_activity_team/static/description/index.html b/mail_activity_team/static/description/index.html new file mode 100644 index 00000000..1ee2f86d --- /dev/null +++ b/mail_activity_team/static/description/index.html @@ -0,0 +1,419 @@ + + + + + + +Mail Activity Team + + + +
+

Mail Activity Team

+ + +

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runbot

+

This module adds the possibility to assign teams to activities.

+

Table of contents

+ +
+

Usage

+

To set up new teams:

+
    +
  1. Go to Settings / Activate developer mode
  2. +
  3. Go to Settings / Technical / Email / Activity Teams
  4. +
  5. Create a new Team and assign (optionally) the models in which it will +be used, and the members of the team.
  6. +
+

You can also assign a user to Activity teams going to +Settings / Users & Companies / Users, and in the Preferences tab, field +Activity Teams.

+

When you create a new activity the application will propose the user’s +assigned team.

+

You can report on the activities assigned to a team going to +Dashboards / Activities, and then filter by a specific team or group by +teams.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Eficent
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mail_activity_team/tests/__init__.py b/mail_activity_team/tests/__init__.py new file mode 100644 index 00000000..f4a7f595 --- /dev/null +++ b/mail_activity_team/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_activity_team diff --git a/mail_activity_team/tests/test_mail_activity_team.py b/mail_activity_team/tests/test_mail_activity_team.py new file mode 100644 index 00000000..413e4122 --- /dev/null +++ b/mail_activity_team/tests/test_mail_activity_team.py @@ -0,0 +1,118 @@ +# 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.tests.common import TransactionCase +from odoo.exceptions import ValidationError + + +class TestMailActivityTeam(TransactionCase): + + def setUp(self): + super(TestMailActivityTeam, self).setUp() + + self.env["mail.activity.team"].search([]).unlink() + + self.employee = self.env['res.users'].create({ + 'company_id': self.env.ref("base.main_company").id, + 'name': "Employee", + 'login': "csu", + 'email': "crmuser@yourcompany.com", + 'groups_id': [(6, 0, [ + self.env.ref('base.group_user').id, + self.env.ref('base.group_partner_manager').id])] + }) + + self.employee2 = self.env['res.users'].create({ + 'company_id': self.env.ref("base.main_company").id, + 'name': "Employee 2", + 'login': "csu2", + 'email': "crmuser2@yourcompany.com", + 'groups_id': [(6, 0, [self.env.ref('base.group_user').id])] + }) + + self.partner_ir_model = self.env['ir.model']._get('res.partner') + + activity_type_model = self.env['mail.activity.type'] + self.activity1 = activity_type_model.create({ + 'name': 'Initial Contact', + 'days': 5, + 'summary': 'ACT 1 : Presentation, barbecue, ... ', + 'res_model_id': self.partner_ir_model.id, + }) + self.activity2 = activity_type_model.create({ + 'name': 'Call for Demo', + 'days': 6, + 'summary': 'ACT 2 : I want to show you my ERP !', + 'res_model_id': self.partner_ir_model.id, + }) + + self.partner_client = self.env.ref("base.res_partner_1") + + self.act1 = self.env['mail.activity'].sudo(self.employee).create({ + 'activity_type_id': self.activity1.id, + 'note': 'Partner activity 1.', + 'res_id': self.partner_client.id, + 'res_model_id': self.partner_ir_model.id, + 'user_id': self.employee.id, + }) + + self.team1 = self.env['mail.activity.team'].sudo().create({ + 'name': 'Team 1', + 'res_model_ids': [(6, 0, [self.partner_ir_model.id])], + 'member_ids': [(6, 0, [self.employee.id])], + }) + + self.team2 = self.env['mail.activity.team'].sudo().create({ + 'name': 'Team 2', + 'res_model_ids': [(6, 0, [self.partner_ir_model.id])], + 'member_ids': [(6, 0, [self.employee.id, self.employee2.id])], + }) + + self.act2 = self.env['mail.activity'].sudo(self.employee).create({ + 'activity_type_id': self.activity2.id, + 'note': 'Partner activity 2.', + 'res_id': self.partner_client.id, + 'res_model_id': self.partner_ir_model.id, + 'user_id': self.employee.id, + }) + + def test_missing_activities(self): + self.assertFalse( + self.act1.team_id, 'Error: Activity 1 should not have a team.') + self.assertEqual(self.team1.count_missing_activities, 1) + self.team1.assign_team_to_unassigned_activities() + self.team1._compute_missing_activities() + self.assertEqual(self.team1.count_missing_activities, 0) + self.assertEqual(self.act1.team_id, self.team1) + + def test_activity_onchanges(self): + self.assertEqual( + self.act2.team_id, self.team1, + 'Error: Activity 2 should have Team 1.') + with self.env.do_in_onchange(): + self.act2.team_id = False + self.act2._onchange_team_id() + self.assertEqual(self.act2.user_id, self.employee) + self.act2.team_id = self.team2 + self.act2._onchange_team_id() + self.assertEqual(self.act2.user_id, self.employee) + self.act2.user_id = self.employee2 + self.act2._onchange_user_id() + self.assertEqual(self.act2.team_id, self.team2) + self.act2.team_id = self.team1 + self.act2._onchange_team_id() + self.assertEqual(self.act2.user_id, self.team1.member_ids) + with self.assertRaises(ValidationError): + self.act2.write({ + 'user_id': self.employee2.id, + 'team_id': self.team1.id, + }) + + def test_team_onchanges(self): + self.assertFalse( + self.team2.user_id, + 'Error: Team 2 should not have a Team Leader yet.') + with self.env.do_in_onchange(): + self.team2.user_id = self.employee + self.team2.member_ids = [(3, self.employee.id)] + self.team2._onchange_member_ids() + self.assertFalse(self.team2.user_id) diff --git a/mail_activity_team/views/mail_activity_team_views.xml b/mail_activity_team/views/mail_activity_team_views.xml new file mode 100644 index 00000000..6ecba09a --- /dev/null +++ b/mail_activity_team/views/mail_activity_team_views.xml @@ -0,0 +1,98 @@ + + + + + + + mail.activity.team.view.form + mail.activity.team + +
+
+ +
+ +
+ +
+ + + + + + + + + + + + + + +
+
+
+
+ + + + + mail.activity.team.view.tree + mail.activity.team + + + + + + + + + + + + mail.activity.team.view.search + mail.activity.team + + + + + + + + + + + + + Activity Teams + mail.activity.team + form + tree,form + [] + {} + + + + + + + +
diff --git a/mail_activity_team/views/mail_activity_views.xml b/mail_activity_team/views/mail_activity_views.xml new file mode 100644 index 00000000..ec0ecd47 --- /dev/null +++ b/mail_activity_team/views/mail_activity_views.xml @@ -0,0 +1,73 @@ + + + + + mail.activity.view.form.popup + mail.activity + + + + + + + + + + mail.activity.view.tree + mail.activity + + + + + + + + + + mail.activity.view.form + mail.activity + + + + + + + + + + mail.activity.boards.view.kanban + mail.activity + + + + + + +
+
+ Team: +
+
+
+
+ + + + mail.activity.boards.view.search + mail.activity + + + + + + + + + + + + + + + +
diff --git a/mail_activity_team/views/res_users_views.xml b/mail_activity_team/views/res_users_views.xml new file mode 100644 index 00000000..bf79365e --- /dev/null +++ b/mail_activity_team/views/res_users_views.xml @@ -0,0 +1,16 @@ + + + + + res.users.form.activity.team + res.users + + + + + + + + + +