def test_existing(self): # all existing object ids all_obj_ids = self.object.search([], limit=False) # generate 10 unexisting ids unexistent_ids = list(range(max(all_obj_ids) + 1, max(all_obj_ids) + 40, 4)) self.assertEqual(len(unexistent_ids), 10) # test simple existense rlist = get_record_list(self.object, all_obj_ids[:10] + unexistent_ids) self.assertEqual(len(rlist), 20) elist = rlist.existing() self.assertEqual(len(elist), 10) self.assertItemsEqual(elist.ids, all_obj_ids[:10]) # test existense with repeated items rlist = get_record_list(self.object, all_obj_ids[:10] + unexistent_ids + all_obj_ids[:5]) self.assertEqual(len(rlist), 25) # with uniqify=True (defualt) elist = rlist.existing() self.assertEqual(len(elist), 10) self.assertItemsEqual(elist.ids, all_obj_ids[:10]) # with uniqify=False elist = rlist.existing(uniqify=False) self.assertEqual(len(elist), 15) self.assertItemsEqual(elist.ids, all_obj_ids[:10] + all_obj_ids[:5])
def __call__(self, *args, **kwargs): """ Performs name_search by specified 'name' (below under name 'name' i mean first of 'args') if name is list or tuple, then search_records will be called if name not passed or name is None, then kwargs will be used to build search domain and search_records will be called else name_search will run """ args = list(args) name = args.pop(0) if args else None # no arguments, only keyword arguments passsed, # so build domain based on keyword arguments if name is None: domain = [(k, '=', v) for k, v in kwargs.items()] return self.search_records(domain, *args) # normal domain passed, then just forward all arguments and # keyword arguments to *search_records* method if isinstance(name, (list, tuple)): return self.search_records(name, *args, **kwargs) # implement name_search capability context = kwargs.get('context', None) res = self.name_search(name, *args, **kwargs) ids = [i[0] for i in res] if len(ids) == 1: return self.read_records(ids[0], context=context) return get_record_list(self, ids=ids, context=context)