From 1ac8e7cdfddbf8ac6b7c4b843582392705f10a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 20 Feb 2014 16:29:45 +0100 Subject: [IMP] mail, email_template: mass mailing feature cleaning - now differentiates mass mailing and mass post. - mass mailing is a true mass mailing - using same_thread log a copy in the document, without using message_post (using notification field, + model and res_id) - improved form view of composer, adding a filed explaining a bit the various recipients - removed unnecessary fields coming from the template (partner_to, ...) because they are confusing -> composer should be easier to understand and use - removed some unnecessary code - removed double body computation when using templates (one for tmeplate, then the wizard -> not necessary) This commit will be followed by other to try to improve the mass mailing and mass post. bzr revid: tde@openerp.com-20140220152945-ash0hfkzevzamihq --- addons/mail/wizard/mail_compose_message.py | 116 +++++++++++++++-------------- 1 file changed, 61 insertions(+), 55 deletions(-) (limited to 'addons/mail/wizard/mail_compose_message.py') diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 74aea3dfc01..c8326ed48cd 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -68,28 +68,25 @@ class mail_compose_message(osv.TransientModel): if context is None: context = {} result = super(mail_compose_message, self).default_get(cr, uid, fields, context=context) - # get some important values from context - composition_mode = context.get('default_composition_mode', context.get('mail.compose.message.mode')) - model = context.get('default_model', context.get('active_model')) - res_id = context.get('default_res_id', context.get('active_id')) - message_id = context.get('default_parent_id', context.get('message_id', context.get('active_id'))) - active_ids = context.get('active_ids') + + # v6.1 compatibility mode + result['composition_mode'] = result.get('composition_mode', context.get('mail.compose.message.mode')) + result['model'] = result.get('model', context.get('active_model')) + result['res_id'] = result.get('res_id', context.get('active_id')) + result['parent_id'] = result.get('parent_id', context.get('message_id')) + + # default values according to composition mode - NOTE: reply is deprecated, fall back on comment + if result['composition_mode'] == 'reply': + result['composition_mode'] = 'comment' + vals = {} if 'active_domain' in context: # not context.get() because we want to keep global [] domains - result['use_active_domain'] = True - result['active_domain'] = '%s' % context.get('active_domain') - elif not result.get('active_domain'): - result['active_domain'] = '' - # get default values according to the composition mode - if composition_mode == 'reply': - vals = self.get_message_data(cr, uid, message_id, context=context) - elif composition_mode == 'comment' and model and res_id: - vals = self.get_record_data(cr, uid, model, res_id, context=context) - elif composition_mode == 'mass_mail' and model and active_ids: - vals = {'model': model, 'res_id': res_id} - else: - vals = {'model': model, 'res_id': res_id} - if composition_mode: - vals['composition_mode'] = composition_mode + vals['use_active_domain'] = True + vals['active_domain'] = '%s' % context.get('active_domain') + if result.get('parent_id'): + vals.update(self.get_message_data(cr, uid, result.get('parent_id'), context=context)) + if result['composition_mode'] == 'comment' and result['model'] and result['res_id']: + vals.update(self.get_record_data(cr, uid, result['model'], result['res_id'], context=context)) + result['recipients_data'] = self.get_recipients_data(cr, uid, result, context=context) for field in vals: if field in fields: @@ -102,13 +99,15 @@ class mail_compose_message(osv.TransientModel): # but when creating the mail.message to create the mail.compose.message # access rights issues may rise # We therefore directly change the model and res_id - if result.get('model') == 'res.users' and result.get('res_id') == uid: + if result['model'] == 'res.users' and result['res_id'] == uid: result['model'] = 'res.partner' result['res_id'] = self.pool.get('res.users').browse(cr, uid, uid).partner_id.id return result def _get_composition_mode_selection(self, cr, uid, context=None): - return [('comment', 'Comment a document'), ('reply', 'Reply to a message'), ('mass_mail', 'Mass mailing')] + return [('comment', 'Post on a document'), + ('mass_mail', 'Email Mass Mailing'), + ('mass_post', 'Post on Multiple Documents')] _columns = { 'composition_mode': fields.selection( @@ -116,11 +115,11 @@ class mail_compose_message(osv.TransientModel): string='Composition mode'), 'partner_ids': fields.many2many('res.partner', 'mail_compose_message_res_partner_rel', - 'wizard_id', 'partner_id', 'Additional contacts'), + 'wizard_id', 'partner_id', 'Additional Contacts'), + 'recipients_data': fields.text(string='Recipients Data', + help='Helper field used in mass mailing to display a sample of recipients'), 'use_active_domain': fields.boolean('Use active domain'), 'active_domain': fields.char('Active domain', readonly=True), - 'post': fields.boolean('Post a copy in the document', - help='Post a copy of the message on the document communication history.'), 'notify': fields.boolean('Notify followers', help='Notify followers of the document'), 'same_thread': fields.boolean('Replies in the document', @@ -136,8 +135,7 @@ class mail_compose_message(osv.TransientModel): 'body': lambda self, cr, uid, ctx={}: '', 'subject': lambda self, cr, uid, ctx={}: False, 'partner_ids': lambda self, cr, uid, ctx={}: [], - 'post': False, - 'notify': False, + 'notify': True, 'same_thread': True, } @@ -169,6 +167,21 @@ class mail_compose_message(osv.TransientModel): not want that feature in the wizard. """ return + def get_recipients_data(self, cr, uid, values, context=None): + """ Returns a string explaining the targetted recipients, to ease the use + of the wizard. """ + composition_mode, model, res_id = values['composition_mode'], values['model'], values['res_id'] + if composition_mode == 'comment' and model and res_id: + doc_name = self.pool[model].name_get(cr, uid, [res_id], context=context) + return doc_name and 'Followers of %s' % doc_name[0][1] or False + elif composition_mode == 'mass_post' and model: + active_ids = context.get('active_ids', list()) + if not active_ids: + return False + name_gets = [rec_name[1] for rec_name in self.pool[model].name_get(cr, uid, active_ids[:3], context=context)] + return 'Followers of selected documents (' + ', '.join(name_gets) + len(active_ids) > 3 and ', ...' or '' + ')' + return False + def get_record_data(self, cr, uid, model, res_id, context=None): """ Returns a defaults-like dict with initial values for the composition wizard when sending an email related to the document record @@ -179,17 +192,10 @@ class mail_compose_message(osv.TransientModel): :param int res_id: id of the document record this mail is related to """ doc_name_get = self.pool[model].name_get(cr, uid, [res_id], context=context) - record_name = False - if doc_name_get: - record_name = doc_name_get[0][1] - values = { - 'model': model, - 'res_id': res_id, - 'record_name': record_name, + return { + 'record_name': doc_name_get and doc_name_get[0][1] or False, + 'subject': doc_name_get and 'Re: %s' % doc_name_get[0][1] or False, } - if record_name: - values['subject'] = 'Re: %s' % record_name - return values def get_message_data(self, cr, uid, message_id, context=None): """ Returns a defaults-like dict with initial values for the composition @@ -208,23 +214,20 @@ class mail_compose_message(osv.TransientModel): # create subject re_prefix = _('Re:') reply_subject = tools.ustr(message_data.subject or message_data.record_name or '') - if not (reply_subject.startswith('Re:') or reply_subject.startswith(re_prefix)) and message_data.subject: + if not (reply_subject.startswith('Re:') or reply_subject.startswith(re_prefix)): reply_subject = "%s %s" % (re_prefix, reply_subject) + # get partner_ids from original message partner_ids = [partner.id for partner in message_data.partner_ids] if message_data.partner_ids else [] partner_ids += context.get('default_partner_ids', []) - if context.get('is_private',False) and message_data.author_id : #check message is private then add author also in partner list. + if context.get('is_private') and message_data.author_id: # check message is private then add author also in partner list. partner_ids += [message_data.author_id.id] # update the result - result = { + return { 'record_name': message_data.record_name, - 'model': message_data.model, - 'res_id': message_data.res_id, - 'parent_id': message_data.id, 'subject': reply_subject, 'partner_ids': partner_ids, } - return result #------------------------------------------------------ # Wizard validation and send @@ -244,16 +247,16 @@ class mail_compose_message(osv.TransientModel): is_log = context.get('mail_compose_log', False) for wizard in self.browse(cr, uid, ids, context=context): - mass_mail_mode = wizard.composition_mode == 'mass_mail' + mass_mode = wizard.composition_mode in ('mass_mail', 'mass_post') active_model_pool = self.pool[wizard.model if wizard.model else 'mail.thread'] if not hasattr(active_model_pool, 'message_post'): context['thread_model'] = wizard.model active_model_pool = self.pool['mail.thread'] # wizard works in batch mode: [res_id] or active_ids or active_domain - if mass_mail_mode and wizard.use_active_domain and wizard.model: + if mass_mode and wizard.use_active_domain and wizard.model: res_ids = self.pool[wizard.model].search(cr, uid, eval(wizard.active_domain), context=context) - elif mass_mail_mode and wizard.model and active_ids: + elif mass_mode and wizard.model and active_ids: res_ids = active_ids else: res_ids = [wizard.res_id] @@ -261,7 +264,9 @@ class mail_compose_message(osv.TransientModel): all_mail_values = self.get_mail_values(cr, uid, wizard, res_ids, context=context) for res_id, mail_values in all_mail_values.iteritems(): - if mass_mail_mode and not wizard.post: + if wizard.composition_mode == 'mass_mail': + if wizard.same_thread: # same thread: keep a copy of the message in the chatter to enable the reply redirection + mail_values.update(notification=True, model=wizard.model, res_id=res_id) m2m_attachment_ids = self.pool['mail.thread']._message_preprocess_attachments( cr, uid, mail_values.pop('attachments', []), mail_values.pop('attachment_ids', []), @@ -271,11 +276,9 @@ class mail_compose_message(osv.TransientModel): self.pool.get('mail.mail').create(cr, uid, mail_values, context=context) else: subtype = 'mail.mt_comment' - if is_log: # log a note: subtype is False + if is_log or (wizard.composition_mode == 'mass_post' and not wizard.notify): # log a note: subtype is False subtype = False - elif mass_mail_mode: # mass mail: is a log pushed to recipients unless specified, author not added - if not wizard.notify: - subtype = False + if wizard.composition_mode == 'mass_post': context = dict(context, mail_notify_force_send=False, # do not send emails directly but use the queue instead mail_create_nosubscribe=True) # add context key to avoid subscribing the author @@ -326,8 +329,7 @@ class mail_compose_message(osv.TransientModel): else: email_dict.pop('reply_to', None) mail_values.update(email_dict) - # mass mailing without post: mail_mail values - if mass_mail_mode and not wizard.post: + # mail_mail values if 'mail_auto_delete' in context: mail_values['auto_delete'] = context.get('mail_auto_delete') mail_values['body_html'] = mail_values.get('body', '') @@ -335,6 +337,10 @@ class mail_compose_message(osv.TransientModel): results[res_id] = mail_values return results + #------------------------------------------------------ + # Template rendering + #------------------------------------------------------ + def render_message_batch(self, cr, uid, wizard, res_ids, context=None): """Generate template-based values of wizard, for the document records given by res_ids. This method is meant to be inherited by email_template that -- cgit v1.2.3 From 4739eb138b4086ba2df76673d4a05f789f0c6512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 24 Feb 2014 14:20:38 +0100 Subject: [IMP] mail, email_template: still continuing work to improve performances of mass mailing. main differences : - record_name is not a function field anymore, but a char field + a method in create if not given (default-like, but dependent of other values). This allows the composer to give a value for record_name (False for email mass mailing) to avoid browsing records and having their access rights issues in the way - author_id, email_from coming from composer instead of called in every mail.message creation - moved code dealing with attachments from send_mail to get_mail-values, to that at the end of this method we know all values of the email Some tests have been updated / temporarily disabled. bzr revid: tde@openerp.com-20140224132038-txdi0g30a7fzbnxp --- addons/mail/wizard/mail_compose_message.py | 35 ++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'addons/mail/wizard/mail_compose_message.py') diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 292bcadd050..fc5a8f2181d 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -238,6 +238,8 @@ class mail_compose_message(osv.TransientModel): email(s), rendering any template patterns on the fly if needed. """ if context is None: context = {} + import datetime + print '--> beginning sending email', datetime.datetime.now() # clean the context (hint: mass mailing sets some default values that # could be wrongly interpreted by mail_mail) context.pop('default_email_to', None) @@ -261,20 +263,12 @@ class mail_compose_message(osv.TransientModel): else: res_ids = [wizard.res_id] + print '----> before computing values', datetime.datetime.now() all_mail_values = self.get_mail_values(cr, uid, wizard, res_ids, context=context) + print '----> after computing values', datetime.datetime.now() for res_id, mail_values in all_mail_values.iteritems(): if wizard.composition_mode == 'mass_mail': - if wizard.same_thread: # same thread: keep a copy of the message in the chatter to enable the reply redirection - mail_values.update(notification=True, model=wizard.model, res_id=res_id) - m2m_attachment_ids = self.pool['mail.thread']._message_preprocess_attachments( - cr, uid, mail_values.pop('attachments', []), - mail_values.pop('attachment_ids', []), - 'mail.message', 0, - context=context) - mail_values['attachment_ids'] = m2m_attachment_ids - if not mail_values.get('reply_to'): - mail_values['reply_to'] = mail_values['email_from'] self.pool.get('mail.mail').create(cr, uid, mail_values, context=context) else: subtype = 'mail.mt_comment' @@ -286,6 +280,7 @@ class mail_compose_message(osv.TransientModel): mail_create_nosubscribe=True) # add context key to avoid subscribing the author active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **mail_values) + print '--> finished sending email', datetime.datetime.now() return {'type': 'ir.actions.act_window_close'} def get_mail_values(self, cr, uid, wizard, res_ids, context=None): @@ -306,9 +301,12 @@ class mail_compose_message(osv.TransientModel): 'parent_id': wizard.parent_id and wizard.parent_id.id, 'partner_ids': [partner.id for partner in wizard.partner_ids], 'attachment_ids': [attach.id for attach in wizard.attachment_ids], + 'author_id': wizard.author_id.id, + 'email_from': wizard.email_from, } # mass mailing: rendering override wizard static values if mass_mail_mode and wizard.model: + # rendered values using template email_dict = rendered_values[res_id] mail_values['partner_ids'] += email_dict.pop('partner_ids', []) # process attachments: should not be encoded before being processed by message_post / mail_mail create @@ -326,16 +324,31 @@ class mail_compose_message(osv.TransientModel): if email_dict.get('email_from'): mail_values['email_from'] = email_dict.pop('email_from') # replies redirection: mass mailing only - if wizard.same_thread and wizard.post: + if wizard.same_thread: email_dict.pop('reply_to', None) else: mail_values['reply_to'] = email_dict.pop('reply_to', None) mail_values.update(email_dict) + + # value tweaking in mass mailing + mail_values['record_name'] = False # avoid browsing the record for an email + if wizard.same_thread: # same thread: keep a copy of the message in the chatter to enable the reply redirection + mail_values.update(notification=True, model=wizard.model, res_id=res_id) + m2m_attachment_ids = self.pool['mail.thread']._message_preprocess_attachments( + cr, uid, mail_values.pop('attachments', []), + mail_values.pop('attachment_ids', []), + 'mail.message', 0, + context=context) + mail_values['attachment_ids'] = m2m_attachment_ids + if not mail_values.get('reply_to'): + mail_values['reply_to'] = mail_values['email_from'] + # mail_mail values if 'mail_auto_delete' in context: mail_values['auto_delete'] = context.get('mail_auto_delete') mail_values['body_html'] = mail_values.get('body', '') mail_values['recipient_ids'] = [(4, id) for id in mail_values.pop('partner_ids', [])] + results[res_id] = mail_values return results -- cgit v1.2.3 From dd99c96ca295a4c55750cea6ef08e37a50304bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 24 Feb 2014 15:22:36 +0100 Subject: [CLEAN] mail: some code cleaning in the modifications bzr revid: tde@openerp.com-20140224142236-l61eqddc4vq9y861 --- addons/mail/wizard/mail_compose_message.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'addons/mail/wizard/mail_compose_message.py') diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index fc5a8f2181d..d509021c5d2 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -121,9 +121,9 @@ class mail_compose_message(osv.TransientModel): 'use_active_domain': fields.boolean('Use active domain'), 'active_domain': fields.char('Active domain', readonly=True), 'notify': fields.boolean('Notify followers', - help='Notify followers of the document'), + help='Notify followers of the document (mass post only)'), 'same_thread': fields.boolean('Replies in the document', - help='Replies to the messages will go into the selected document.'), + help='Replies to the messages will go into the selected document (mass mail only)'), 'attachment_ids': fields.many2many('ir.attachment', 'mail_compose_message_ir_attachments_rel', 'wizard_id', 'attachment_id', 'Attachments'), @@ -245,9 +245,6 @@ class mail_compose_message(osv.TransientModel): context.pop('default_email_to', None) context.pop('default_partner_ids', None) - active_ids = context.get('active_ids') - is_log = context.get('mail_compose_log', False) - for wizard in self.browse(cr, uid, ids, context=context): mass_mode = wizard.composition_mode in ('mass_mail', 'mass_post') active_model_pool = self.pool[wizard.model if wizard.model else 'mail.thread'] @@ -258,8 +255,8 @@ class mail_compose_message(osv.TransientModel): # wizard works in batch mode: [res_id] or active_ids or active_domain if mass_mode and wizard.use_active_domain and wizard.model: res_ids = self.pool[wizard.model].search(cr, uid, eval(wizard.active_domain), context=context) - elif mass_mode and wizard.model and active_ids: - res_ids = active_ids + elif mass_mode and wizard.model and context.get('active_ids'): + res_ids = context['active_ids'] else: res_ids = [wizard.res_id] @@ -269,10 +266,10 @@ class mail_compose_message(osv.TransientModel): for res_id, mail_values in all_mail_values.iteritems(): if wizard.composition_mode == 'mass_mail': - self.pool.get('mail.mail').create(cr, uid, mail_values, context=context) + self.pool['mail.mail'].create(cr, uid, mail_values, context=context) else: subtype = 'mail.mt_comment' - if is_log or (wizard.composition_mode == 'mass_post' and not wizard.notify): # log a note: subtype is False + if context.get('mail_compose_log') or (wizard.composition_mode == 'mass_post' and not wizard.notify): # log a note: subtype is False subtype = False if wizard.composition_mode == 'mass_post': context = dict(context, -- cgit v1.2.3 From 48098b5df135df3a709b533ae3ba20be01cc659b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 14 Mar 2014 18:48:27 +0100 Subject: [IMP] mail.compose.message: removed unnecessary code, email_from is already corretly managed bzr revid: tde@openerp.com-20140314174827-nent5v02s2v2y2n0 --- addons/mail/wizard/mail_compose_message.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'addons/mail/wizard/mail_compose_message.py') diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index ed36718fe67..fc331cb4b6d 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -317,9 +317,6 @@ class mail_compose_message(osv.TransientModel): new_attach_id = self.pool.get('ir.attachment').copy(cr, uid, attach_id, {'res_model': self._name, 'res_id': wizard.id}, context=context) attachment_ids.append(new_attach_id) mail_values['attachment_ids'] = attachment_ids - # email_from: mass mailing only can specify another email_from - if email_dict.get('email_from'): - mail_values['email_from'] = email_dict.pop('email_from') # replies redirection: mass mailing only if wizard.same_thread: email_dict.pop('reply_to', None) -- cgit v1.2.3 From 48deceb6c6e19be497cc623828c6eff361d6c081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 17 Mar 2014 12:53:15 +0100 Subject: [IMP] [REF] mail_compose_message: slightly cleaned wizard code to lessen the number of corner cases and to remove unnecessary code. post and filter_id fields have been removed as they are not necessary. Updated tests accordingly to new mass mailing tests: mass mailing create emails, no message_post anymore using followers. bzr revid: tde@openerp.com-20140317115315-ws8dvjbiv5rspk43 --- addons/mail/wizard/mail_compose_message.py | 183 +++++++++++++---------------- 1 file changed, 83 insertions(+), 100 deletions(-) (limited to 'addons/mail/wizard/mail_compose_message.py') diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index fc331cb4b6d..7bdc344d28b 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -38,10 +38,7 @@ class mail_compose_message(osv.TransientModel): at model and view levels to provide specific features. The behavior of the wizard depends on the composition_mode field: - - 'reply': reply to a previous message. The wizard is pre-populated - via ``get_message_data``. - - 'comment': new post on a record. The wizard is pre-populated via - ``get_record_data`` + - 'comment': post on a record. The wizard is pre-populated via ``get_record_data`` - 'mass_mail': wizard in mass mailing mode where the mail details can contain template placeholders that will be merged with actual data before being sent to each recipient. @@ -50,6 +47,7 @@ class mail_compose_message(osv.TransientModel): _inherit = 'mail.message' _description = 'Email composition wizard' _log_access = True + _batch_size = 500 def default_get(self, cr, uid, fields, context=None): """ Handle composition mode. Some details about context keys: @@ -82,10 +80,8 @@ class mail_compose_message(osv.TransientModel): if 'active_domain' in context: # not context.get() because we want to keep global [] domains vals['use_active_domain'] = True vals['active_domain'] = '%s' % context.get('active_domain') - if result.get('parent_id'): - vals.update(self.get_message_data(cr, uid, result.get('parent_id'), context=context)) - if result['composition_mode'] == 'comment' and result['model'] and result['res_id']: - vals.update(self.get_record_data(cr, uid, result['model'], result['res_id'], context=context)) + if result['composition_mode'] == 'comment': + vals.update(self.get_record_data(cr, uid, result, context=context)) result['recipients_data'] = self.get_recipients_data(cr, uid, result, context=context) for field in vals: @@ -120,14 +116,14 @@ class mail_compose_message(osv.TransientModel): help='Helper field used in mass mailing to display a sample of recipients'), 'use_active_domain': fields.boolean('Use active domain'), 'active_domain': fields.char('Active domain', readonly=True), + 'attachment_ids': fields.many2many('ir.attachment', + 'mail_compose_message_ir_attachments_rel', + 'wizard_id', 'attachment_id', 'Attachments'), + # mass mode options 'notify': fields.boolean('Notify followers', help='Notify followers of the document (mass post only)'), 'same_thread': fields.boolean('Replies in the document', help='Replies to the messages will go into the selected document (mass mail only)'), - 'attachment_ids': fields.many2many('ir.attachment', - 'mail_compose_message_ir_attachments_rel', - 'wizard_id', 'attachment_id', 'Attachments'), - 'filter_id': fields.many2one('ir.filters', 'Filters'), } #TODO change same_thread to False in trunk (Require view update) _defaults = { @@ -135,7 +131,6 @@ class mail_compose_message(osv.TransientModel): 'body': lambda self, cr, uid, ctx={}: '', 'subject': lambda self, cr, uid, ctx={}: False, 'partner_ids': lambda self, cr, uid, ctx={}: [], - 'notify': True, 'same_thread': True, } @@ -175,58 +170,54 @@ class mail_compose_message(osv.TransientModel): doc_name = self.pool[model].name_get(cr, uid, [res_id], context=context) return doc_name and 'Followers of %s' % doc_name[0][1] or False elif composition_mode == 'mass_post' and model: - active_ids = context.get('active_ids', list()) - if not active_ids: - return False - name_gets = [rec_name[1] for rec_name in self.pool[model].name_get(cr, uid, active_ids[:3], context=context)] - return 'Followers of selected documents (' + ', '.join(name_gets) + len(active_ids) > 3 and ', ...' or '' + ')' + if 'active_domain' in context: + active_ids = self.pool[model].search(cr, uid, eval(context['active_domain']), limit=100, context=context) + else: + active_ids = context.get('active_ids', list()) + if active_ids: + name_gets = [rec_name[1] for rec_name in self.pool[model].name_get(cr, uid, active_ids[:3], context=context)] + return 'Followers of selected documents (' + ', '.join(name_gets) + len(active_ids) > 3 and ', ...' or '' + ')' return False - def get_record_data(self, cr, uid, model, res_id, context=None): + def get_record_data(self, cr, uid, values, context=None): """ Returns a defaults-like dict with initial values for the composition wizard when sending an email related to the document record identified by ``model`` and ``res_id``. - :param str model: model name of the document record this mail is - related to. - :param int res_id: id of the document record this mail is related to - """ - doc_name_get = self.pool[model].name_get(cr, uid, [res_id], context=context) - return { - 'record_name': doc_name_get and doc_name_get[0][1] or False, - 'subject': doc_name_get and 'Re: %s' % doc_name_get[0][1] or False, - } - - def get_message_data(self, cr, uid, message_id, context=None): - """ Returns a defaults-like dict with initial values for the composition - wizard when replying to the given message (e.g. including the quote - of the initial message, and the correct recipients). - - :param int message_id: id of the mail.message to which the user - is replying. - """ - if not message_id: - return {} + :param values: dictionary of default and already computed values for the mail_compose_message_res_partner_re + :type values: dict""" if context is None: context = {} - message_data = self.pool.get('mail.message').browse(cr, uid, message_id, context=context) + model, res_id, parent_id = values.get('model'), values.get('res_id'), values.get('parent_id') + record_name, subject, partner_ids = values.get('record_name'), values.get('subject'), values.get('partner_ids', list()) + if parent_id: + message_data = self.pool.get('mail.message').browse(cr, uid, parent_id, context=context) + record_name = message_data.record_name, + subject = tools.ustr(message_data.subject or message_data.record_name or '') + if not model: + model = message_data.model + if not res_id: + res_id = message_data.res_id + # get partner_ids from original message + partner_ids += [partner.id for partner in message_data.partner_ids] + if context.get('is_private') and message_data.author_id: # check message is private then add author also in partner list. + partner_ids += [message_data.author_id.id] + elif model and res_id: + doc_name_get = self.pool[model].name_get(cr, uid, [res_id], context=context) + record_name = doc_name_get and doc_name_get[0][1] or '' + subject = tools.ustr(record_name) # create subject re_prefix = _('Re:') - reply_subject = tools.ustr(message_data.subject or message_data.record_name or '') - if not (reply_subject.startswith('Re:') or reply_subject.startswith(re_prefix)): - reply_subject = "%s %s" % (re_prefix, reply_subject) - - # get partner_ids from original message - partner_ids = [partner.id for partner in message_data.partner_ids] if message_data.partner_ids else [] - partner_ids += context.get('default_partner_ids', []) - if context.get('is_private') and message_data.author_id: # check message is private then add author also in partner list. - partner_ids += [message_data.author_id.id] - # update the result + if not (subject.startswith('Re:') or subject.startswith(re_prefix)): + subject = "%s %s" % (re_prefix, subject) + return { - 'record_name': message_data.record_name, - 'subject': reply_subject, - 'partner_ids': partner_ids, + 'record_name': record_name, + 'subject': subject, + 'partner_ids': list(set(partner_ids)), + 'model': model, + 'res_id': res_id, } #------------------------------------------------------ @@ -238,8 +229,8 @@ class mail_compose_message(osv.TransientModel): email(s), rendering any template patterns on the fly if needed. """ if context is None: context = {} - import datetime - print '--> beginning sending email', datetime.datetime.now() + # import datetime + # print '--> beginning sending email', datetime.datetime.now() # clean the context (hint: mass mailing sets some default values that # could be wrongly interpreted by mail_mail) context.pop('default_email_to', None) @@ -260,24 +251,26 @@ class mail_compose_message(osv.TransientModel): else: res_ids = [wizard.res_id] - print '----> before computing values', datetime.datetime.now() - all_mail_values = self.get_mail_values(cr, uid, wizard, res_ids, context=context) - print '----> after computing values', datetime.datetime.now() - - for res_id, mail_values in all_mail_values.iteritems(): - if wizard.composition_mode == 'mass_mail': - self.pool['mail.mail'].create(cr, uid, mail_values, context=context) - else: - subtype = 'mail.mt_comment' - if context.get('mail_compose_log') or (wizard.composition_mode == 'mass_post' and not wizard.notify): # log a note: subtype is False - subtype = False - if wizard.composition_mode == 'mass_post': - context = dict(context, - mail_notify_force_send=False, # do not send emails directly but use the queue instead - mail_create_nosubscribe=True) # add context key to avoid subscribing the author - active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **mail_values) - - print '--> finished sending email', datetime.datetime.now() + # print '----> before computing values', datetime.datetime.now() + # print '----> after computing values', datetime.datetime.now() + + sliced_res_ids = [res_ids[i:i + self._batch_size] for i in range(0, len(res_ids), self._batch_size)] + for res_ids in sliced_res_ids: + all_mail_values = self.get_mail_values(cr, uid, wizard, res_ids, context=context) + for res_id, mail_values in all_mail_values.iteritems(): + if wizard.composition_mode == 'mass_mail': + self.pool['mail.mail'].create(cr, uid, mail_values, context=context) + else: + subtype = 'mail.mt_comment' + if context.get('mail_compose_log') or (wizard.composition_mode == 'mass_post' and not wizard.notify): # log a note: subtype is False + subtype = False + if wizard.composition_mode == 'mass_post': + context = dict(context, + mail_notify_force_send=False, # do not send emails directly but use the queue instead + mail_create_nosubscribe=True) # add context key to avoid subscribing the author + active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **mail_values) + + # print '--> finished sending email', datetime.datetime.now() return {'type': 'ir.actions.act_window_close'} def get_mail_values(self, cr, uid, wizard, res_ids, context=None): @@ -300,46 +293,36 @@ class mail_compose_message(osv.TransientModel): 'attachment_ids': [attach.id for attach in wizard.attachment_ids], 'author_id': wizard.author_id.id, 'email_from': wizard.email_from, + 'record_name': wizard.record_name, } # mass mailing: rendering override wizard static values if mass_mail_mode and wizard.model: + # always keep a copy, reset record name (avoid browsing records) + mail_values.update(notification=True, model=wizard.model, res_id=res_id, record_name=False) + # auto deletion of mail_mail + if 'mail_auto_delete' in context: + mail_values['auto_delete'] = context.get('mail_auto_delete') # rendered values using template email_dict = rendered_values[res_id] mail_values['partner_ids'] += email_dict.pop('partner_ids', []) - # process attachments: should not be encoded before being processed by message_post / mail_mail create - attachments = [] - if email_dict.get('attachments'): - for name, enc_cont in email_dict.pop('attachments'): - attachments.append((name, base64.b64decode(enc_cont))) - mail_values['attachments'] = attachments - attachment_ids = [] - for attach_id in mail_values.pop('attachment_ids'): - new_attach_id = self.pool.get('ir.attachment').copy(cr, uid, attach_id, {'res_model': self._name, 'res_id': wizard.id}, context=context) - attachment_ids.append(new_attach_id) - mail_values['attachment_ids'] = attachment_ids - # replies redirection: mass mailing only if wizard.same_thread: email_dict.pop('reply_to', None) else: mail_values['reply_to'] = email_dict.pop('reply_to', None) + # if not mail_values.get('reply_to'): + # mail_values['reply_to'] = mail_values['email_from'] mail_values.update(email_dict) - # value tweaking in mass mailing - mail_values['record_name'] = False # avoid browsing the record for an email - if wizard.same_thread: # same thread: keep a copy of the message in the chatter to enable the reply redirection - mail_values.update(notification=True, model=wizard.model, res_id=res_id) - m2m_attachment_ids = self.pool['mail.thread']._message_preprocess_attachments( + # process attachments: should not be encoded before being processed by message_post / mail_mail create + mail_values['attachments'] = [(name, base64.b64decode(enc_cont)) for name, enc_cont in email_dict.pop('attachments', list())] + attachment_ids = [] + for attach_id in mail_values.pop('attachment_ids'): + new_attach_id = self.pool.get('ir.attachment').copy(cr, uid, attach_id, {'res_model': self._name, 'res_id': wizard.id}, context=context) + attachment_ids.append(new_attach_id) + mail_values['attachment_ids'] = self.pool['mail.thread']._message_preprocess_attachments( cr, uid, mail_values.pop('attachments', []), - mail_values.pop('attachment_ids', []), - 'mail.message', 0, - context=context) - mail_values['attachment_ids'] = m2m_attachment_ids - if not mail_values.get('reply_to'): - mail_values['reply_to'] = mail_values['email_from'] - - # mail_mail values - if 'mail_auto_delete' in context: - mail_values['auto_delete'] = context.get('mail_auto_delete') + attachment_ids, 'mail.message', 0, context=context) + # mail_mail values: body -> body_html, partner_ids -> recipient_ids mail_values['body_html'] = mail_values.get('body', '') mail_values['recipient_ids'] = [(4, id) for id in mail_values.pop('partner_ids', [])] -- cgit v1.2.3 From d5a8905941f6af1245721d985e2a01f76d170a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 17 Mar 2014 13:24:09 +0100 Subject: [IMP] mail_compose_message: added is_log boolean field for internal notes; + removed context hack that did the same thing. Fixed composer form view: internal note, only subject + body is displayed. bzr revid: tde@openerp.com-20140317122409-5fd5d5uwc35oq0hb --- addons/mail/wizard/mail_compose_message.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'addons/mail/wizard/mail_compose_message.py') diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 7bdc344d28b..5e235dd0010 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -119,6 +119,8 @@ class mail_compose_message(osv.TransientModel): 'attachment_ids': fields.many2many('ir.attachment', 'mail_compose_message_ir_attachments_rel', 'wizard_id', 'attachment_id', 'Attachments'), + 'is_log': fields.boolean('Log an Internal Note', + help='Whether the message is an internal note (comment mode only)'), # mass mode options 'notify': fields.boolean('Notify followers', help='Notify followers of the document (mass post only)'), -- cgit v1.2.3 From 43cc0540485f1fa4bdaf28e1a91cd944f5905265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 17 Mar 2014 14:22:27 +0100 Subject: [FIX] mail_compose_message: create Re subject only when having a parent bzr revid: tde@openerp.com-20140317132227-mcey6ywjr1g6pe9g --- addons/mail/wizard/mail_compose_message.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'addons/mail/wizard/mail_compose_message.py') diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 5e235dd0010..367597d347a 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -204,16 +204,15 @@ class mail_compose_message(osv.TransientModel): partner_ids += [partner.id for partner in message_data.partner_ids] if context.get('is_private') and message_data.author_id: # check message is private then add author also in partner list. partner_ids += [message_data.author_id.id] + # create subject + re_prefix = _('Re:') + if not (subject.startswith('Re:') or subject.startswith(re_prefix)): + subject = "%s %s" % (re_prefix, subject) elif model and res_id: doc_name_get = self.pool[model].name_get(cr, uid, [res_id], context=context) record_name = doc_name_get and doc_name_get[0][1] or '' subject = tools.ustr(record_name) - # create subject - re_prefix = _('Re:') - if not (subject.startswith('Re:') or subject.startswith(re_prefix)): - subject = "%s %s" % (re_prefix, subject) - return { 'record_name': record_name, 'subject': subject, -- cgit v1.2.3 From 79cb083a623cb46ec36b37f839487d98b0b029fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 21 Mar 2014 18:17:23 +0100 Subject: [IMP] mail: mail_compose_message: some code cleaning in get_record_data + code cleaning in get_mail_values + management of the previously introduced method get_default_recipients, to be sure that in mass mailing an email is effectively sent to a customer / lead / applicant / ... because with an ill-configured template, you could have mass amiling mailing nobody. bzr revid: tde@openerp.com-20140321171723-7e3lk64knojf09at --- addons/mail/wizard/mail_compose_message.py | 90 +++++++++++++++--------------- 1 file changed, 45 insertions(+), 45 deletions(-) (limited to 'addons/mail/wizard/mail_compose_message.py') diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 367597d347a..43259d3dd3e 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -183,43 +183,35 @@ class mail_compose_message(osv.TransientModel): def get_record_data(self, cr, uid, values, context=None): """ Returns a defaults-like dict with initial values for the composition - wizard when sending an email related to the document record - identified by ``model`` and ``res_id``. - - :param values: dictionary of default and already computed values for the mail_compose_message_res_partner_re - :type values: dict""" + wizard when sending an email related a previous email (parent_id) or + a document (model, res_id). This is based on previously computed default + values. """ if context is None: context = {} - model, res_id, parent_id = values.get('model'), values.get('res_id'), values.get('parent_id') - record_name, subject, partner_ids = values.get('record_name'), values.get('subject'), values.get('partner_ids', list()) - if parent_id: - message_data = self.pool.get('mail.message').browse(cr, uid, parent_id, context=context) - record_name = message_data.record_name, - subject = tools.ustr(message_data.subject or message_data.record_name or '') - if not model: - model = message_data.model - if not res_id: - res_id = message_data.res_id - # get partner_ids from original message - partner_ids += [partner.id for partner in message_data.partner_ids] - if context.get('is_private') and message_data.author_id: # check message is private then add author also in partner list. - partner_ids += [message_data.author_id.id] - # create subject - re_prefix = _('Re:') - if not (subject.startswith('Re:') or subject.startswith(re_prefix)): - subject = "%s %s" % (re_prefix, subject) - elif model and res_id: - doc_name_get = self.pool[model].name_get(cr, uid, [res_id], context=context) - record_name = doc_name_get and doc_name_get[0][1] or '' - subject = tools.ustr(record_name) - - return { - 'record_name': record_name, - 'subject': subject, - 'partner_ids': list(set(partner_ids)), - 'model': model, - 'res_id': res_id, - } + result, subject = {}, False + if values.get('parent_id'): + parent = self.pool.get('mail.message').browse(cr, uid, values.get('parent_id'), context=context) + result['record_name'] = parent.record_name, + subject = tools.ustr(parent.subject or parent.record_name or '') + if not values.get('model'): + result['model'] = parent.model + if not values.get('res_id'): + result['res_id'] = parent.res_id + partner_ids = values.get('partner_ids', list()) + [partner.id for partner in parent.partner_ids] + if context.get('is_private') and parent.author_id: # check message is private then add author also in partner list. + partner_ids += [parent.author_id.id] + result['partner_ids'] = partner_ids + elif values.get('model') and values.get('res_id'): + doc_name_get = self.pool[values.get('model')].name_get(cr, uid, [values.get('res_id')], context=context) + result['record_name'] = doc_name_get and doc_name_get[0][1] or '' + subject = tools.ustr(result['record_name']) + + re_prefix = _('Re:') + if subject and not (subject.startswith('Re:') or subject.startswith(re_prefix)): + subject = "%s %s" % (re_prefix, subject) + result['subject'] = subject + + return result #------------------------------------------------------ # Wizard validation and send @@ -278,12 +270,17 @@ class mail_compose_message(osv.TransientModel): """Generate the values that will be used by send_mail to create mail_messages or mail_mails. """ results = dict.fromkeys(res_ids, False) + rendered_values, default_recipients = {}, {} mass_mail_mode = wizard.composition_mode == 'mass_mail' # render all template-based value at once if mass_mail_mode and wizard.model: rendered_values = self.render_message_batch(cr, uid, wizard, res_ids, context=context) + # # get default recipients for mass mailing + # if mass_mail_mode and hasattr(self.pool[wizard.model], 'message_get_default_recipients'): + # default_recipients = self.pool[wizard.model].message_get_default_recipients(cr, uid, res_ids, context=context) + for res_id in res_ids: # static wizard (mail.message) values mail_values = { @@ -305,14 +302,20 @@ class mail_compose_message(osv.TransientModel): mail_values['auto_delete'] = context.get('mail_auto_delete') # rendered values using template email_dict = rendered_values[res_id] + print email_dict mail_values['partner_ids'] += email_dict.pop('partner_ids', []) - if wizard.same_thread: - email_dict.pop('reply_to', None) - else: - mail_values['reply_to'] = email_dict.pop('reply_to', None) - # if not mail_values.get('reply_to'): - # mail_values['reply_to'] = mail_values['email_from'] mail_values.update(email_dict) + if wizard.same_thread: + mail_values.pop('reply_to') + elif not mail_values.get('reply_to'): + mail_values['reply_to'] = mail_values['email_from'] + # mail_mail values: body -> body_html, partner_ids -> recipient_ids + mail_values['body_html'] = mail_values.get('body', '') + mail_values['recipient_ids'] = [(4, id) for id in mail_values.pop('partner_ids', [])] + # add some specific recipients depending on the model, to be sure some are mailed + if default_recipients.get(res_id): + mail_values['recipient_ids'] += [(4, id) for id in default_recipients[res_id]['recipient_ids']] + mail_values['email_to'] = ','.join(filter(None, [mail_values.get('email_to', ''), default_recipients[res_id]['email_to']])) # process attachments: should not be encoded before being processed by message_post / mail_mail create mail_values['attachments'] = [(name, base64.b64decode(enc_cont)) for name, enc_cont in email_dict.pop('attachments', list())] @@ -323,10 +326,7 @@ class mail_compose_message(osv.TransientModel): mail_values['attachment_ids'] = self.pool['mail.thread']._message_preprocess_attachments( cr, uid, mail_values.pop('attachments', []), attachment_ids, 'mail.message', 0, context=context) - # mail_mail values: body -> body_html, partner_ids -> recipient_ids - mail_values['body_html'] = mail_values.get('body', '') - mail_values['recipient_ids'] = [(4, id) for id in mail_values.pop('partner_ids', [])] - + print mail_values results[res_id] = mail_values return results -- cgit v1.2.3 From 73bebb6563b1bd9d031ffc28d73fcce084df90a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 25 Mar 2014 14:53:47 +0100 Subject: [IMP] mail: default recipients management - mail.compose.message: in render_message_batch, compute defaults recipients for the composer (method called for mass mailing only). This way values are available for inheriting models. bzr revid: tde@openerp.com-20140325135347-9v7u4uokffy7ud43 --- addons/mail/wizard/mail_compose_message.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'addons/mail/wizard/mail_compose_message.py') diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 43259d3dd3e..74f8d2f8e57 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -224,6 +224,7 @@ class mail_compose_message(osv.TransientModel): context = {} # import datetime # print '--> beginning sending email', datetime.datetime.now() + # clean the context (hint: mass mailing sets some default values that # could be wrongly interpreted by mail_mail) context.pop('default_email_to', None) @@ -277,10 +278,6 @@ class mail_compose_message(osv.TransientModel): if mass_mail_mode and wizard.model: rendered_values = self.render_message_batch(cr, uid, wizard, res_ids, context=context) - # # get default recipients for mass mailing - # if mass_mail_mode and hasattr(self.pool[wizard.model], 'message_get_default_recipients'): - # default_recipients = self.pool[wizard.model].message_get_default_recipients(cr, uid, res_ids, context=context) - for res_id in res_ids: # static wizard (mail.message) values mail_values = { @@ -302,7 +299,6 @@ class mail_compose_message(osv.TransientModel): mail_values['auto_delete'] = context.get('mail_auto_delete') # rendered values using template email_dict = rendered_values[res_id] - print email_dict mail_values['partner_ids'] += email_dict.pop('partner_ids', []) mail_values.update(email_dict) if wizard.same_thread: @@ -312,10 +308,6 @@ class mail_compose_message(osv.TransientModel): # mail_mail values: body -> body_html, partner_ids -> recipient_ids mail_values['body_html'] = mail_values.get('body', '') mail_values['recipient_ids'] = [(4, id) for id in mail_values.pop('partner_ids', [])] - # add some specific recipients depending on the model, to be sure some are mailed - if default_recipients.get(res_id): - mail_values['recipient_ids'] += [(4, id) for id in default_recipients[res_id]['recipient_ids']] - mail_values['email_to'] = ','.join(filter(None, [mail_values.get('email_to', ''), default_recipients[res_id]['email_to']])) # process attachments: should not be encoded before being processed by message_post / mail_mail create mail_values['attachments'] = [(name, base64.b64decode(enc_cont)) for name, enc_cont in email_dict.pop('attachments', list())] @@ -326,7 +318,7 @@ class mail_compose_message(osv.TransientModel): mail_values['attachment_ids'] = self.pool['mail.thread']._message_preprocess_attachments( cr, uid, mail_values.pop('attachments', []), attachment_ids, 'mail.message', 0, context=context) - print mail_values + results[res_id] = mail_values return results @@ -343,6 +335,10 @@ class mail_compose_message(osv.TransientModel): once, and render it multiple times. This is useful for mass mailing where template rendering represent a significant part of the process. + Default recipients are also computed, based on mail_thread method + message_get_default_recipients. This allows to ensure a mass mailing has + always some recipients specified. + :param browse wizard: current mail.compose.message browse record :param list res_ids: list of record ids @@ -354,6 +350,14 @@ class mail_compose_message(osv.TransientModel): emails_from = self.render_template_batch(cr, uid, wizard.email_from, wizard.model, res_ids, context=context) replies_to = self.render_template_batch(cr, uid, wizard.reply_to, wizard.model, res_ids, context=context) + if wizard.model and hasattr(self.pool[wizard.model], 'message_get_default_recipients'): + default_recipients = self.pool[wizard.model].message_get_default_recipients(cr, uid, res_ids, context=context) + elif wizard.model: + ctx = dict(context, thread_model=wizard.model) + default_recipients = self.pool['mail.thread'].message_get_default_recipients(cr, uid, res_ids, context=ctx) + else: + default_recipients = {} + results = dict.fromkeys(res_ids, False) for res_id in res_ids: results[res_id] = { @@ -362,6 +366,7 @@ class mail_compose_message(osv.TransientModel): 'email_from': emails_from[res_id], 'reply_to': replies_to[res_id], } + results[res_id].update(default_recipients.get(res_id, dict())) return results def render_template_batch(self, cr, uid, template, model, res_ids, context=None, post_process=False): -- cgit v1.2.3 From 55fc583f36b4764592d196e2f5d3c7b8ded50077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 15 Apr 2014 16:33:43 +0200 Subject: [REM] mail: compose message: removed unnecessary code bzr revid: tde@openerp.com-20140415143343-on2d3j92o6zifq59 --- addons/mail/wizard/mail_compose_message.py | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'addons/mail/wizard/mail_compose_message.py') diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 74f8d2f8e57..52bdbf8ebf1 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -82,7 +82,6 @@ class mail_compose_message(osv.TransientModel): vals['active_domain'] = '%s' % context.get('active_domain') if result['composition_mode'] == 'comment': vals.update(self.get_record_data(cr, uid, result, context=context)) - result['recipients_data'] = self.get_recipients_data(cr, uid, result, context=context) for field in vals: if field in fields: @@ -112,8 +111,6 @@ class mail_compose_message(osv.TransientModel): 'partner_ids': fields.many2many('res.partner', 'mail_compose_message_res_partner_rel', 'wizard_id', 'partner_id', 'Additional Contacts'), - 'recipients_data': fields.text(string='Recipients Data', - help='Helper field used in mass mailing to display a sample of recipients'), 'use_active_domain': fields.boolean('Use active domain'), 'active_domain': fields.char('Active domain', readonly=True), 'attachment_ids': fields.many2many('ir.attachment', @@ -164,23 +161,6 @@ class mail_compose_message(osv.TransientModel): not want that feature in the wizard. """ return - def get_recipients_data(self, cr, uid, values, context=None): - """ Returns a string explaining the targetted recipients, to ease the use - of the wizard. """ - composition_mode, model, res_id = values['composition_mode'], values['model'], values['res_id'] - if composition_mode == 'comment' and model and res_id: - doc_name = self.pool[model].name_get(cr, uid, [res_id], context=context) - return doc_name and 'Followers of %s' % doc_name[0][1] or False - elif composition_mode == 'mass_post' and model: - if 'active_domain' in context: - active_ids = self.pool[model].search(cr, uid, eval(context['active_domain']), limit=100, context=context) - else: - active_ids = context.get('active_ids', list()) - if active_ids: - name_gets = [rec_name[1] for rec_name in self.pool[model].name_get(cr, uid, active_ids[:3], context=context)] - return 'Followers of selected documents (' + ', '.join(name_gets) + len(active_ids) > 3 and ', ...' or '' + ')' - return False - def get_record_data(self, cr, uid, values, context=None): """ Returns a defaults-like dict with initial values for the composition wizard when sending an email related a previous email (parent_id) or -- cgit v1.2.3 From 98472d82534101bc23b2364fa62dea81420c86cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 15 Apr 2014 16:49:43 +0200 Subject: [CLEAN] Removed commented print bzr revid: tde@openerp.com-20140415144943-ov6g4n9tzjxtwlk9 --- addons/mail/wizard/mail_compose_message.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'addons/mail/wizard/mail_compose_message.py') diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 52bdbf8ebf1..842ddcb90a7 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -202,8 +202,6 @@ class mail_compose_message(osv.TransientModel): email(s), rendering any template patterns on the fly if needed. """ if context is None: context = {} - # import datetime - # print '--> beginning sending email', datetime.datetime.now() # clean the context (hint: mass mailing sets some default values that # could be wrongly interpreted by mail_mail) @@ -225,9 +223,6 @@ class mail_compose_message(osv.TransientModel): else: res_ids = [wizard.res_id] - # print '----> before computing values', datetime.datetime.now() - # print '----> after computing values', datetime.datetime.now() - sliced_res_ids = [res_ids[i:i + self._batch_size] for i in range(0, len(res_ids), self._batch_size)] for res_ids in sliced_res_ids: all_mail_values = self.get_mail_values(cr, uid, wizard, res_ids, context=context) @@ -244,7 +239,6 @@ class mail_compose_message(osv.TransientModel): mail_create_nosubscribe=True) # add context key to avoid subscribing the author active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **mail_values) - # print '--> finished sending email', datetime.datetime.now() return {'type': 'ir.actions.act_window_close'} def get_mail_values(self, cr, uid, wizard, res_ids, context=None): -- cgit v1.2.3 From 3eaeae55a03da0244d5eef821dfa81cd0c911764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 15 Apr 2014 17:47:00 +0200 Subject: [IMP] mail, mass_mailing: better recipientsz computation for mass mailing, composer and template. This allows to have one method computing recipints and avoid repetiting myself. bzr revid: tde@openerp.com-20140415154700-zu2izvxfjq1k4h4a --- addons/mail/wizard/mail_compose_message.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'addons/mail/wizard/mail_compose_message.py') diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 842ddcb90a7..e14a8f3dfe5 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -324,13 +324,8 @@ class mail_compose_message(osv.TransientModel): emails_from = self.render_template_batch(cr, uid, wizard.email_from, wizard.model, res_ids, context=context) replies_to = self.render_template_batch(cr, uid, wizard.reply_to, wizard.model, res_ids, context=context) - if wizard.model and hasattr(self.pool[wizard.model], 'message_get_default_recipients'): - default_recipients = self.pool[wizard.model].message_get_default_recipients(cr, uid, res_ids, context=context) - elif wizard.model: - ctx = dict(context, thread_model=wizard.model) - default_recipients = self.pool['mail.thread'].message_get_default_recipients(cr, uid, res_ids, context=ctx) - else: - default_recipients = {} + ctx = dict(context, thread_model=wizard.model) + default_recipients = self.pool['mail.thread'].message_get_default_recipients(cr, uid, res_ids, context=ctx) results = dict.fromkeys(res_ids, False) for res_id in res_ids: -- cgit v1.2.3