add mail_follower_module
							parent
							
								
									3420748c79
								
							
						
					
					
						commit
						582d4f46d2
					
				|  | @ -0,0 +1,20 @@ | |||
| # mail_follower_control | ||||
| 
 | ||||
| This addon allows better control over follower handling for the chatter view. | ||||
| 
 | ||||
| ## Goals: | ||||
| 
 | ||||
| - Checkbox "Do not automatically add as follower" for res.partner | ||||
| - Set this new Checkbox to True by default | ||||
| - Show the followers and additional recipients that will receive an email (notify always + email) | ||||
| - Show a warning when adding additional recipients if the new recipient will not receive an email | ||||
| - Show followers that will not receive Messages in Red | ||||
| - Write the followers that received an email to mail.message in a new field to view them in message thread views | ||||
| 
 | ||||
| - ToDo: Always show all the followers when writing a message in full message composer | ||||
|     - ToDo: Allow to remove some followers just for the current mail | ||||
| - ToDo: BCC Field for all Chatter E-Mails | ||||
|     - ToDo: Do NOT add BCC Recipients as followers regardless of the checkbox "Do not automatically ad as follower" | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  | @ -0,0 +1,25 @@ | |||
| # -*- encoding: utf-8 -*- | ||||
| ############################################################################## | ||||
| # | ||||
| #    OpenERP, Open Source Management Solution	 | ||||
| #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved | ||||
| #    $Id$ | ||||
| # | ||||
| #    This program is free software: you can redistribute it and/or modify | ||||
| #    it under the terms of the GNU General Public License as published by | ||||
| #    the Free Software Foundation, either version 3 of the License, or | ||||
| #    (at your option) any later version. | ||||
| # | ||||
| #    This program is distributed in the hope that it will be useful, | ||||
| #    but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| #    GNU General Public License for more details. | ||||
| # | ||||
| #    You should have received a copy of the GNU General Public License | ||||
| #    along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
| # | ||||
| ############################################################################## | ||||
| import mail_follower_control | ||||
| 
 | ||||
| # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | ||||
| 
 | ||||
|  | @ -0,0 +1,61 @@ | |||
| # -*- encoding: utf-8 -*- | ||||
| ############################################################################## | ||||
| # | ||||
| #    OpenERP, Open Source Management Solution     | ||||
| #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved | ||||
| #    $Id$ | ||||
| # | ||||
| #    This program is free software: you can redistribute it and/or modify | ||||
| #    it under the terms of the GNU General Public License as published by | ||||
| #    the Free Software Foundation, either version 3 of the License, or | ||||
| #    (at your option) any later version. | ||||
| # | ||||
| #    This program is distributed in the hope that it will be useful, | ||||
| #    but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| #    GNU General Public License for more details. | ||||
| # | ||||
| #    You should have received a copy of the GNU General Public License | ||||
| #    along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
| # | ||||
| ############################################################################## | ||||
| 
 | ||||
| 
 | ||||
| { | ||||
|     'name': 'Mail Follower Control', | ||||
|     'version': '1.0', | ||||
|     'category': 'Custom', | ||||
|     'author': 'DataDialog, Michael Karrer (original version for v7 by camadeus)', | ||||
|     'website': 'http://www.datadialog.net', | ||||
|     'installable': True, | ||||
|     'description': """ | ||||
| mail_follower_control | ||||
| ===================== | ||||
| 
 | ||||
| This addon allows better control over follower handling for the chatter view. | ||||
| 
 | ||||
| Goals: | ||||
| ------ | ||||
| 
 | ||||
| - Checkbox "Do not automatically add as follower" for res.partner | ||||
| - Set this new Checkbox to True by default | ||||
| - Show the followers and additional recipients that will receive an email (notify always + email) | ||||
| - Show a warning when adding additional recipients if the new recipient will not receive an email | ||||
| - Show followers that will not receive Messages in Red | ||||
| - Write the followers that received an email to mail.message in a new field to view them in message thread views | ||||
| 
 | ||||
| - ToDo: Always show all the followers when writing a message in full message composer | ||||
|     - ToDo: Allow to remove some followers just for the current mail | ||||
| - ToDo: BCC Field for all Chatter E-Mails | ||||
|     - ToDo: Do NOT add BCC Recipients as followers regardless of the checkbox "Do not automatically ad as follower" | ||||
| 
 | ||||
|     """, | ||||
|     'depends': ['web', 'mail'], | ||||
|     'qweb': [ | ||||
|         'views/templates.xml', | ||||
|     ], | ||||
|     'data': [ | ||||
|         'views/views.xml', | ||||
|     ], | ||||
| 
 | ||||
| } | ||||
|  | @ -0,0 +1,84 @@ | |||
| # Translation of Odoo Server. | ||||
| # This file contains the translation of the following modules: | ||||
| #	* mail_follower_control | ||||
| # | ||||
| msgid "" | ||||
| msgstr "" | ||||
| "Project-Id-Version: Odoo Server 8.0\n" | ||||
| "Report-Msgid-Bugs-To: \n" | ||||
| "POT-Creation-Date: 2015-04-29 12:25+0000\n" | ||||
| "PO-Revision-Date: 2015-04-29 12:25+0000\n" | ||||
| "Last-Translator: <>\n" | ||||
| "Language-Team: \n" | ||||
| "MIME-Version: 1.0\n" | ||||
| "Content-Type: text/plain; charset=UTF-8\n" | ||||
| "Content-Transfer-Encoding: \n" | ||||
| "Plural-Forms: \n" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: field:res.partner,no_subscribe:0 | ||||
| msgid "Do not add as Follower automatically" | ||||
| msgstr "Nicht automatisch als Follower hinzufügen" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: model:ir.model,name:mail_follower_control.model_mail_thread | ||||
| msgid "Email Thread" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: model:ir.model,name:mail_follower_control.model_mail_compose_message | ||||
| msgid "Email composition wizard" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: model:ir.model,name:mail_follower_control.model_mail_wizard_invite | ||||
| msgid "Invite wizard" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: model:ir.model,name:mail_follower_control.model_mail_message | ||||
| msgid "Message" | ||||
| msgstr "Nachricht" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: view:mail.compose.message:mail_follower_control.mail_message_wizard_form_view | ||||
| #: field:mail.compose.message,follower_ids:0 | ||||
| msgid "Notified by eMail" | ||||
| msgstr "Benachrichtigt per E-Mail" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: model:ir.model,name:mail_follower_control.model_mail_mail | ||||
| msgid "Outgoing Mails" | ||||
| msgstr "Ausgehende E-Mails" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: model:ir.model,name:mail_follower_control.model_res_partner | ||||
| msgid "Partner" | ||||
| msgstr "Kontakt" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: field:mail.message,notified_by_email_ids:0 | ||||
| msgid "Partners notified by e-mail" | ||||
| msgstr "Benachrichtigt per E-Mail" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: code:addons/mail_follower_control/mail_follower_control.py:261 | ||||
| #, python-format | ||||
| msgid "Some partners will not be notified by e-mail!" | ||||
| msgstr "Einige Kontakte werden nicht per E-Mail benachrichtigt!" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: code:addons/mail_follower_control/mail_follower_control.py:262 | ||||
| #, python-format | ||||
| msgid "The following partners will not be notified by e-mail but they will still get a message in odoo (if they have a login):\n" | ||||
| "\n" | ||||
| "%s" | ||||
| msgstr "Folgende Kontakte werden keine Benachrichtigung per E-Mail bekommen. Diese Kontakte bekommen jedoch zumindest eine Benachrichtigung in Ihren odoo Posteingang sofern sie sich einloggen können.: \n" | ||||
| "\n" | ||||
| "%s" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: view:mail.compose.message:mail_follower_control.mail_message_wizard_form_view | ||||
| msgid "onchange_partner_ids(partner_ids, follower_ids, model, res_id, context)" | ||||
| msgstr "" | ||||
| 
 | ||||
|  | @ -0,0 +1,82 @@ | |||
| # Translation of Odoo Server. | ||||
| # This file contains the translation of the following modules: | ||||
| #	* mail_follower_control | ||||
| # | ||||
| msgid "" | ||||
| msgstr "" | ||||
| "Project-Id-Version: Odoo Server 8.0\n" | ||||
| "Report-Msgid-Bugs-To: \n" | ||||
| "POT-Creation-Date: 2015-04-29 12:25+0000\n" | ||||
| "PO-Revision-Date: 2015-04-29 12:25+0000\n" | ||||
| "Last-Translator: <>\n" | ||||
| "Language-Team: \n" | ||||
| "MIME-Version: 1.0\n" | ||||
| "Content-Type: text/plain; charset=UTF-8\n" | ||||
| "Content-Transfer-Encoding: \n" | ||||
| "Plural-Forms: \n" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: field:res.partner,no_subscribe:0 | ||||
| msgid "Do not add as Follower automatically" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: model:ir.model,name:mail_follower_control.model_mail_thread | ||||
| msgid "Email Thread" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: model:ir.model,name:mail_follower_control.model_mail_compose_message | ||||
| msgid "Email composition wizard" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: model:ir.model,name:mail_follower_control.model_mail_wizard_invite | ||||
| msgid "Invite wizard" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: model:ir.model,name:mail_follower_control.model_mail_message | ||||
| msgid "Message" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: view:mail.compose.message:mail_follower_control.mail_message_wizard_form_view | ||||
| #: field:mail.compose.message,follower_ids:0 | ||||
| msgid "Notified by eMail" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: model:ir.model,name:mail_follower_control.model_mail_mail | ||||
| msgid "Outgoing Mails" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: model:ir.model,name:mail_follower_control.model_res_partner | ||||
| msgid "Partner" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: field:mail.message,notified_by_email_ids:0 | ||||
| msgid "Partners notified by e-mail" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: code:addons/mail_follower_control/mail_follower_control.py:261 | ||||
| #, python-format | ||||
| msgid "Some partners will not be notified by e-mail!" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: code:addons/mail_follower_control/mail_follower_control.py:262 | ||||
| #, python-format | ||||
| msgid "The following partners will not be notified by e-mail but they will still get a message in odoo (if they have a login):\n" | ||||
| "\n" | ||||
| "%s" | ||||
| msgstr "" | ||||
| 
 | ||||
| #. module: mail_follower_control | ||||
| #: view:mail.compose.message:mail_follower_control.mail_message_wizard_form_view | ||||
| msgid "onchange_partner_ids(partner_ids, follower_ids, model, res_id, context)" | ||||
| msgstr "" | ||||
| 
 | ||||
|  | @ -0,0 +1,296 @@ | |||
| # -*- coding: utf-8 -*- | ||||
| ############################################################################## | ||||
| # | ||||
| #    OpenERP, Open Source Management Solution | ||||
| #    Copyright (C) 2004-2010 conexus (<http://conexus.at>). | ||||
| # | ||||
| #    This program is free software: you can redistribute it and/or modify | ||||
| #    it under the terms of the GNU Affero General Public License as | ||||
| #    published by the Free Software Foundation, either version 3 of the | ||||
| #    License, or (at your option) any later version. | ||||
| # | ||||
| #    This program is distributed in the hope that it will be useful, | ||||
| #    but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| #    GNU Affero General Public License for more details. | ||||
| # | ||||
| #    You should have received a copy of the GNU Affero General Public License | ||||
| #    along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
| # | ||||
| ############################################################################## | ||||
| 
 | ||||
| from openerp.osv import fields, osv | ||||
| from openerp.tools.translate import _ | ||||
| from openerp import SUPERUSER_ID | ||||
| 
 | ||||
| 
 | ||||
| class res_partner(osv.Model): | ||||
|     _inherit = "res.partner" | ||||
| 
 | ||||
|     _columns = { | ||||
|         'no_subscribe': fields.boolean("Do not add as Follower automatically"), | ||||
|     } | ||||
|     _defaults = { | ||||
|         'no_subscribe': True, | ||||
|     } | ||||
|      | ||||
|     def get_partners_notify_by_email(self, cr, uid, ids, message_type, context): | ||||
|         """ Return the list of partners which will be notified per mail, based on their preferences. | ||||
|             :param message_type: type of message | ||||
| 
 | ||||
|         """ | ||||
|         notify_pids = [] | ||||
|         user = self.pool.get('res.users').browse(cr,uid,uid) | ||||
|         for partner in self.browse(cr, uid, ids): | ||||
|             # Do not send to partners without email address defined | ||||
|             if not partner.email: | ||||
|                 continue | ||||
|             # Partner does not want to receive any emails | ||||
|             if partner.notify_email == 'none': | ||||
|                 continue | ||||
| 
 | ||||
|             # Exclude own partner | ||||
|             if partner.email == user.email: | ||||
|                 continue | ||||
| 
 | ||||
|             notify_pids.append(partner.id) | ||||
|         return notify_pids | ||||
| res_partner() | ||||
| 
 | ||||
| 
 | ||||
| class mail_thread(osv.AbstractModel): | ||||
|     _inherit = "mail.thread" | ||||
| 
 | ||||
|     # Add data for JS to mark follower in red that will not receive an email | ||||
|     # | ||||
|     # FULL OVERWRITE of function to add 'notify_email': --> stupid but needed | ||||
|     # (this function will be called by the java script mail_followers.js to get the follower data) | ||||
|     # we need to know notify_email in the qweb template to mark followers in red that will not receive an email | ||||
|     # we alter mail_followers.js in addons-own/mail_follower_control/static/src/js/mail_follower_control.js to add | ||||
|     # notify_email to the display_followers function | ||||
|     def read_followers_data(self, cr, uid, follower_ids, context=None): | ||||
|         result = [] | ||||
|         technical_group = self.pool.get('ir.model.data').get_object(cr, uid, 'base', 'group_no_one', context=context) | ||||
|         for follower in self.pool.get('res.partner').browse(cr, uid, follower_ids, context=context): | ||||
|             is_editable = uid in map(lambda x: x.id, technical_group.users) | ||||
|             is_uid = uid in map(lambda x: x.id, follower.user_ids) | ||||
|             data = (follower.id, | ||||
|                     follower.name, | ||||
|                     {'is_editable': is_editable, 'is_uid': is_uid, 'notify_email': follower.notify_email, }, | ||||
|                     ) | ||||
|             result.append(data) | ||||
|         return result | ||||
| 
 | ||||
|     # Do not subscript followers with no_subscribe=True (except force_subscription is in the context) | ||||
|     # | ||||
|     # message_post will call message_subscribe to add followers | ||||
|     # we alter this method to take our new field no_subscribe into account | ||||
|     def message_subscribe(self, cr, uid, ids, partner_ids, subtype_ids=None, context=None): | ||||
|         if context is None: | ||||
|             context = {} | ||||
| 
 | ||||
|         # 1.) Filter all mail_post_autofollow_partner_ids if they exists to respect the no_subscribe setting | ||||
|         if context.get('mail_post_autofollow') and context.get('mail_post_autofollow_partner_ids'): | ||||
|             context['mail_post_autofollow_partner_ids'] = self.pool.get('res.partner').search(cr, uid, [ | ||||
|                 ('no_subscribe', '=', False), | ||||
|                 ('id', 'in', context.get('mail_post_autofollow_partner_ids'), ) | ||||
|             ]) | ||||
|          | ||||
|         # 2.) Filter partner_ids: to respect the no_subscribe setting (except 'force_subscription' is set) | ||||
|         # HINT: force_subscription is set by java script to allow adding a follower with no_subscribe=True by the | ||||
|         #       add followers links in the chatter window - without this the follower could not be added by any method. | ||||
|         if not context.get('force_subscription'): | ||||
|             partner_ids = self.pool.get('res.partner').search(cr, uid, [ | ||||
|                 ('no_subscribe', '=', False), | ||||
|                 ('id', 'in', partner_ids), | ||||
|             ]) | ||||
| 
 | ||||
|         # Remove force_subscription from the context after the filtering is done | ||||
|         if context.get('force_subscription'): | ||||
|             context.pop('force_subscription') | ||||
| 
 | ||||
|         res = super(mail_thread, self).message_subscribe(cr, uid, ids, partner_ids, subtype_ids, context) | ||||
|         return res | ||||
| mail_thread() | ||||
| 
 | ||||
| 
 | ||||
| # Allow to add followers with no_subscribe=True at least with the invite wizard (Add Followers Link) | ||||
| class invite_wizard(osv.osv_memory): | ||||
|     _inherit = 'mail.wizard.invite' | ||||
| 
 | ||||
|     # Add force Subscription to the context so that followers can be added even if no_subscribe=True | ||||
|     def add_followers(self, cr, uid, ids, context=None): | ||||
|         if context is None: | ||||
|             context = {} | ||||
|         context['force_subscription'] = True | ||||
|          | ||||
|         return super(invite_wizard, self).add_followers(cr, uid, ids, context) | ||||
| invite_wizard() | ||||
| 
 | ||||
| 
 | ||||
| class mail_message(osv.Model): | ||||
|     _inherit = "mail.message" | ||||
|     # Add field notified_by_email_ids to store this data from mail.mail if a mail was sent | ||||
|     # WARNING: do not use relation= for old style many2many fields - will be ignored!!!! | ||||
|     # WARNING: always use a custom name for the relation table e.g.: mail_message_res_partner_notified_by_email_rel | ||||
|     #          if you use none the system may generate one that is already in use and both fields will have | ||||
|     #          the related fields - which is very hard to debug. | ||||
|     _columns = { | ||||
|         'notified_by_email_ids': fields.many2many('res.partner', | ||||
|                                                   'mail_message_res_partner_notified_by_email_rel', | ||||
|                                                   'mail_message_id', 'res_partner_id', | ||||
|                                                   string='Partners notified by e-mail'), | ||||
|     } | ||||
| 
 | ||||
|     # Update Dict for JS rendering of messages with field notified_by_email_ids | ||||
|     # HINT: _message_read_dict returns a dict representation of the message. This representation is | ||||
|     #       used in the JS client code, to display the messages. Partners and | ||||
|     #       attachments related stuff will be done in post-processing in batch. | ||||
|     def _message_read_dict(self, cr, uid, message, parent_id=False, context=None): | ||||
|         res = super(mail_message, self)._message_read_dict(cr, uid, message, parent_id, context) | ||||
| 
 | ||||
|         # ToDo: Create a dict wich holds name and id for each id in ids (partner) - needed in template! | ||||
|         vals = {'notified_by_email_ids': [[p.id, p.name] for p in message.notified_by_email_ids]} | ||||
|         # print 'vals: %s' % vals | ||||
|         res.update(vals) | ||||
|         return res | ||||
| 
 | ||||
| mail_message() | ||||
| 
 | ||||
| 
 | ||||
| # Check Receipients while composing a mail (Full composing dialog not quick dialogue) and give a warning | ||||
| # if the added recipients will not receive an e-mail by setting | ||||
| class mail_compose_message(osv.TransientModel): | ||||
|     _inherit = "mail.compose.message" | ||||
| 
 | ||||
|     _columns = { | ||||
|         'follower_ids': fields.many2many('res.partner', | ||||
|                                          'mail_compose_message_followers_rel', | ||||
|                                          'wizard_id', | ||||
|                                          'partner_id', | ||||
|                                          string='Notified by eMail', readonly=True), | ||||
|     } | ||||
| 
 | ||||
|     # This will recalculate/set the field follower_ids for the current mail_compose_message (which is a transient model | ||||
|     # so its not a problem to recalculate it here on the fly) | ||||
|     def get_record_data(self, cr, uid, values, context=None): | ||||
| 
 | ||||
|         res = super(mail_compose_message, self).get_record_data(cr, uid, values, context) | ||||
| 
 | ||||
|         # if this message belongs to a resource add follower ids that will receieve an email to the result dict | ||||
|         if values.get('model') and values.get('res_id'): | ||||
|             p_obj = self.pool.get('res.partner') | ||||
|             fol_obj = self.pool.get("mail.followers") | ||||
| 
 | ||||
|             # get all followers for the current resource (= model and res_id) | ||||
|             fol_ids = fol_obj.search(cr, SUPERUSER_ID, [ | ||||
|                     ('res_model', '=', values.get('model')), | ||||
|                     ('res_id', '=', values.get('res_id')), | ||||
|                     ('subtype_ids', 'in', 1)    # ID 1 is always the subtyp "Discussion" | ||||
|                     ], context=context) | ||||
| 
 | ||||
|             # get the res.partner objects of the followers (mail.followers) of this resource | ||||
|             followers = set(fo.partner_id for fo in fol_obj.browse(cr, SUPERUSER_ID, fol_ids, context=context)) | ||||
| 
 | ||||
|             # get the res.partner ids for the objects in followers | ||||
|             follower_ids = [f.id for f in followers] | ||||
| 
 | ||||
|             # filter out all followers without an email or with notify_email set to none | ||||
|             notify_pids = p_obj.get_partners_notify_by_email(cr, uid, follower_ids, 'comment', context) | ||||
| 
 | ||||
|             # add follower_ids tp the result dict | ||||
|             # This result dict is used by the ??? - I DONT KNOW TILL NOW! | ||||
|             res.update({'follower_ids': notify_pids}) | ||||
| 
 | ||||
|         return res | ||||
| 
 | ||||
|     def onchange_partner_ids(self, cr, uid, ids, partner_ids, follower_ids, model, res_id, context=None): | ||||
| 
 | ||||
|         # We unwrap the variable partner_ids which most likely has a form of e.g. [(6, 0, [7]), ] | ||||
|         # see https://doc.odoo.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html/#osv.osv.osv.write | ||||
|         p_ids = [] | ||||
|         # Unwrap: Only take the first list or tuble | ||||
|         if isinstance(partner_ids, (list, tuple)): | ||||
|             partner_ids = partner_ids[0] | ||||
|         # 4 means "link to existing record with id = ID" so we add new links which in fact is nonsense since | ||||
|         # p_ids is empty at this time anyway. | ||||
|         if isinstance(partner_ids, (list, tuple)) and partner_ids[0] == 4 and len(partner_ids) == 2: | ||||
|             p_ids.add(partner_ids[1]) | ||||
|         # 6 means "replace the list of linked IDs" so we replace the partner ids | ||||
|         if isinstance(partner_ids, (list, tuple)) and partner_ids[0] == 6 and len(partner_ids) == 3 and partner_ids[2]: | ||||
|             p_ids = partner_ids[2] | ||||
|         elif isinstance(partner_ids, (int, long)): | ||||
|             p_ids.add(partner_ids) | ||||
|         else: | ||||
|             pass  # we do not manage anything else | ||||
| 
 | ||||
|         p_obj = self.pool.get('res.partner') | ||||
| 
 | ||||
|         # get all partners that have an email and also notify_email is not none | ||||
|         parterns_to_notify = p_obj.get_partners_notify_by_email(cr, uid, p_ids, "comment", context) | ||||
| 
 | ||||
|         # find any partners in p_ids that are not in parterns_to_notify | ||||
|         partners_not_to_notify = [p for p in p_ids if p not in parterns_to_notify] | ||||
| 
 | ||||
|         # get the names of the partners that will not get an email | ||||
|         partners = p_obj.name_get(cr, uid, partners_not_to_notify, context=context)         | ||||
|         partner_names = [p[1] for p in partners] | ||||
| 
 | ||||
|         # Update follower_ids | ||||
|         # Update the values for the wizzard (found in addons/email_template/wizard/mail_compose_message.py) | ||||
|         # HINT: There was no docu in how to update the wizard but at least i found an example - i have no idea | ||||
|         #       If this is the same for all wizards | ||||
|         p_obj = self.pool.get('res.partner') | ||||
|         fol_obj = self.pool.get("mail.followers") | ||||
| 
 | ||||
|         # get all followers for the current resource (= model and res_id) | ||||
|         fol_ids = fol_obj.search(cr, SUPERUSER_ID, [ | ||||
|                 ('res_model', '=', model), | ||||
|                 ('res_id', '=', res_id), | ||||
|                 ('subtype_ids', 'in', 1)    # ID 1 is always the subtyp "Discussion" | ||||
|                 ], context=context) | ||||
| 
 | ||||
|         # get the res.partner objects of the followers (mail.followers) of this resource | ||||
|         followers = set(fo.partner_id for fo in fol_obj.browse(cr, SUPERUSER_ID, fol_ids, context=context)) | ||||
| 
 | ||||
|         # get the res.partner ids for the objects in followers | ||||
|         follower_ids = [f.id for f in followers] | ||||
| 
 | ||||
|         # filter out all followers without an email or with notify_email set to none | ||||
|         follower_partner_ids = p_obj.get_partners_notify_by_email(cr, uid, follower_ids, 'comment', context) | ||||
| 
 | ||||
|         # update the follower_ids to reflect the newly added partners to notify by mail if any | ||||
|         values = {'follower_ids': list(set(follower_partner_ids + parterns_to_notify)), } | ||||
| 
 | ||||
| 
 | ||||
|         # Warn if any partners found that will not get an email | ||||
|         if partner_names: | ||||
|             warning = { | ||||
|                 'title': _('Some partners will not be notified by e-mail!'), | ||||
|                 'message': _('The following partners will not be notified by e-mail but they will still get a message in odoo (if they have a login):\n\n%s') % ('\n'.join(partner_names)) | ||||
|             } | ||||
|             res = {'warning': warning, 'value': values} | ||||
|         else: | ||||
|             res = {'value': values} | ||||
|         return res | ||||
| mail_compose_message() | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # This will update the new custom field mail_sent for the model mail.notification - seems useless ... because | ||||
| # it will be true if the smtp server takes over the mail which des not guarantee sending was successful | ||||
| class mail_mail(osv.Model): | ||||
|     _inherit = 'mail.mail' | ||||
| 
 | ||||
|     def _postprocess_sent_message(self, cr, uid, mail, context=None, mail_sent=True): | ||||
| 
 | ||||
|         # Copy the notified_by_email_ids to the mail.message | ||||
|         # Hint: It seems that notified_by_email_ids of mail.message is already there but in the state of the initial | ||||
|         #       setting so we have to update it here after we send the message to inculde the right notified_by_email_ids | ||||
|         if mail_sent and mail.recipient_ids and mail.mail_message_id: | ||||
|             mail.mail_message_id.notified_by_email_ids = mail.recipient_ids | ||||
| 
 | ||||
| 
 | ||||
|         return super(mail_mail, self)._postprocess_sent_message(cr=cr, uid=uid, mail=mail, | ||||
|                                                                 context=context, mail_sent=mail_sent) | ||||
|  | @ -0,0 +1,15 @@ | |||
| 
 | ||||
| .oe_follower_red {  | ||||
|     color: red !important; | ||||
| } | ||||
| 
 | ||||
| .oe_follower_orange { | ||||
|     color: orange !important; | ||||
| } | ||||
| 
 | ||||
| .oe_msg_notify_mail { | ||||
|     margin-left: 4px; | ||||
|     overflow: hidden; | ||||
|     margin-top: -4px; | ||||
|     font-size: 11px; | ||||
| } | ||||
|  | @ -0,0 +1,82 @@ | |||
| openerp.mail_follower_control = function (session) { | ||||
| 	 | ||||
| 	session.mail_followers.Followers = session.mail_followers.Followers.extend({ | ||||
| 
 | ||||
|         /** FULL OVERWRITE: because we need to add more data to the records: 'notify_email' | ||||
|          *  Do not forget to update the python function "read_followers_data" in "mail_follower_control.py" | ||||
|          *  ("read_followers_data" is called by JS function "fetch_followers" which then calls "display_followers") | ||||
|          * | ||||
|          * */ | ||||
|         display_followers: function (records) { | ||||
|             var self = this; | ||||
|             this.message_is_follower = false; | ||||
|             console.log('RECORDS:'); | ||||
|             console.log(records); | ||||
|             this.followers = records || this.followers; | ||||
|             // clean and display title
 | ||||
|             var node_user_list = this.$('.oe_follower_list').empty(); | ||||
|             this.$('.oe_follower_title').html(this._format_followers(this.followers.length)); | ||||
|             self.message_is_follower = _.indexOf(this.followers.map(function (rec) { return rec[2]['is_uid']}), true) != -1; | ||||
|             // truncate number of displayed followers
 | ||||
|             var truncated = this.followers.slice(0, this.displayed_nb); | ||||
|             _(truncated).each(function (record) { | ||||
|                 partner = { | ||||
|                     'id': record[0], | ||||
|                     'name': record[1], | ||||
|                     'is_uid': record[2]['is_uid'], | ||||
|                     'is_editable': record[2]['is_editable'], | ||||
|                     'notify_email': record[2]['notify_email'], | ||||
|                     'avatar_url': session.mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record[0]) | ||||
|                 }; | ||||
|                 console.log('partner'); | ||||
|                 console.log(partner); | ||||
|                 $(session.web.qweb.render('mail.followers.partner', {'record': partner, 'widget': self})).appendTo(node_user_list); | ||||
|                 // On mouse-enter it will show the edit_subtype pencil.
 | ||||
|                 if (partner.is_editable) { | ||||
|                     self.$('.oe_follower_list').on('mouseenter mouseleave', function(e) { | ||||
|                         self.$('.oe_edit_subtype').toggleClass('oe_hidden', e.type == 'mouseleave'); | ||||
|                         self.$('.oe_follower_list').find('.oe_partner').toggleClass('oe_partner_name', e.type == 'mouseenter'); | ||||
|                     }); | ||||
|                 } | ||||
|             }); | ||||
|             // FVA note: be sure it is correctly translated
 | ||||
|             if (truncated.length < this.followers.length) { | ||||
|                 $(session.web.qweb.render('mail.followers.show_more', {'number': (this.followers.length - truncated.length)} )).appendTo(node_user_list); | ||||
|             } | ||||
|         }, | ||||
| 	 | ||||
| 	    do_follow: function () { | ||||
| 	        /** | ||||
| 	         * Add this context value to force subscription | ||||
| 	         */	    	 | ||||
| 	        var context = new session.web.CompoundContext(this.build_context(), {'force_subscription': 1}); | ||||
|             console.log('do_follow'); | ||||
| 
 | ||||
| 	        this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], [this.session.uid], undefined, context]) | ||||
| 	            .then(this.proxy('read_value')); | ||||
| 	 | ||||
| 	        _.each(this.$('.oe_subtype_list input'), function (record) { | ||||
| 	            $(record).attr('checked', 'checked'); | ||||
| 	        }); | ||||
| 	 | ||||
| 	    } | ||||
|      | ||||
|     }); | ||||
| 
 | ||||
|     // HINT: Add recipient_ids to MessageCommon - message common is extended by:
 | ||||
|     //       mail.ThreadMessage AND
 | ||||
|     //       mail.ThreadComposeMessage so both should have recipients_ids now for ThreadComposeMessage it will be
 | ||||
|     //       useless for now because this is updated after we post the message.
 | ||||
|     // session.mail.MessageCommon = session.mail.MessageCommon.extend({
 | ||||
|     // HINT2: mail.MessageCommon did not work ?!?
 | ||||
|     openerp.mail.ThreadMessage = openerp.mail.ThreadMessage.extend({ | ||||
|     	template: 'mail.thread.message', | ||||
| 
 | ||||
|     	init: function (parent, datasets, options) { | ||||
|     		this._super(parent, datasets, options); | ||||
| 
 | ||||
|     		this.notified_by_email_ids = datasets.notified_by_email_ids || []; | ||||
|     	} | ||||
|     }); | ||||
| 
 | ||||
| }; | ||||
|  | @ -0,0 +1,52 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <templates id="template" xml:space="preserve"> | ||||
| 
 | ||||
|     <!-- Chatter widget on left side with followers of thread: show partners in red that will not receive an email --> | ||||
|     <t t-extend="mail.followers.partner"> | ||||
|         <t t-jquery="a" t-operation="replace"> | ||||
|             <t t-if="record.notify_email == 'none'"> | ||||
|                 <a class="oe_follower_red" t-attf-href="#model=res.partner&id=#{record.id}" t-att-title="record.name" t-att-data-partner="record.id"><t t-esc="record.name"/></a> | ||||
|             </t> | ||||
|             <t t-if="record.notify_email != 'none'"> | ||||
|                 <a t-attf-href="#model=res.partner&id=#{record.id}" t-att-title="record.name" t-att-data-partner="record.id"><t t-esc="record.name"/></a> | ||||
|             </t> | ||||
|         </t> | ||||
|     </t> | ||||
| 
 | ||||
|     <!-- Add recipients.ids for the Mail sent to message - this is not a guarantee that the partner got an email! | ||||
|          HINT: This template is called by mail.js mail.ThreadMessage which extends mail.MessageCommon | ||||
|                All relevant fields of mail.message should be available - if needed can be extended in | ||||
|                mail_follower_control/static/src/js/mail_follower_control.js | ||||
|     --> | ||||
|     <t t-extend="mail.thread.message"> | ||||
|         <t t-jquery=".oe_msg_footer" t-operation="append"> | ||||
|             <div class="oe_msg_notify_mail"> | ||||
|                 <span>By e-mail to:</span> | ||||
|                     <t t-if="widget.type == 'notification' or ( (widget.type == 'email' or widget.type == 'comment') and widget.subtype)"> | ||||
| 
 | ||||
|                         <t t-foreach="widget.notified_by_email_ids" t-as="partner"> | ||||
|                             <span t-attf-class="oe_partner_follower"> | ||||
|                                 <a t-if="widget.options.show_link" t-attf-href="#model=res.partner&id=#{partner[0]}"> | ||||
|                                     <t t-raw="partner[1]"/> | ||||
|                                 </a> | ||||
|                                 <t t-if="!widget.options.show_link" t-raw="partner[1]"/> | ||||
|                             </span> | ||||
|                             <t t-if="!partner_last">,</t> | ||||
|                         </t> | ||||
| 
 | ||||
|                     </t> | ||||
|             </div> | ||||
|         </t> | ||||
|     </t> | ||||
| 
 | ||||
|     <!-- Todo: Extend the Quick mail composer with recipients_ids --> | ||||
|     <!-- HINT: This template for the quick mail composer is called by mail.js mail.ThreadComposeMessage which | ||||
|                extends mail.MessageCommon -> all relevant fields from mail.message should be available! | ||||
|                if not add them in mail_follower_control/static/src/js/mail_follower_control.js | ||||
|     --> | ||||
|     <!--<t t-extend="mail.compose_message">--> | ||||
|         <!--<t t-jquery=".oe_full" t-operation="after">--> | ||||
|             <!--<div>Notified by eMail: <t t-esc="widget.partner_ids"/></div>--> | ||||
|         <!--</t>--> | ||||
|     <!--</t>--> | ||||
| </templates> | ||||
|  | @ -0,0 +1,64 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <openerp> | ||||
|     <data> | ||||
| 
 | ||||
|         <!-- Load CSS and JS into the Backend--> | ||||
|         <template id="assets_backend" name="mail_follower_control assets" inherit_id="web.assets_backend"> | ||||
|             <xpath expr="." position="inside"> | ||||
|                 <link rel="stylesheet" href="/mail_follower_control/static/src/css/mail_follower_control.css"/> | ||||
|                 <script type="text/javascript" src="/mail_follower_control/static/src/js/mail_follower_control.js"></script> | ||||
|             </xpath> | ||||
|         </template> | ||||
| 
 | ||||
|         <!-- Add no_subscribe checkbox to partner form --> | ||||
|         <record id="res_partner_form_view" model="ir.ui.view"> | ||||
|             <field name="name">chatterimprovments.res_partner.form</field> | ||||
|             <field name="model">res.partner</field> | ||||
|             <field name="inherit_id" ref="mail.view_emails_partner_info_form"/> | ||||
|             <field name="arch" type="xml"> | ||||
|                 <field name="notify_email" position="after"> | ||||
|                     <field name="no_subscribe"/> | ||||
|                 </field> | ||||
|             </field> | ||||
|         </record> | ||||
| 
 | ||||
|         <!-- Add follower_ids and an onchange event for partner_ids to mail compose wizard form | ||||
|              To warn if the notification setting of a partner would prevent to send an e-mail | ||||
|              and to show which res.partner will receive an e-mail --> | ||||
|         <record id="mail_message_wizard_form_view" model="ir.ui.view"> | ||||
|             <field name="name">chatterimprovments.mail_message_wizard.form</field> | ||||
|             <field name="model">mail.compose.message</field> | ||||
|             <field name="inherit_id" ref="mail.email_compose_message_wizard_form"/> | ||||
|             <field name="arch" type="xml"> | ||||
| 
 | ||||
|                 <!-- ADD field follower_ids which hold the res.partner ids that will get an eMail --> | ||||
|                 <field name="notify" position="before"> | ||||
|                     <label for="follower_ids" string="Notified by eMail"/> | ||||
|                     <div> | ||||
|                         <field name="follower_ids" widget="many2many_tags_email"/> | ||||
|                     </div> | ||||
|                 </field> | ||||
| 
 | ||||
|                 <!-- ADD attribute onchange to partner_ids field--> | ||||
|                 <xpath expr="//field[@name='partner_ids']" position="attributes"> | ||||
|                     <attribute name="on_change">onchange_partner_ids(partner_ids, follower_ids, model, res_id, context)</attribute> | ||||
|                 </xpath> | ||||
|             </field> | ||||
|         </record> | ||||
| 
 | ||||
|         <!-- Show recipient_ids in mail_message form --> | ||||
|         <record id="mail_view_message_form_extended" model="ir.ui.view"> | ||||
|             <field name="name">mail_view_message_form_extended</field> | ||||
|             <field name="model">mail.message</field> | ||||
|             <field name="inherit_id" ref="mail.view_message_form"/> | ||||
|             <field name="arch" type="xml"> | ||||
| 
 | ||||
|                 <!-- ADD field recipient_ids which hold the res.partner ids that got an eMail --> | ||||
|                 <field name="notified_partner_ids" position="after"> | ||||
|                     <field name="notified_by_email_ids" widget="many2many_tags"/> | ||||
|                 </field> | ||||
|             </field> | ||||
|         </record> | ||||
| 
 | ||||
|     </data> | ||||
| </openerp> | ||||
|  | @ -202,6 +202,7 @@ class Config(): | |||
|             'web_printscreen_zb',                                                 | ||||
|             'crm', | ||||
|             'sale', | ||||
|             'mail_follower_control', | ||||
|             #'cam_hr_overtime', | ||||
|             #'cam_hr', | ||||
|             #'sale_order_optional', | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue