Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0][MIG] mail_activity_team #340

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions mail_activity_team/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/social/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 <https://github.com/OCA/social/issues/new?body=module:%20mail_activity_team%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Eficent

Contributors
~~~~~~~~~~~~

* `Eficent <https://www.eficent.com>`_:

* 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 <https://github.com/OCA/social/tree/12.0/mail_activity_team>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions mail_activity_team/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions mail_activity_team/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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',
],
}
3 changes: 3 additions & 0 deletions mail_activity_team/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import mail_activity_team
from . import mail_activity
from . import res_users
72 changes: 72 additions & 0 deletions mail_activity_team/models/mail_activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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, _, SUPERUSER_ID
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:
# SUPERUSER is used to put mail.activity on some objects
# like sale.order coming from stock.picking
# (for example with exception type activity, with no backorder).
# SUPERUSER is inactive and then even if you add it
# to member_ids it's not taken account
# To not be blocked we must add it to constraint condition
if activity.user_id.id != SUPERUSER_ID and 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.'))
78 changes: 78 additions & 0 deletions mail_activity_team/models/mail_activity_team.py
Original file line number Diff line number Diff line change
@@ -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})
13 changes: 13 additions & 0 deletions mail_activity_team/models/res_users.py
Original file line number Diff line number Diff line change
@@ -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",
)
4 changes: 4 additions & 0 deletions mail_activity_team/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Eficent <https://www.eficent.com>`_:

* Jordi Ballester Alomar (jordi.ballester@eficent.com)
* Miquel Raïch (miquel.raich@eficent.com)
3 changes: 3 additions & 0 deletions mail_activity_team/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module adds the possibility to assign teams to activities.


17 changes: 17 additions & 0 deletions mail_activity_team/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions mail_activity_team/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions mail_activity_team/security/mail_activity_team_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">

<record id="mail_activity_rule_my_team" model="ir.rule">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cosmetical change: use original id

prefer naming the inherited view after the original over using a name which follows the guidelines.

<record id="original_id" model="ir.ui.view">
    <field name="inherit_id" ref="original_module.original_id"/>
    ...
</record>

<field name="name">mail.activity: user: my team</field>
<field name="model_id" ref="mail.model_mail_activity"/>
<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="False"/>
<field name="perm_write" eval="True"/>
<field name="perm_unlink" eval="True"/>
</record>

</odoo>
Binary file added mail_activity_team/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading