mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[IMP] Model emulator: better support method calls
Since we have the model fields loaded up, we can just check into that and assume anything that's not a field is a method. That avoids having to go through `_call`, making things way less awkward.
This commit is contained in:
parent
c036c7a28f
commit
d32ca9a1b3
11
conftest.py
11
conftest.py
@ -1120,17 +1120,18 @@ class Model:
|
|||||||
def __getattr__(self, fieldname):
|
def __getattr__(self, fieldname):
|
||||||
if fieldname in ['__dataclass_fields__', '__attrs_attrs__']:
|
if fieldname in ['__dataclass_fields__', '__attrs_attrs__']:
|
||||||
raise AttributeError('%r is invalid on %s' % (fieldname, self._model))
|
raise AttributeError('%r is invalid on %s' % (fieldname, self._model))
|
||||||
|
|
||||||
|
field_description = self._fields.get(fieldname)
|
||||||
|
if field_description is None:
|
||||||
|
return functools.partial(self._call, fieldname)
|
||||||
|
|
||||||
if not self._ids:
|
if not self._ids:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
assert len(self._ids) == 1
|
|
||||||
if fieldname == 'id':
|
if fieldname == 'id':
|
||||||
return self._ids[0]
|
return self._ids[0]
|
||||||
|
|
||||||
try:
|
val = self.read([fieldname])[0][fieldname]
|
||||||
val = self.read([fieldname])[0][fieldname]
|
|
||||||
except Exception:
|
|
||||||
raise AttributeError('%r is invalid on %s' % (fieldname, self._model))
|
|
||||||
field_description = self._fields[fieldname]
|
field_description = self._fields[fieldname]
|
||||||
if field_description['type'] in ('many2one', 'one2many', 'many2many'):
|
if field_description['type'] in ('many2one', 'one2many', 'many2many'):
|
||||||
val = val or []
|
val = val or []
|
||||||
|
@ -19,7 +19,7 @@ def test_partner_merge(env):
|
|||||||
'state': 'selection',
|
'state': 'selection',
|
||||||
'partner_ids': (p_src + p_dest).ids,
|
'partner_ids': (p_src + p_dest).ids,
|
||||||
'dst_partner_id': p_dest.id,
|
'dst_partner_id': p_dest.id,
|
||||||
})._call('action_merge')
|
}).action_merge()
|
||||||
assert not p_src.exists()
|
assert not p_src.exists()
|
||||||
assert p_dest.name == 'Partner P. Partnersson'
|
assert p_dest.name == 'Partner P. Partnersson'
|
||||||
assert p_dest.github_login == 'xxx'
|
assert p_dest.github_login == 'xxx'
|
||||||
|
Loading…
Reference in New Issue
Block a user