'exists() -> records
Returns the subset of records in ``self`` that exist, and marks deleted
records as such in cache. It can be used as a test on records::
if record.exists():
By convention, new records are returned as existing.'

@api.multi
@api.returns('self')
def exists(self):

    (ids, new_ids) = ([], [])
    for i in self._ids:
        (ids if isinstance(i, (int, long)) else new_ids).append(i)
    if (not ids):
        return self
    query = ('SELECT    id    FROM    "%s"    WHERE    id    IN    %%s' % self._table)
    self._cr.execute(query, [tuple(ids)])
    ids = [r[0] for r in self._cr.fetchall()]
    existing = self.browse((ids + new_ids))
    if (len(existing) < len(self)):
        exc = MissingError(_('Record    does    not    exist    or    has    been    deleted.'))
        (self - existing)._cache.update(FailedValue(exc))
    return existing
