[IMP] project_assignees: add notification for new assignees
This commit is contained in:
@@ -78,6 +78,7 @@ This module is maintained by Elabore.
|
||||
},
|
||||
# always loaded
|
||||
"data": [
|
||||
"data/project_assignees_data.xml",
|
||||
"views/project_task.xml",
|
||||
"views/portal_template.xml",
|
||||
],
|
||||
|
35
project_assignees/data/project_assignees_data.xml
Normal file
35
project_assignees/data/project_assignees_data.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
<record id="mt_task_assignees" model="mail.message.subtype">
|
||||
<field name="name">Assignees change</field>
|
||||
<field name="res_model">project.task</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="description">Assignees changed</field>
|
||||
</record>
|
||||
|
||||
<record id="mt_project_task_assignees" model="mail.message.subtype">
|
||||
<field name="name">Task Assignees Changed</field>
|
||||
<field name="sequence">13</field>
|
||||
<field name="res_model">project.project</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="parent_id" eval="ref('mt_task_assignees')"/>
|
||||
<field name="relation_field">project_id</field>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
<!-- Template email user assigned to a task -->
|
||||
<data>
|
||||
<template id="message_user_assigned">
|
||||
<p style="margin: 0px;">
|
||||
<span>Dear <t t-esc="partner_name"/>,</span><br />
|
||||
<span style="margin-top: 8px;">You have been assigned to the <t t-esc="model_description or 'document'"/> <t t-esc="object.name_get()[0][1]"/>.</span>
|
||||
</p>
|
||||
<p style="margin-top: 24px; margin-bottom: 16px;">
|
||||
<a t-att-href="'/mail/view?model=%s&res_id=%s' % (object._name, object.id)" style="background-color:#875A7B; padding: 10px; text-decoration: none; color: #fff; border-radius: 5px;">
|
||||
View <t t-esc="model_description or 'document'"/>
|
||||
</a>
|
||||
</p>
|
||||
</template>
|
||||
</data>
|
||||
</odoo>
|
@@ -6,8 +6,8 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 12.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2022-08-25 15:14+0000\n"
|
||||
"PO-Revision-Date: 2022-08-25 15:14+0000\n"
|
||||
"POT-Creation-Date: 2023-04-12 11:37+0000\n"
|
||||
"PO-Revision-Date: 2023-04-12 11:37+0000\n"
|
||||
"Last-Translator: <>\n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
@@ -18,15 +18,66 @@ msgstr ""
|
||||
#. module: project_assignees
|
||||
#: model_terms:ir.ui.view,arch_db:project_assignees.portal_my_task_assignees
|
||||
msgid "<strong>Other assignees</strong>"
|
||||
msgstr "<strong>Autres intervenants</strong>"
|
||||
msgstr "<strong>Assigné à</strong>"
|
||||
|
||||
#. module: project_assignees
|
||||
#: model:mail.message.subtype,name:project_assignees.mt_task_assignees
|
||||
msgid "Assignees change"
|
||||
msgstr "Changement d'assignation"
|
||||
|
||||
#. module: project_assignees
|
||||
#: model:mail.message.subtype,description:project_assignees.mt_task_assignees
|
||||
msgid "Assignees changed"
|
||||
msgstr "Changement d'assignation"
|
||||
|
||||
#. module: project_assignees
|
||||
#: model_terms:ir.ui.view,arch_db:project_assignees.portal_my_task_assignees
|
||||
msgid "Contact"
|
||||
msgstr ""
|
||||
|
||||
#. module: project_assignees
|
||||
#: model_terms:ir.ui.view,arch_db:project_assignees.message_user_assigned
|
||||
msgid "Dear"
|
||||
msgstr "Cher"
|
||||
|
||||
#. module: project_assignees
|
||||
#: model:ir.model,name:project_assignees.model_mail_thread
|
||||
msgid "Email Thread"
|
||||
msgstr "Discussion par courriel"
|
||||
|
||||
#. module: project_assignees
|
||||
#: model:ir.model,name:project_assignees.model_mail_tracking_value
|
||||
msgid "Mail Tracking Value"
|
||||
msgstr "Valeur de suivi des courriers"
|
||||
|
||||
#. module: project_assignees
|
||||
#: model:ir.model.fields,field_description:project_assignees.field_project_task__assignee_ids
|
||||
msgid "Other Assignees"
|
||||
msgstr "Autres intervenants"
|
||||
msgstr "Assigné à"
|
||||
|
||||
#. module: project_assignees
|
||||
#: model:ir.model,name:project_assignees.model_project_task
|
||||
msgid "Task"
|
||||
msgstr "Tâche"
|
||||
|
||||
#. module: project_assignees
|
||||
#: model:mail.message.subtype,name:project_assignees.mt_project_task_assignees
|
||||
msgid "Task Assignees Changed"
|
||||
msgstr "Changement d'assignation pour la tâche"
|
||||
|
||||
#. module: project_assignees
|
||||
#: model_terms:ir.ui.view,arch_db:project_assignees.message_user_assigned
|
||||
msgid "View"
|
||||
msgstr "Vue"
|
||||
|
||||
#. module: project_assignees
|
||||
#: code:addons/project_assignees/models/project_task.py:57
|
||||
#, python-format
|
||||
msgid "You have been assigned to %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: project_assignees
|
||||
#: model_terms:ir.ui.view,arch_db:project_assignees.message_user_assigned
|
||||
msgid "You have been assigned to the"
|
||||
msgstr "Vous avez été assigné à "
|
||||
|
||||
|
@@ -1,26 +1,99 @@
|
||||
|
||||
from odoo import models, fields, _, api
|
||||
|
||||
|
||||
|
||||
|
||||
class MailTracking(models.Model):
|
||||
_inherit = 'mail.tracking.value'
|
||||
|
||||
@api.model
|
||||
def create_tracking_values(self, initial_value, new_value, col_name, col_info, track_sequence):
|
||||
"""
|
||||
Track values of assignees changes in chatter
|
||||
"""
|
||||
if col_name == 'assignee_ids' and initial_value:
|
||||
values = {'field': col_name, 'field_desc': col_info['string'], 'field_type': col_info['type'], 'track_sequence': track_sequence}
|
||||
values.update({
|
||||
'old_value_char': ', '.join([i.name for i in initial_value]),
|
||||
'new_value_char': ', '.join([i.name for i in new_value])
|
||||
})
|
||||
return values
|
||||
return super(MailTracking, self).create_tracking_values(initial_value, new_value, col_name, col_info, track_sequence)
|
||||
|
||||
class Task(models.Model):
|
||||
_inherit = "project.task"
|
||||
|
||||
assignee_ids = fields.Many2many('res.users', 'assignee_ids_rel', string='Other Assignees')
|
||||
assignee_ids = fields.Many2many('res.users', 'assignee_ids_rel', string='Other Assignees', track_visibility='change')
|
||||
|
||||
@api.multi
|
||||
def subscribe_assignees(self):
|
||||
def subscribe_and_notify_assignees(self, new_assignee_ids=None):
|
||||
for task in self:
|
||||
partner_ids = [a.partner_id.id for a in task.assignee_ids]
|
||||
# Use assignees on parameter if exists
|
||||
if new_assignee_ids:
|
||||
assignees = self.env['res.users'].browse(new_assignee_ids)
|
||||
else:
|
||||
assignees = task.assignee_ids
|
||||
|
||||
# Subscribe partners
|
||||
partner_ids = [a.partner_id.id for a in assignees]
|
||||
task.message_subscribe(partner_ids)
|
||||
|
||||
# Send notification to assignees
|
||||
view = self.env['ir.ui.view'].browse(self.env['ir.model.data'].xmlid_to_res_id('project_assignees.message_user_assigned'))
|
||||
model_description = self.env['ir.model']._get(task._name).display_name
|
||||
|
||||
for assignee in assignees:
|
||||
values = {
|
||||
'object': task,
|
||||
'model_description': model_description,
|
||||
'partner_name':assignee.name_get()[0][1]
|
||||
}
|
||||
assignation_msg = view.render(values, engine='ir.qweb', minimal_qcontext=True)
|
||||
assignation_msg = self.env['mail.thread']._replace_local_links(assignation_msg)
|
||||
|
||||
|
||||
task.message_notify(
|
||||
subject=_('You have been assigned to %s') % task.display_name,
|
||||
body=assignation_msg,
|
||||
partner_ids=[(4, assignee.partner_id.id)],
|
||||
record_name=task.display_name,
|
||||
notif_layout='mail.mail_notification_light',
|
||||
model_description=model_description,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
# Notify only new assignees
|
||||
if 'assignee_ids' in vals:
|
||||
new_assignee_ids = vals['assignee_ids'][0][2].copy()
|
||||
for a in self.assignee_ids:
|
||||
if a.id in new_assignee_ids:
|
||||
new_assignee_ids.remove(a.id)
|
||||
self.subscribe_and_notify_assignees(new_assignee_ids)
|
||||
|
||||
result = super(Task, self).write(vals)
|
||||
self.subscribe_assignees()
|
||||
|
||||
return result
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
task = super(Task, self).create(vals)
|
||||
task.subscribe_assignees()
|
||||
return task
|
||||
task.subscribe_and_notify_assignees()
|
||||
return task
|
||||
|
||||
|
||||
@api.multi
|
||||
def _track_subtype(self, init_values):
|
||||
self.ensure_one()
|
||||
# keep notification of new task when creating a new task
|
||||
res = super(Task, self)._track_subtype(init_values)
|
||||
if res == 'project.mt_task_new':
|
||||
return res
|
||||
# if assignees change, notify it
|
||||
if 'assignee_ids' in init_values:
|
||||
return 'project_assignees.mt_task_assignees'
|
||||
|
||||
return super(Task, self)._track_subtype(init_values)
|
Reference in New Issue
Block a user