From 63cec1bde3a896eadaaf90c8cc59992358a7a1dc Mon Sep 17 00:00:00 2001 From: Laetitia Da Costa Date: Thu, 16 Nov 2023 11:23:58 +0100 Subject: [PATCH] [IMP]project_assignees:notify assignees --- project_assignees/__init__.py | 1 + project_assignees/__manifest__.py | 2 +- project_assignees/models/__init__.py | 3 +- project_assignees/models/mail_thread.py | 42 +++++++++++++++++++ project_assignees/models/project_task.py | 2 +- project_followers/__init__.py | 0 project_followers/__manifest__.py | 26 ++++++++++++ .../js/suggested_recipient_info_custom.js | 17 ++++++++ 8 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 project_assignees/models/mail_thread.py create mode 100644 project_followers/__init__.py create mode 100644 project_followers/__manifest__.py create mode 100644 project_followers/static/js/suggested_recipient_info_custom.js diff --git a/project_assignees/__init__.py b/project_assignees/__init__.py index cde864b..9364503 100644 --- a/project_assignees/__init__.py +++ b/project_assignees/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- from . import models +from . import models diff --git a/project_assignees/__manifest__.py b/project_assignees/__manifest__.py index d7b8d1e..46066d1 100644 --- a/project_assignees/__manifest__.py +++ b/project_assignees/__manifest__.py @@ -3,7 +3,7 @@ { "name": "project_assignees", - "version": "14.0.1.1.0", + "version": "14.0.1.2.0", "author": "Elabore", "website": "https://github.com/elabore-coop/project-tools", "maintainer": "Stéphan Sainléger", diff --git a/project_assignees/models/__init__.py b/project_assignees/models/__init__.py index 853e5dd..008af44 100644 --- a/project_assignees/models/__init__.py +++ b/project_assignees/models/__init__.py @@ -1,2 +1,3 @@ -from . import project_task \ No newline at end of file +from . import project_task +from . import mail_thread diff --git a/project_assignees/models/mail_thread.py b/project_assignees/models/mail_thread.py new file mode 100644 index 0000000..fda5423 --- /dev/null +++ b/project_assignees/models/mail_thread.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + +class MailThread(models.AbstractModel): + _inherit = 'mail.thread' + + def _message_auto_subscribe_followers(self, updated_values, default_subtype_ids): + """ Overrides mail.thread._message_auto_subscribe_followers() only in a project task context. + + In a project task context : user(s) to notify are the assignees (field assignee_ids not user_id) + In other context : use parent _message_auto_subscribe_followers and notify the user identify by the field user_id + + Return a list tuples containing ( + partner ID, + subtype IDs (or False if model-based default subtypes), + QWeb template XML ID for notification (or False is no specific + notification is required), + ), aka partners and their subtype and possible notification to send + using the auto subscription mechanism linked to updated values. + + :param updated_values: see ``_message_auto_subscribe`` + :param default_subtype_ids: coming from ``_get_auto_subscription_subtypes`` + """ + + if self._name == 'project.task' : + results = [] + assignee_ids = updated_values.get('assignee_ids') + if assignee_ids and len(assignee_ids) == 1 and assignee_ids[0][0] == 6: + user_ids = assignee_ids[0][-1] + users = self.env['res.users'].sudo().browse(user_ids) + if users : + for user in users : + try: + if user.active: + results.append((user.partner_id.id, default_subtype_ids, 'mail.message_user_assigned' if user != self.env.user else False)) + except: + pass + return results + else: + return super()._message_auto_subscribe_followers(updated_values, default_subtype_ids) \ No newline at end of file diff --git a/project_assignees/models/project_task.py b/project_assignees/models/project_task.py index 598f2b4..8140799 100644 --- a/project_assignees/models/project_task.py +++ b/project_assignees/models/project_task.py @@ -5,5 +5,5 @@ from odoo import models, fields class Task(models.Model): _inherit = "project.task" - assignee_ids = fields.Many2many('res.users', 'assignee_ids_rel', string='Assignees') + assignee_ids = fields.Many2many('res.users', 'assignee_ids_rel', string='Assignees', tracking=True) diff --git a/project_followers/__init__.py b/project_followers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project_followers/__manifest__.py b/project_followers/__manifest__.py new file mode 100644 index 0000000..2af4110 --- /dev/null +++ b/project_followers/__manifest__.py @@ -0,0 +1,26 @@ +{ + 'name': 'Project Followers', + 'version': '14.0.1.0.0', + 'description': 'disable partner checked by while sending a message in project task chatter', + 'summary': '', + 'author': '', + 'website': '', + 'license': 'LGPL-3', + 'category': '', + 'depends': [ + 'base','mail' + ], + 'data': [ + '' + ], + 'demo': [ + '' + ], + 'auto_install': False, + 'application': False, + "assets": { + "web.assets_frontend": [ + "project_followers/static/src/js/suggested_recipient_info_custom.js", + ], + }, +} \ No newline at end of file diff --git a/project_followers/static/js/suggested_recipient_info_custom.js b/project_followers/static/js/suggested_recipient_info_custom.js new file mode 100644 index 0000000..fcc8549 --- /dev/null +++ b/project_followers/static/js/suggested_recipient_info_custom.js @@ -0,0 +1,17 @@ +odoo.define('project_followers.suggested_recipient_info_custom', function (require) { + 'use strict'; + + const SuggestedRecipientInfo = require('mail.suggested_recipient_info'); + + SuggestedRecipientInfo.include({ + /** + * @private + * @returns {boolean} + */ + _computeIsSelected: function () { + // Votre code de surcharge ici + // N'oubliez pas d'appeler la fonction d'origine si nécessaire + return this.partner ? this.isSelected : false; + }, + }); +}); \ No newline at end of file