[IMP] models: "X in self" is now equivalent to any(X == rec for rec in self)
Fix modules with code like "record.id in other.stuff_ids".
This commit is contained in:
parent
070f28dce6
commit
d6f375df61
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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. """
|
||||
|
|
Loading…
Reference in New Issue