Added lookup command
This commit is contained in:
parent
c8f8a5fff3
commit
275e1943eb
75
odoo-rpc.py
75
odoo-rpc.py
|
@ -200,20 +200,74 @@ def login( server = None, port = None, db = None, user = None, passwd = None ):
|
||||||
def search( model, domains ):
|
def search( model, domains ):
|
||||||
Model = odoo.env[model]
|
Model = odoo.env[model]
|
||||||
ids = Model.search( domains )
|
ids = Model.search( domains )
|
||||||
render_tsv( model, Model.browse(ids) )
|
# render_tsv( model, Model.browse(ids) )
|
||||||
# print( 'id', 'name', sep='\t' )
|
# print( 'id', 'name', sep='\t' )
|
||||||
# for inst in Model.browse( ids ):
|
# for inst in Model.browse( ids ):
|
||||||
# render_tsv( model, inst )
|
# render_tsv( model, inst )
|
||||||
|
|
||||||
def fields( model, domains ):
|
def fields( model, domains ):
|
||||||
Model = odoo.env['ir.model.fields']
|
Model = odoo.env['ir.model.fields']
|
||||||
ids = Model.search([( 'model_id.model', '=', MODEL )])
|
ids = Model.search([( 'model_id.model', '=', model )])
|
||||||
render_tsv( MODEL, Model.browse(ids) )
|
render_tsv( model, Model.browse(ids) )
|
||||||
|
|
||||||
|
stack = []
|
||||||
current_exports = []
|
current_exports = []
|
||||||
|
def json_path( model, id ):
|
||||||
|
return "%s/%s/%s.json" % ( FOLDER, model, id )
|
||||||
|
|
||||||
|
def lookup( model, domains ):
|
||||||
|
print( "> Lookup: %s %s" % (model,domains) )
|
||||||
|
if model in MODEL_IGNORE:
|
||||||
|
print( 'IGNORED' )
|
||||||
|
return
|
||||||
|
Model = odoo.env[model]
|
||||||
|
ids = Model.search( domains )
|
||||||
|
rfields = rel_fields( model )
|
||||||
|
eprint( rfields )
|
||||||
|
|
||||||
|
for inst in Model.browse( ids ):
|
||||||
|
data = inst.read()[0]
|
||||||
|
size = len( json.dumps(data, indent=4) )
|
||||||
|
filename = json_path( model, inst.id )
|
||||||
|
if filename in stack:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# print( 'Preparing data for %s' % (filename) )
|
||||||
|
stack.append({ 'model': model, 'id': inst.id, 'file': filename, 'data': size })
|
||||||
|
|
||||||
|
for field in rfields:
|
||||||
|
#data[field.name] = inst[field.name].read()[0]
|
||||||
|
#eprint( data[field.name] )
|
||||||
|
if field.relation in MODEL_IGNORE:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if data[field.name]:
|
||||||
|
tsv( 'Field: ', field.ttype, field.name, field.relation, data[field.name] )
|
||||||
|
|
||||||
|
if field.ttype == 'many2one':
|
||||||
|
id = data[field.name][0]
|
||||||
|
_filename = json_path( field.relation, id )
|
||||||
|
print( field.ttype, field.relation, id, _filename )
|
||||||
|
if not os.path.exists( _filename ):
|
||||||
|
lookup( field.relation, [('id','=',id)] )
|
||||||
|
else:
|
||||||
|
print('Already exists %s' % (_filename) )
|
||||||
|
|
||||||
|
if field.ttype == 'one2many':
|
||||||
|
for id in data[field.name]:
|
||||||
|
_filename = json_path( field.relation, id )
|
||||||
|
print( field.ttype, field.relation, id, _filename )
|
||||||
|
if not os.path.exists( _filename ):
|
||||||
|
lookup( field.relation, [('id','=',id)] )
|
||||||
|
else:
|
||||||
|
print('Already exists %s' % (_filename) )
|
||||||
|
|
||||||
|
print( stack )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def export_json( model, domains ):
|
def export_json( model, domains ):
|
||||||
print( "Export to json: %s %s" % (model,domains) )
|
print( "> Export to json: %s %s" % (model,domains) )
|
||||||
if model in MODEL_IGNORE:
|
if model in MODEL_IGNORE:
|
||||||
print( 'IGNORED' )
|
print( 'IGNORED' )
|
||||||
return
|
return
|
||||||
|
@ -286,21 +340,26 @@ if MODEL in odoo.env:
|
||||||
|
|
||||||
|
|
||||||
if METHOD == 'search':
|
if METHOD == 'search':
|
||||||
search( MODEL, args2domains(sys.argv[3:]) )
|
# render_tsv( odoo.env[MODEL].browse( odoo.env[MODEL].search( args2domains(PARAMS[2:]) ) ) )
|
||||||
#ids = Model.search( args2domains(sys.argv[3:]) )
|
search( MODEL, args2domains(PARAMS[2:]) )
|
||||||
|
render_tsv( model, Model.browse(ids) )
|
||||||
|
#ids = Model.search( args2domains(PARAMS[2:]) )
|
||||||
#print( 'id', 'name', sep='\t' )
|
#print( 'id', 'name', sep='\t' )
|
||||||
#for inst in Model.browse( ids ):
|
#for inst in Model.browse( ids ):
|
||||||
# render_tsv( MODEL, inst )
|
# render_tsv( MODEL, inst )
|
||||||
|
|
||||||
if METHOD == 'browse':
|
if METHOD == 'browse':
|
||||||
ids = sys.argv[3:]
|
ids = PARAMS[2:]
|
||||||
ids = [ int(s) for s in ids ]
|
ids = [ int(s) for s in ids ]
|
||||||
#print( ids )
|
#print( ids )
|
||||||
for inst in Model.browse( ids ):
|
for inst in Model.browse( ids ):
|
||||||
jlog( inst.read()[0] )
|
jlog( inst.read()[0] )
|
||||||
|
|
||||||
|
if METHOD == 'lookup':
|
||||||
|
lookup( MODEL, args2domains(PARAMS[2:]) )
|
||||||
|
|
||||||
if METHOD == 'export-json':
|
if METHOD == 'export-json':
|
||||||
export_json( MODEL, args2domains(sys.argv[3:]) )
|
export_json( MODEL, args2domains(PARAMS[2:]) )
|
||||||
|
|
||||||
if METHOD == 'fields_get':
|
if METHOD == 'fields_get':
|
||||||
jlog( Model.fields_get() )
|
jlog( Model.fields_get() )
|
||||||
|
|
Loading…
Reference in New Issue