'Check the prefetching model.'

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

    partners = self.env['res.partner'].search([], limit=models.PREFETCH_MAX)
    self.assertTrue(partners)
    def same_prefetch(a, b):
        self.assertIs(a._prefetch, b._prefetch)
    def diff_prefetch(a, b):
        self.assertIsNot(a._prefetch, b._prefetch)
    diff_prefetch(partners, partners.browse())
    diff_prefetch(partners, partners.browse(partners.ids))
    diff_prefetch(partners, partners[0])
    diff_prefetch(partners, partners[:10])
    same_prefetch(partners, partners.sudo(self.env.ref('base.user_demo')))
    same_prefetch(partners, partners.with_context(active_test=False))
    same_prefetch(partners, partners[:10].with_prefetch(partners._prefetch))
    self.assertEqual(type(partners).country_id.type, 'many2one')
    self.assertEqual(type(partners).bank_ids.type, 'one2many')
    self.assertEqual(type(partners).category_id.type, 'many2many')
    vals0 = {'name': 'Empty    relational    fields', 'country_id': False, 'bank_ids': [], 'category_id': []}
    vals1 = {'name': 'Non-empty    relational    fields', 'country_id': self.ref('base.be'), 'bank_ids': [(0, 0, {'acc_number': 'FOO42'})], 'category_id': [(4, self.ref('base.res_partner_category_0'))]}
    partners = (partners.create(vals0) + partners.create(vals1))
    for partner in partners:
        same_prefetch(partners, partner)
        same_prefetch(partners, partner.country_id)
        same_prefetch(partners, partner.bank_ids)
        same_prefetch(partners, partner.category_id)
    empty = partners.browse()
    same_prefetch(empty, empty.country_id)
    same_prefetch(empty, empty.bank_ids)
    same_prefetch(empty, empty.category_id)
