'Verifies that the operation given by ``operation`` is allowed for
the current user according to ir.rules.
:param operation: one of ``write``, ``unlink``
:raise UserError: * if current ir.rules do not permit this operation.
:return: None if the operation is allowed'

@api.multi
def check_access_rule(self, operation):

    if (self._uid == SUPERUSER_ID):
        return
    if self.is_transient():
        query = ('SELECT    DISTINCT    create_uid    FROM    %s    WHERE    id    IN    %%s' % self._table)
        self._cr.execute(query, (tuple(self.ids),))
        uids = [x[0] for x in self._cr.fetchall()]
        if ((len(uids) != 1) or (uids[0] != self._uid)):
            raise AccessError((_('For    this    kind    of    document,    you    may    only    access    records    you    created    yourself.\n\n(Document    type:    %s)') % (self._description,)))
    else:
        (where_clause, where_params, tables) = self.env['ir.rule'].domain_get(self._name, operation)
        if where_clause:
            query = ('SELECT    %s.id    FROM    %s    WHERE    %s.id    IN    %%s    AND    ' % (self._table, ','.join(tables), self._table))
            query = (query + '    AND    '.join(where_clause))
            for sub_ids in self._cr.split_for_in_conditions(self.ids):
                self._cr.execute(query, ([sub_ids] + where_params))
                returned_ids = [x[0] for x in self._cr.fetchall()]
                self.browse(sub_ids)._check_record_rules_result_count(returned_ids, operation)
