[IMP] models: "X in self" is now equivalent to any(X == rec for rec in self)
authorRaphael Collet <rco@openerp.com>
Fri, 22 Aug 2014 14:14:58 +0000 (16:14 +0200)
committerRaphael Collet <rco@openerp.com>
Thu, 4 Sep 2014 13:31:04 +0000 (15:31 +0200)
Fix modules with code like "record.id in other.stuff_ids".

addons/portal_sale/portal_sale.py
addons/product_email_template/models/invoice.py
openerp/models.py

index 31a2e1f..6bc44b5 100644 (file)
@@ -62,7 +62,7 @@ class sale_order(osv.Model):
         assert len(ids) == 1
         document = self.browse(cr, uid, ids[0], context=context)
         partner = document.partner_id
-        if partner.id not in document.message_follower_ids:
+        if partner not in document.message_follower_ids:
             self.message_subscribe(cr, uid, ids, [partner.id], context=context)
         return super(sale_order, self).action_button_confirm(cr, uid, ids, context=context)
 
@@ -121,7 +121,7 @@ class account_invoice(osv.Model):
         # fetch the partner's id and subscribe the partner to the invoice
         for invoice in self.browse(cr, uid, ids, context=context):
             partner = invoice.partner_id
-            if partner.id not in invoice.message_follower_ids:
+            if partner not in invoice.message_follower_ids:
                 self.message_subscribe(cr, uid, [invoice.id], [partner.id], context=context)
         return super(account_invoice, self).invoice_validate(cr, uid, ids, context=context)
 
@@ -150,10 +150,10 @@ class mail_mail(osv.osv):
             order = so_obj.browse(cr, uid, mail.res_id, context=context)
             partner = order.partner_id
             # Add the customer in the SO as follower
-            if partner.id not in order.message_follower_ids:
+            if partner not in order.message_follower_ids:
                 so_obj.message_subscribe(cr, uid, [mail.res_id], [partner.id], context=context)
             # Add all recipients of the email as followers
             for p in mail.partner_ids:
-                if p.id not in order.message_follower_ids:
+                if p not in order.message_follower_ids:
                     so_obj.message_subscribe(cr, uid, [mail.res_id], [p.id], context=context)
         return super(mail_mail, self)._postprocess_sent_message(cr, uid, mail=mail, context=context, mail_sent=mail_sent)
index d5876b5..60d7c4c 100644 (file)
@@ -13,7 +13,7 @@ class account_invoice(osv.Model):
             if invoice.type != 'out_invoice':
                 continue
             # subscribe the partner to the invoice
-            if invoice.partner_id.id not in invoice.message_follower_ids:
+            if invoice.partner_id not in invoice.message_follower_ids:
                 self.message_subscribe(cr, uid, [invoice.id], [invoice.partner_id.id], context=context)
             for line in invoice.invoice_line:
                 if line.product_id.email_template_id:
index 121186c..33bf9ba 100644 (file)
@@ -5308,14 +5308,17 @@ class BaseModel(object):
             yield self._browse(self.env, (id,))
 
     def __contains__(self, item):
-        """ Test whether `item` is a subset of `self` or a field name. """
-        if isinstance(item, BaseModel):
-            if self._name == item._name:
-                return set(item._ids) <= set(self._ids)
-            raise except_orm("ValueError", "Mixing apples and oranges: %s in %s" % (item, self))
-        if isinstance(item, basestring):
+        """ Test whether `item` (record or field name) is an element of `self`.
+            In the first case, the test is fully equivalent to::
+
+                any(item == record for record in self)
+        """
+        if isinstance(item, BaseModel) and self._name == item._name:
+            return len(item) == 1 and item.id in self._ids
+        elif isinstance(item, basestring):
             return item in self._fields
-        return item in self.ids
+        else:
+            raise except_orm("ValueError", "Mixing apples and oranges: %s in %s" % (item, self))
 
     def __add__(self, other):
         """ Return the concatenation of two recordsets. """