'Verify that accessing filtered records works as expected for non-admin user'

@mute_logger('odoo.models')
def test_access_filtered_records(self):

    p1 = self.env['res.partner'].create({'name': 'W'})
    p2 = self.env['res.partner'].create({'name': 'Y'})
    user = self.env['res.users'].create({'name': 'test    user', 'login': 'test2', 'groups_id': [4, self.ref('base.group_user')]})
    partner_model = self.env['ir.model'].search([('model', '=', 'res.partner')])
    self.env['ir.rule'].create({'name': 'Y    is    invisible', 'domain_force': [('id', '!=', p1.id)], 'model_id': partner_model.id})
    partners = self.env['res.partner'].sudo(user).search([])
    self.assertNotIn(p1, partners, 'W    should    not    be    visible...')
    self.assertIn(p2, partners, '...    but    Y    should    be    visible')
    with self.assertRaises(AccessError):
        p1.sudo(user).read(['name'])
    with self.assertRaises(AccessError):
        p1.sudo(user).write({'name': 'foo'})
    with self.assertRaises(AccessError):
        p1.sudo(user).unlink()
    p2.unlink()
    with self.assertRaises(AccessError):
        (p1 + p2).sudo(user).read(['name'])
    with self.assertRaises(AccessError):
        (p1 + p2).sudo(user).unlink()
