[MERGE] Forward port of addons until 8903
authorThibault Delavallée <tde@openerp.com>
Thu, 21 Mar 2013 09:37:16 +0000 (10:37 +0100)
committerThibault Delavallée <tde@openerp.com>
Thu, 21 Mar 2013 09:37:16 +0000 (10:37 +0100)
bzr revid: tde@openerp.com-20130321093716-3nt7h2xunl8lusqh

1  2 
addons/account/account_invoice.py
addons/mail/mail_followers.py
addons/mail/mail_mail.py
addons/mail/mail_thread.py
addons/mail/static/src/js/mail.js
addons/mail/wizard/mail_compose_message.py
addons/mrp/mrp_view.xml
addons/point_of_sale/point_of_sale.py
addons/stock/stock.py
addons/stock/stock_view.xml

Simple merge
@@@ -180,25 -144,36 +183,30 @@@ class mail_notification(osv.Model)
          # TDE FIXME: commented, to be improved in a future branch
          # quote_context = self.pool.get('mail.message').message_quote_context(cr, uid, msg_id, context=context)
  
 -        mail_mail = self.pool.get('mail.mail')
          # add signature
          body_html = msg.body
 -        # if quote_context:
 -            # body_html = tools.append_content_to_html(body_html, quote_context, plaintext=False)
 -        signature = msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0].signature or ''
 -        if signature:
 -            body_html = tools.append_content_to_html(body_html, signature, plaintext=True, container_tag='div')
 -
 -        # email_from: partner-user alias or partner email or mail.message email_from
 -        if msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0].alias_domain and msg.author_id.user_ids[0].alias_name:
 -            email_from = '%s <%s@%s>' % (msg.author_id.name, msg.author_id.user_ids[0].alias_name, msg.author_id.user_ids[0].alias_domain)
 -        elif msg.author_id:
 -            email_from = '%s <%s>' % (msg.author_id.name, msg.author_id.email)
 -        else:
 -            email_from = msg.email_from
 +        user_id = msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0] and msg.author_id.user_ids[0].id or None
 +        signature_company = self.get_signature_footer(cr, uid, user_id, res_model=msg.model, res_id=msg.res_id, context=context)
 +        body_html = tools.append_content_to_html(body_html, signature_company, plaintext=False, container_tag='div')
  
+         references = False
+         if msg.parent_id:
+             references = msg.parent_id.message_id
          mail_values = {
              'mail_message_id': msg.id,
              'auto_delete': True,
              'body_html': body_html,
-             'recipient_ids': [(4, id) for id in notify_partner_ids]
 -            'email_from': email_from,
++            'recipient_ids': [(4, id) for id in notify_partner_ids],
+             'references': references,
          }
 +        if msg.email_from:
 +            mail_values['email_from'] = msg.email_from
 +        if msg.reply_to:
 +            mail_values['reply_to'] = msg.reply_to
 +        mail_mail = self.pool.get('mail.mail')
          email_notif_id = mail_mail.create(cr, uid, mail_values, context=context)
          try:
 -            return mail_mail.send(cr, uid, [email_notif_id], recipient_ids=notify_partner_ids, context=context)
 +            return mail_mail.send(cr, uid, [email_notif_id], context=context)
          except Exception:
              return False
@@@ -241,8 -226,9 +241,8 @@@ class mail_mail(osv.Model)
          """
          body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context)
          subject = self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context)
 -        reply_to = self.send_get_mail_reply_to(cr, uid, mail, partner=partner, context=context)
          body_alternative = tools.html2plaintext(body)
-         email_to = [partner.email] if partner else tools.email_split(mail.email_to)
+         email_to = ['%s <%s>' % (partner.name, partner.email)] if partner else tools.email_split(mail.email_to)
          return {
              'body': body,
              'body_alternative': body_alternative,
Simple merge
Simple merge
@@@ -131,11 -125,31 +132,34 @@@ class mail_compose_message(osv.Transien
          'body': lambda self, cr, uid, ctx={}: '',
          'subject': lambda self, cr, uid, ctx={}: False,
          'partner_ids': lambda self, cr, uid, ctx={}: [],
 +        'notify': lambda self, cr, uid, ctx={}: False,
 +        'post': lambda self, cr, uid, ctx={}: True,
 +        'same_thread': lambda self, cr, uid, ctx={}: True,
      }
  
+     def check_access_rule(self, cr, uid, ids, operation, context=None):
+         """ Access rules of mail.compose.message:
+             - create: if
+                 - model, no res_id, I create a message in mass mail mode
+             - then: fall back on mail.message acces rules
+         """
+         if isinstance(ids, (int, long)):
+             ids = [ids]
+         # Author condition (CREATE (mass_mail))
+         if operation == 'create' and uid != SUPERUSER_ID:
+             # read mail_compose_message.ids to have their values
+             message_values = {}
+             cr.execute('SELECT DISTINCT id, model, res_id FROM "%s" WHERE id = ANY (%%s) AND res_id = 0' % self._table, (ids,))
+             for id, rmod, rid in cr.fetchall():
+                 message_values[id] = {'model': rmod, 'res_id': rid}
+             # remove from the set to check the ids that mail_compose_message accepts
+             author_ids = [mid for mid, message in message_values.iteritems()
+                 if message.get('model') and not message.get('res_id')]
+             ids = list(set(ids) - set(author_ids))
+         return super(mail_compose_message, self).check_access_rule(cr, uid, ids, operation, context=context)
      def _notify(self, cr, uid, newid, context=None):
          """ Override specific notify method of mail.message, because we do
              not want that feature in the wizard. """
                      new_attachments = email_dict.pop('attachments', [])
                      post_values['attachments'] += new_attachments
                      post_values.update(email_dict)
 +                    # email_from: mass mailing only can specify another email_from
 +                    if email_dict.get('email_from'):
 +                        post_values['email_from'] = email_dict.pop('email_from')
 +                    # replies redirection: mass mailing only
 +                    if not wizard.same_thread:
 +                        post_values['reply_to'] = email_dict.pop('reply_to')
 +                # clean the context (hint: mass mailing sets some default values that
 +                # could be wrongly interpreted by mail_mail)
 +                context.pop('default_email_to', None)
 +                context.pop('default_partner_ids', None)
                  # post the message
 -                subtype = 'mail.mt_comment'
 -                if is_log:  # log a note: subtype is False
 -                    subtype = False
 -                elif mass_mail_mode:  # mass mail: is a log pushed to recipients, author not added
 -                    subtype = False
 -                    context = dict(context, mail_create_nosubscribe=True)  # add context key to avoid subscribing the author
 -                msg_id = active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **post_values)
 -                # mass_mailing: notify specific partners, because subtype was False, and no-one was notified
 -                if mass_mail_mode and post_values['partner_ids']:
 -                    self.pool.get('mail.notification')._notify(cr, uid, msg_id, post_values['partner_ids'], context=context)
 +                if mass_mail_mode and not wizard.post:
 +                    post_values['recipient_ids'] = [(4, id) for id in post_values.pop('partner_ids', [])]
 +                    self.pool.get('mail.mail').create(cr, uid, post_values, context=context)
 +                else:
 +                    subtype = 'mail.mt_comment'
-                     if is_log or (mass_mail_mode and not wizard.notify):
++                    if is_log:  # log a note: subtype is False
++                        subtype = False
++                    elif mass_mail_mode:  # mass mail: is a log pushed to recipients, author not added
 +                        subtype = False
++                        context = dict(context, mail_create_nosubscribe=True)  # add context key to avoid subscribing the author
 +                    msg_id = active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **post_values)
 +                    # mass_mailing, post without notify: notify specific partners
 +                    if mass_mail_mode and not wizard.notify and post_values['partner_ids']:
 +                        self.pool.get('mail.notification')._notify(cr, uid, msg_id, post_values['partner_ids'], context=context)
  
          return {'type': 'ir.actions.act_window_close'}
  
Simple merge
Simple merge
Simple merge
Simple merge