В классе Odoo BaseModel
реализован __getitem__
1 , который позволяет использовать "именованные индексы": recordset['field_name']
Из Odoo 12.0 odoo.models.BaseModel:
def __getitem__(self, key):
""" If ``key`` is an integer or a slice, return the corresponding record
selection as an instance (attached to ``self.env``).
Otherwise read the field ``key`` of the first record in ``self``.
Examples::
inst = model.search(dom) # inst is a recordset
r4 = inst[3] # fourth record in inst
rs = inst[10:20] # subset of inst
nm = rs['name'] # name of first record in inst
"""
if isinstance(key, pycompat.string_types):
# important: one must call the field's getter
return self._fields[key].__get__(self, type(self))
elif isinstance(key, slice):
return self._browse(self._ids[key], self.env)
else:
return self._browse((self._ids[key],), self.env)
Таким образом, на наборах записей будет прочитан атрибут первой записи.Попробуйте использовать его для синглетонов, если это возможно.
1 для получения дополнительной информации об универсальных типах нажмите здесь