This commit refactors f488dc58c3 that added reminder feature in activities.
After merging it was suggested specifications were not correct and it has
been decided to move the whole reminder feature in note.
Reminders are now notes instead of activities. Now when having note appµ
systray proposes to create a note / reminder. A note.note record is created
with info given by the user. If a date is given in the systray quick create
then an activity is scheduled on this note.
This means user can create records in activity systray that are not
activities but notes used as reminders. Those will use the first availableµ
note column for the user.
As reminders are now notes the support of activities not linked to any
document is removed, as well as archiving activities and tests linked to
that behavior.
This commit has been not carefully tested nor in-depth reviewied. It is
considered as too important for the upcoming freeze. This closes task ID
1833628. Closes #24129 . Many thanks to @dpr-odoo for its quick development
and good work on this task.
122 lines
6.0 KiB
Python
122 lines
6.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import _, api, exceptions, fields, models, modules
|
|
from odoo.addons.base.models.res_users import is_selection_groups
|
|
|
|
|
|
class Users(models.Model):
|
|
""" Update of res.users class
|
|
- add a preference about sending emails about notifications
|
|
- make a new user follow itself
|
|
- add a welcome message
|
|
- add suggestion preference
|
|
- if adding groups to an user, check mail.channels linked to this user
|
|
group, and the user. This is done by overriding the write method.
|
|
"""
|
|
_name = 'res.users'
|
|
_inherit = ['res.users']
|
|
|
|
alias_id = fields.Many2one('mail.alias', 'Alias', ondelete="set null", required=False,
|
|
help="Email address internally associated with this user. Incoming "\
|
|
"emails will appear in the user's notifications.", copy=False, auto_join=True)
|
|
alias_contact = fields.Selection([
|
|
('everyone', 'Everyone'),
|
|
('partners', 'Authenticated Partners'),
|
|
('followers', 'Followers only')], string='Alias Contact Security', related='alias_id.alias_contact')
|
|
notification_type = fields.Selection([
|
|
('email', 'Handle by Emails'),
|
|
('inbox', 'Handle in Odoo')],
|
|
'Notification Management', required=True, default='email',
|
|
help="Policy on how to handle Chatter notifications:\n"
|
|
"- Handle by Emails: notifications are sent to your email address\n"
|
|
"- Handle in Odoo: notifications appear in your Odoo Inbox")
|
|
|
|
def __init__(self, pool, cr):
|
|
""" Override of __init__ to add access rights on notification_email_send
|
|
and alias fields. Access rights are disabled by default, but allowed
|
|
on some specific fields defined in self.SELF_{READ/WRITE}ABLE_FIELDS.
|
|
"""
|
|
init_res = super(Users, self).__init__(pool, cr)
|
|
# duplicate list to avoid modifying the original reference
|
|
type(self).SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS)
|
|
type(self).SELF_WRITEABLE_FIELDS.extend(['notification_type'])
|
|
# duplicate list to avoid modifying the original reference
|
|
type(self).SELF_READABLE_FIELDS = list(self.SELF_READABLE_FIELDS)
|
|
type(self).SELF_READABLE_FIELDS.extend(['notification_type'])
|
|
return init_res
|
|
|
|
@api.model
|
|
def create(self, values):
|
|
if not values.get('login', False):
|
|
action = self.env.ref('base.action_res_users')
|
|
msg = _("You cannot create a new user from here.\n To create new user please go to configuration panel.")
|
|
raise exceptions.RedirectWarning(msg, action.id, _('Go to the configuration panel'))
|
|
|
|
return super(Users, self).create(values)
|
|
|
|
@api.multi
|
|
def write(self, vals):
|
|
write_res = super(Users, self).write(vals)
|
|
sel_groups = [vals[k] for k in vals if is_selection_groups(k) and vals[k]]
|
|
if vals.get('groups_id'):
|
|
# form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]}
|
|
user_group_ids = [command[1] for command in vals['groups_id'] if command[0] == 4]
|
|
user_group_ids += [id for command in vals['groups_id'] if command[0] == 6 for id in command[2]]
|
|
self.env['mail.channel'].search([('group_ids', 'in', user_group_ids)])._subscribe_users()
|
|
elif sel_groups:
|
|
self.env['mail.channel'].search([('group_ids', 'in', sel_groups)])._subscribe_users()
|
|
return write_res
|
|
|
|
@api.model
|
|
def activity_user_count(self):
|
|
query = """SELECT m.id, count(*), act.res_model as model,
|
|
CASE
|
|
WHEN now()::date - act.date_deadline::date = 0 Then 'today'
|
|
WHEN now()::date - act.date_deadline::date > 0 Then 'overdue'
|
|
WHEN now()::date - act.date_deadline::date < 0 Then 'planned'
|
|
END AS states
|
|
FROM mail_activity AS act
|
|
JOIN ir_model AS m ON act.res_model_id = m.id
|
|
WHERE user_id = %s
|
|
GROUP BY m.id, states, act.res_model;
|
|
"""
|
|
self.env.cr.execute(query, [self.env.uid])
|
|
activity_data = self.env.cr.dictfetchall()
|
|
model_ids = [a['id'] for a in activity_data]
|
|
model_names = {n[0]: n[1] for n in self.env['ir.model'].browse(model_ids).name_get()}
|
|
|
|
user_activities = {}
|
|
for activity in activity_data:
|
|
if not user_activities.get(activity['model']):
|
|
user_activities[activity['model']] = {
|
|
'name': model_names[activity['id']],
|
|
'model': activity['model'],
|
|
'icon': modules.module.get_module_icon(self.env[activity['model']]._original_module),
|
|
'total_count': 0, 'today_count': 0, 'overdue_count': 0, 'planned_count': 0,
|
|
}
|
|
user_activities[activity['model']]['%s_count' % activity['states']] += activity['count']
|
|
if activity['states'] in ('today', 'overdue'):
|
|
user_activities[activity['model']]['total_count'] += activity['count']
|
|
|
|
return list(user_activities.values())
|
|
|
|
|
|
class res_groups_mail_channel(models.Model):
|
|
""" Update of res.groups class
|
|
- if adding users from a group, check mail.channels linked to this user
|
|
group and subscribe them. This is done by overriding the write method.
|
|
"""
|
|
_name = 'res.groups'
|
|
_inherit = 'res.groups'
|
|
|
|
@api.multi
|
|
def write(self, vals, context=None):
|
|
write_res = super(res_groups_mail_channel, self).write(vals)
|
|
if vals.get('users'):
|
|
# form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]}
|
|
user_ids = [command[1] for command in vals['users'] if command[0] == 4]
|
|
user_ids += [id for command in vals['users'] if command[0] == 6 for id in command[2]]
|
|
self.env['mail.channel'].search([('group_ids', 'in', self._ids)])._subscribe_users()
|
|
return write_res
|