[FIX] mass_mailing: allow to add a user/email to a specific mailing list and not...
authorJeremy Kersten <jke@odoo.com>
Fri, 1 Aug 2014 09:25:41 +0000 (11:25 +0200)
committerJeremy Kersten <jke@odoo.com>
Fri, 1 Aug 2014 09:25:41 +0000 (11:25 +0200)
addons/mass_mailing/controllers/main.py
addons/mass_mailing/models/mass_mailing.py

index 935b51c..666a7bb 100644 (file)
@@ -68,7 +68,7 @@ class MassMailController(http.Controller):
 
         contact_ids = Contacts.search(cr, SUPERUSER_ID, [('list_id', '=', int(list_id)), ('email', '=', email)], context=context)
         if not contact_ids:
-            Contacts.name_create(cr, SUPERUSER_ID, email, context=context)
+            Contacts.add_to_list(cr, SUPERUSER_ID, email, int(list_id), context=context)
         # add email to session
         request.session['mass_mailing_email'] = email
         return True
index eafab52..c2d7588 100644 (file)
@@ -52,15 +52,24 @@ class MassMailingContact(osv.Model):
         'list_id': _get_latest_list
     }
 
-    def name_create(self, cr, uid, name, context=None):
+    def get_name_email(self, name, context):
         name, email = self.pool['res.partner']._parse_partner_name(name, context=context)
         if name and not email:
             email = name
         if email and not name:
             name = email
+        return name, email
+
+    def name_create(self, cr, uid, name, context=None):
+        name, email = self.get_name_email(name, context=context)
         rec_id = self.create(cr, uid, {'name': name, 'email': email}, context=context)
         return self.name_get(cr, uid, [rec_id], context)[0]
 
+    def add_to_list(self, cr, uid, name, list_id, context=None):
+        name, email = self.get_name_email(name, context=context)
+        rec_id = self.create(cr, uid, {'name': name, 'email': email, 'list_id': list_id}, context=context)
+        return self.name_get(cr, uid, [rec_id], context)[0]
+
     def message_get_default_recipients(self, cr, uid, ids, context=None):
         res = {}
         for record in self.browse(cr, uid, ids, context=context):