[MERGE] forward port of branch saas-1 up to revid 8745 chs@openerp.com-20130613181503...
authorChristophe Simonis <chs@openerp.com>
Fri, 14 Jun 2013 09:19:24 +0000 (11:19 +0200)
committerChristophe Simonis <chs@openerp.com>
Fri, 14 Jun 2013 09:19:24 +0000 (11:19 +0200)
bzr revid: chs@openerp.com-20130614091924-z5ta02kwhmwcrgox

13 files changed:
1  2 
addons/account/account_invoice.py
addons/email_template/email_template.py
addons/mail/mail_followers.py
addons/mail/mail_mail.py
addons/mail/mail_mail_view.xml
addons/mail/mail_message.py
addons/mail/mail_message_view.xml
addons/mail/mail_thread.py
addons/mail/static/src/js/mail.js
addons/mail/static/src/xml/mail.xml
addons/mail/tests/test_mail_gateway.py
addons/point_of_sale/static/src/js/widgets.js
addons/report_webkit/webkit_report.py

Simple merge
Simple merge
@@@ -90,41 -86,37 +86,42 @@@ class mail_mail(osv.Model)
          """ Return a specific reply_to: alias of the document through message_get_reply_to
              or take the email_from
          """
 +        # if value specified: directly return it
          if values.get('reply_to'):
              return values.get('reply_to')
+         format_name = True  # whether to use a 'Followers of Pigs <pigs@openerp.com' format
 -        email_reply_to = False
 +
-         mailgateway = True  # tells whether the answer will go through the mailgateway, leading to the formatting of reply_to <Followers of ...>
 +        ir_config_parameter = self.pool.get("ir.config_parameter")
 +        catchall_domain = ir_config_parameter.get_param(cr, uid, "mail.catchall.domain", context=context)
  
-         # model, res_id, email_from, reply_to: comes from values OR related message
-         message = None
+         # model, res_id, email_from: comes from values OR related message
+         model, res_id, email_from = values.get('model'), values.get('res_id'), values.get('email_from')
          if values.get('mail_message_id'):
              message = self.pool.get('mail.message').browse(cr, uid, values.get('mail_message_id'), context=context)
-         model = values.get('model', message and message.model or False)
-         res_id = values.get('res_id', message and message.res_id or False)
-         email_from = values.get('email_from', message and message.email_from or False)
-         email_reply_to = message and message.reply_to or False
+             if message.reply_to:
+                 email_reply_to = message.reply_to
+                 format_name = False
+             if not model:
+                 model = message.model
+             if not res_id:
+                 res_id = message.res_id
+             if not email_from:
+                 email_from = message.email_from
  
          # if model and res_id: try to use ``message_get_reply_to`` that returns the document alias
          if not email_reply_to and model and res_id and hasattr(self.pool[model], 'message_get_reply_to'):
              email_reply_to = self.pool[model].message_get_reply_to(cr, uid, [res_id], context=context)[0]
 -        # no alias reply_to -> reply_to will be the email_from
 -        if not email_reply_to and email_from:
 -            email_reply_to = email_from
 +        # no alias reply_to -> catchall alias
 +        if not email_reply_to:
 +            catchall_alias = ir_config_parameter.get_param(cr, uid, "mail.catchall.alias", context=context)
 +            if catchall_domain and catchall_alias:
 +                email_reply_to = '%s@%s' % (catchall_alias, catchall_domain)
-         # no alias reply_to -> reply_to will be the email_from, only the email part
-         if not email_reply_to and email_from:
-             emails = tools.email_split(email_from)
-             if emails:
-                 email_reply_to = emails[0]
-                 if emails[0].split('@')[1] != catchall_domain:
-                     mailgateway = False
  
          # format 'Document name <email_address>'
-         if email_reply_to and model and res_id and mailgateway:
+         if email_reply_to and model and res_id and format_name:
+             emails = tools.email_split(email_reply_to)
+             if emails:
+                 email_reply_to = emails[0]
              document_name = self.pool[model].name_get(cr, SUPERUSER_ID, [res_id], context=context)[0]
              if document_name:
                  # sanitize document name
Simple merge
Simple merge
Simple merge
Simple merge
@@@ -264,9 -257,9 +264,10 @@@ openerp.mail = function (session) 
  
          /* Convert date, timerelative and avatar in displayable data. */
          format_data: function () {
 +
              //formating and add some fields for render
              this.date = this.date ? session.web.str_to_datetime(this.date) : false;
+             this.display_date = this.date.toString('ddd MMM dd yyyy HH:mm');
              if (this.date && new Date().getTime()-this.date.getTime() < 7*24*60*60*1000) {
                  this.timerelative = $.timeago(this.date);
              }
Simple merge
@@@ -126,113 -126,100 +126,209 @@@ class TestMailgateway(TestMailBase)
  
      def test_05_mail_message_mail_mail(self):
          """ Tests designed for testing email values based on mail.message, aliases, ... """
+         cr, uid, user_raoul_id = self.cr, self.uid, self.user_raoul_id
+         # Data: update + generic variables
+         reply_to1 = '_reply_to1@example.com'
+         reply_to2 = '_reply_to2@example.com'
+         email_from1 = 'from@example.com'
+         alias_domain = 'schlouby.fr'
+         raoul_from = 'Raoul Grosbedon <raoul@raoul.fr>'
+         raoul_from_alias = 'Raoul Grosbedon <raoul@schlouby.fr>'
+         raoul_reply = '"Followers of Pigs" <raoul@raoul.fr>'
+         raoul_reply_alias = '"Followers of Pigs" <group+pigs@schlouby.fr>'
+         # Data: remove alias_domain to see emails with alias
+         param_ids = self.registry('ir.config_parameter').search(cr, uid, [('key', '=', 'mail.catchall.domain')])
+         self.registry('ir.config_parameter').unlink(cr, uid, param_ids)
+         # Do: free message; specified values > default values
+         msg_id = self.mail_message.create(cr, user_raoul_id, {'reply_to': reply_to1, 'email_from': email_from1})
+         msg = self.mail_message.browse(cr, user_raoul_id, msg_id)
+         # Test: message content
+         self.assertIn('reply_to', msg.message_id,
+                         'mail_message: message_id should be specific to a mail_message with a given reply_to')
+         self.assertEqual(msg.reply_to, reply_to1,
+                         'mail_message: incorrect reply_to: should come from values')
+         self.assertEqual(msg.email_from, email_from1,
+                         'mail_message: incorrect email_from: should come from values')
+         # Do: create a mail_mail with the previous mail_message
+         mail_id = self.mail_mail.create(cr, user_raoul_id, {'mail_message_id': msg_id, 'state': 'cancel'})
+         mail = self.mail_mail.browse(cr, user_raoul_id, mail_id)
+         # Test: mail_mail content
+         self.assertEqual(mail.reply_to, reply_to1,
+                         'mail_mail: incorrect reply_to: should come from mail.message')
+         self.assertEqual(mail.email_from, email_from1,
+                         'mail_mail: incorrect email_from: should come from mail.message')
+         # Do: create a mail_mail with the previous mail_message + specified reply_to
+         mail_id = self.mail_mail.create(cr, user_raoul_id, {'mail_message_id': msg_id, 'state': 'cancel', 'reply_to': reply_to2})
+         mail = self.mail_mail.browse(cr, user_raoul_id, mail_id)
+         # Test: mail_mail content
+         self.assertEqual(mail.reply_to, reply_to2,
+                         'mail_mail: incorrect reply_to: should come from values')
+         self.assertEqual(mail.email_from, email_from1,
+                         'mail_mail: incorrect email_from: should come from mail.message')
+         # Do: mail_message attached to a document
+         msg_id = self.mail_message.create(cr, user_raoul_id, {'model': 'mail.group', 'res_id': self.group_pigs_id})
+         msg = self.mail_message.browse(cr, user_raoul_id, msg_id)
+         # Test: message content
+         self.assertIn('mail.group', msg.message_id,
+                         'mail_message: message_id should contain model')
+         self.assertIn('%s' % self.group_pigs_id, msg.message_id,
+                         'mail_message: message_id should contain res_id')
+         self.assertFalse(msg.reply_to,
+                         'mail_message: incorrect reply_to: should not be generated if not specified')
+         self.assertEqual(msg.email_from, raoul_from,
+                         'mail_message: incorrect email_from: should be Raoul')
+         # Do: create a mail_mail based on the previous mail_message
+         mail_id = self.mail_mail.create(cr, user_raoul_id, {'mail_message_id': msg_id, 'state': 'cancel'})
+         mail = self.mail_mail.browse(cr, user_raoul_id, mail_id)
+         # Test: mail_mail content
+         self.assertEqual(mail.reply_to, raoul_reply,
+                         'mail_mail: incorrect reply_to: should be Raoul')
+         # Data: set catchall domain
+         self.registry('ir.config_parameter').set_param(cr, uid, 'mail.catchall.domain', alias_domain)
+         # Update message
+         self.mail_message.write(cr, user_raoul_id, [msg_id], {'email_from': False, 'reply_to': False})
+         msg.refresh()
+         # Do: create a mail_mail based on the previous mail_message
+         mail_id = self.mail_mail.create(cr, user_raoul_id, {'mail_message_id': msg_id, 'state': 'cancel'})
+         mail = self.mail_mail.browse(cr, user_raoul_id, mail_id)
+         # Test: mail_mail content
+         self.assertEqual(mail.reply_to, raoul_reply_alias,
+                         'mail_mail: incorrect reply_to: should be Pigs alias')
+         # Update message: test alias on email_from
+         msg_id = self.mail_message.create(cr, user_raoul_id, {})
+         msg = self.mail_message.browse(cr, user_raoul_id, msg_id)
+         # Do: create a mail_mail based on the previous mail_message
+         mail_id = self.mail_mail.create(cr, user_raoul_id, {'mail_message_id': msg_id, 'state': 'cancel'})
+         mail = self.mail_mail.browse(cr, user_raoul_id, mail_id)
+         # Test: mail_mail content
+         self.assertEqual(mail.reply_to, raoul_from_alias,
+                         'mail_mail: incorrect reply_to: should be message email_from using Raoul alias')
+         # Update message
+         self.mail_message.write(cr, user_raoul_id, [msg_id], {'res_id': False, 'email_from': 'someone@schlouby.fr', 'reply_to': False})
+         msg.refresh()
+         # Do: create a mail_mail based on the previous mail_message
+         mail_id = self.mail_mail.create(cr, user_raoul_id, {'mail_message_id': msg_id, 'state': 'cancel'})
+         mail = self.mail_mail.browse(cr, user_raoul_id, mail_id)
+         # Test: mail_mail content
+         self.assertEqual(mail.reply_to, msg.email_from,
+                         'mail_mail: incorrect reply_to: should be message email_from')
++    def test_05_mail_message_mail_mail(self):
++        """ Tests designed for testing email values based on mail.message, aliases, ... """
 +        cr, uid = self.cr, self.uid
 +
 +        # Data: clean catchall domain
 +        param_ids = self.registry('ir.config_parameter').search(cr, uid, [('key', '=', 'mail.catchall.domain')])
 +        self.registry('ir.config_parameter').unlink(cr, uid, param_ids)
 +
 +        # Do: create a mail_message with a reply_to, without message-id
 +        msg_id = self.mail_message.create(cr, uid, {'subject': 'Subject', 'body': 'Body', 'reply_to': 'custom@example.com'})
 +        msg = self.mail_message.browse(cr, uid, msg_id)
 +        # Test: message content
 +        self.assertIn('reply_to', msg.message_id,
 +                        'mail_message: message_id should be specific to a mail_message with a given reply_to')
 +        self.assertEqual('custom@example.com', msg.reply_to,
 +                        'mail_message: incorrect reply_to')
 +        # Do: create a mail_mail with the previous mail_message and specified reply_to
 +        mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'reply_to': 'other@example.com', 'state': 'cancel'})
 +        mail = self.mail_mail.browse(cr, uid, mail_id)
 +        # Test: mail_mail content
 +        self.assertEqual(mail.reply_to, 'other@example.com',
 +                        'mail_mail: reply_to should be equal to the one coming from creation values')
 +        # Do: create a mail_mail with the previous mail_message
 +        self.mail_message.write(cr, uid, [msg_id], {'reply_to': 'custom@example.com'})
 +        msg.refresh()
 +        mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'})
 +        mail = self.mail_mail.browse(cr, uid, mail_id)
 +        # Test: mail_mail content
 +        self.assertEqual(mail.reply_to, msg.reply_to,
 +                        'mail_mail: reply_to should be equal to the one coming from the mail_message')
 +
 +        # Do: create a mail_message without a reply_to
 +        msg_id = self.mail_message.create(cr, uid, {'subject': 'Subject', 'body': 'Body', 'model': 'mail.group', 'res_id': self.group_pigs_id, 'email_from': False})
 +        msg = self.mail_message.browse(cr, uid, msg_id)
 +        # Test: message content
 +        self.assertIn('mail.group', msg.message_id,
 +                        'mail_message: message_id should contain model')
 +        self.assertIn('%s' % self.group_pigs_id, msg.message_id,
 +                        'mail_message: message_id should contain res_id')
 +        self.assertFalse(msg.reply_to,
 +                        'mail_message: should not generate a reply_to address when not specified')
 +        # Do: create a mail_mail based on the previous mail_message
 +        mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'})
 +        mail = self.mail_mail.browse(cr, uid, mail_id)
 +        # Test: mail_mail content
 +        self.assertFalse(mail.reply_to,
 +                        'mail_mail: reply_to should not have been guessed')
 +        # Update message
 +        self.mail_message.write(cr, uid, [msg_id], {'email_from': 'someone@example.com'})
 +        msg.refresh()
 +        # Do: create a mail_mail based on the previous mail_message
 +        mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'})
 +        mail = self.mail_mail.browse(cr, uid, mail_id)
 +        # Test: mail_mail content
 +        self.assertEqual(mail.reply_to, msg.email_from,
 +                        'mail_mail: reply_to should be equal to mail_message.email_from when having no document or default alias')
 +
 +        # Data: set catchall domain
 +        self.registry('ir.config_parameter').set_param(cr, uid, 'mail.catchall.domain', 'schlouby.fr')
 +        self.registry('ir.config_parameter').unlink(cr, uid, self.registry('ir.config_parameter').search(cr, uid, [('key', '=', 'mail.catchall.alias')]))
 +
 +        # Update message
 +        self.mail_message.write(cr, uid, [msg_id], {'email_from': False, 'reply_to': False})
 +        msg.refresh()
 +        # Do: create a mail_mail based on the previous mail_message
 +        mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'})
 +        mail = self.mail_mail.browse(cr, uid, mail_id)
 +        # Test: mail_mail content
 +        self.assertEqual(mail.reply_to, '"Followers of Pigs" <group+pigs@schlouby.fr>',
 +                        'mail_mail: reply_to should equal the mail.group alias')
 +
 +        # Update message
 +        self.mail_message.write(cr, uid, [msg_id], {'res_id': False, 'email_from': 'someone@schlouby.fr', 'reply_to': False})
 +        msg.refresh()
 +        # Do: create a mail_mail based on the previous mail_message
 +        mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'})
 +        mail = self.mail_mail.browse(cr, uid, mail_id)
 +        # Test: mail_mail content
 +        self.assertEqual(mail.reply_to, msg.email_from,
 +                        'mail_mail: reply_to should equal the mail_message email_from')
 +
 +        # Data: set catchall alias
 +        self.registry('ir.config_parameter').set_param(self.cr, self.uid, 'mail.catchall.alias', 'gateway')
 +
 +        # Update message
 +        self.mail_message.write(cr, uid, [msg_id], {'email_from': False, 'reply_to': False})
 +        msg.refresh()
 +        # Do: create a mail_mail based on the previous mail_message
 +        mail_id = self.mail_mail.create(cr, uid, {'mail_message_id': msg_id, 'state': 'cancel'})
 +        mail = self.mail_mail.browse(cr, uid, mail_id)
 +        # Test: mail_mail content
 +        self.assertEqual(mail.reply_to, 'gateway@schlouby.fr',
 +                        'mail_mail: reply_to should equal the catchall email alias')
 +
 +        # Do: create a mail_mail
 +        mail_id = self.mail_mail.create(cr, uid, {'state': 'cancel'})
 +        mail = self.mail_mail.browse(cr, uid, mail_id)
 +        # Test: mail_mail content
 +        self.assertEqual(mail.reply_to, 'gateway@schlouby.fr',
 +                        'mail_mail: reply_to should equal the catchall email alias')
 +
 +        # Do: create a mail_mail
 +        mail_id = self.mail_mail.create(cr, uid, {'state': 'cancel', 'reply_to': 'someone@example.com'})
 +        mail = self.mail_mail.browse(cr, uid, mail_id)
 +        # Test: mail_mail content
 +        self.assertEqual(mail.reply_to, 'someone@example.com',
 +                        'mail_mail: reply_to should equal the rpely_to given to create')
 +
 +    @mute_logger('openerp.addons.mail.mail_thread', 'openerp.osv.orm')
      def test_10_message_process(self):
          """ Testing incoming emails processing. """
          cr, uid, user_raoul = self.cr, self.uid, self.user_raoul
Simple merge