WIP lookup one model

This commit is contained in:
DiG 2022-01-16 16:03:50 +01:00
parent f2380522e4
commit 951e799c59
1 changed files with 14 additions and 10 deletions

View File

@ -222,27 +222,31 @@ current_exports = []
def lookup_model( muid ):
eprint( "> Lookup model: %s" % (muid) )
_stack = []
# _stack = []
_tree = {}
_ctree = _tree
# _ctree = _tree
model, id = muid.split( '/' )
id = int(id)
eprint( model, id )
_tree[muid] = {}
_ctree = _tree[muid]
# _ctree = _tree[muid]
if model in odoo.env:
rfields = rel_fields( model )
eprint( rfields )
inst = odoo.env[model].browse( id )
try:
inst = odoo.env[model].browse( id )
except:
_tree[muid]['error'] = 'Instance %s not found' % (muid)
return [ _tree ]
# data = inst.read()[0]
# size = len( json.dumps(data, indent=4) )
# filename = json_path( model, inst.id )
# _ctree['size'] = size
# _tree[muid]['size'] = size
for field in rfields:
# if data[field.name]:
# _ctree[field.name] = {}
# _tree[muid][field.name] = {}
_value = getattr( inst, field.name )
print( field.name )
print( _value )
@ -251,10 +255,10 @@ def lookup_model( muid ):
if field.ttype == 'many2one':
id = _value.id
# _stack.append( Muid(field.relation, id) )
_ctree[field.name] = [ Muid(field.relation, id) ]
_tree[muid][field.name] = [ Muid(field.relation, id) ]
if field.ttype == 'one2many':
_ctree[field.name] = [ Muid(field.relation, id) for id in _value.ids ]
_tree[muid][field.name] = [ Muid(field.relation, id) for id in _value.ids ]
# for id in _value.ids:
# _stack.append( Muid(field.relation, id) )
@ -262,9 +266,9 @@ def lookup_model( muid ):
# if field.ttype == 'reference':
else:
_ctree['error'] = 'Model do not exists'
_tree[muid]['error'] = 'Model do not exists'
return _tree
return [ _tree ]
def lookup( model, domains ):
eprint( "> Lookup: %s %s" % (model,domains) )