diff --git a/project_assignees/__manifest__.py b/project_assignees/__manifest__.py index 3e56d90..ad0f75f 100644 --- a/project_assignees/__manifest__.py +++ b/project_assignees/__manifest__.py @@ -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", ], diff --git a/project_assignees/data/project_assignees_data.xml b/project_assignees/data/project_assignees_data.xml new file mode 100644 index 0000000..0366ddc --- /dev/null +++ b/project_assignees/data/project_assignees_data.xml @@ -0,0 +1,35 @@ + + + + + Assignees change + project.task + + Assignees changed + + + + Task Assignees Changed + 13 + project.project + + + project_id + + + + + + + + Dear , + You have been assigned to the . + + + + View + + + + + \ No newline at end of file diff --git a/project_assignees/i18n/fr.po b/project_assignees/i18n/fr.po index 92a4f33..1e2f428 100644 --- a/project_assignees/i18n/fr.po +++ b/project_assignees/i18n/fr.po @@ -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 "Other assignees" -msgstr "Autres intervenants" +msgstr "Assigné à" + +#. 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é à " + diff --git a/project_assignees/models/project_task.py b/project_assignees/models/project_task.py index 88909c7..1a71eb1 100644 --- a/project_assignees/models/project_task.py +++ b/project_assignees/models/project_task.py @@ -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 \ No newline at end of file + 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) \ No newline at end of file
+ Dear , + You have been assigned to the . +
+ + View + +