Skip to content

Commit

Permalink
Merge pull request OCA#2 from acsone/8.0-login_logout-lga
Browse files Browse the repository at this point in the history
mprove import/export of group_ids and user_ids
  • Loading branch information
lmignon committed Sep 1, 2015
2 parents 40aafaa + b520722 commit b909ebe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
23 changes: 23 additions & 0 deletions scripts/export_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,22 @@
scenario_obj = Object(cnx, 'scanner.scenario')
model_obj = Object(cnx, 'ir.model')
warehouse_obj = Object(cnx, 'stock.warehouse')
user_obj = Object(cnx, 'res.users')
group_obj = Object(cnx, 'res.groups')
scen_read = scenario_obj.read(
int(opts.scenario_id), [], {'active_test': False})
if not scen_read:
logger.error('Scenario ID %s not found' % opts.scenario_id)
sys.exit(1)
del scen_read['step_ids']
del scen_read['id']

field_to_remove = ['create_uid', 'create_date',
'write_uid', 'write_date',
'__last_update', 'display_name']
for field in field_to_remove:
del scen_read[field]

# create node and attributs
root = Element('scenario')
for field in scen_read:
Expand Down Expand Up @@ -137,6 +146,16 @@
for warehouse in warehouse_obj.read(scen_read[field], ['name']):
node = SubElement(root, 'warehouse_ids')
node.text = unicode(warehouse.get('name'))
elif field == 'group_ids':
root.remove(node)
for group in group_obj.read(scen_read[field], ['full_name']):
node = SubElement(root, 'group_ids')
node.text = unicode(group.get('full_name'))
elif field == 'user_ids':
root.remove(node)
for user in user_obj.read(scen_read[field], ['login']):
node = SubElement(root, 'user_ids')
node.text = unicode(user.get('login'))
else:
node.text = unicode(scen_read[field])
# add step
Expand All @@ -151,6 +170,8 @@
del step['out_transition_ids']
del step['id']
del step['scenario_id']
for field in field_to_remove:
del step[field]
# get res_id
if not step['reference_res_id']:
step['reference_res_id'] = unicode(uuid.uuid1())
Expand All @@ -176,6 +197,8 @@
transition = transition_obj.read(transition_id, [])
del transition['id']
del transition['scenario_id']
for field in field_to_remove:
del transition[field]
# get res id
if not transition['reference_res_id']:
transition['reference_res_id'] = unicode(uuid.uuid1())
Expand Down
16 changes: 16 additions & 0 deletions scripts/import_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
model_obj = Object(cnx, 'ir.model')
company_obj = Object(cnx, 'res.company')
warehouse_obj = Object(cnx, 'stock.warehouse')
user_obj = Object(cnx, 'res.users')
group_obj = Object(cnx, 'res.groups')
step_obj = Object(cnx, 'scanner.scenario.step')
trans_obj = Object(cnx, 'scanner.scenario.transition')
xml_file = open('%s/scenario.xml' % directory, 'r')
Expand Down Expand Up @@ -138,6 +140,20 @@
0, None, None, {'active_test': False})
if warehouse_ids:
scen_vals['warehouse_ids'].append((4, warehouse_ids[0]))
elif node.tag == 'group_ids':
if 'group_ids' not in scen_vals:
scen_vals['group_ids'] = []
group_ids = group_obj.search(
[('full_name', '=', node.text)])
if group_ids:
scen_vals['group_ids'].append((4, group_ids[0]))
elif node.tag == 'user_ids':
if 'user_ids' not in scen_vals:
scen_vals['user_ids'] = []
user_ids = user_obj.search(
[('login', '=', node.text)])
if user_ids:
scen_vals['user_ids'].append((4, user_ids[0]))
elif node.tag in ('active', 'shared_custom'):
scen_vals[node.tag] = eval(node.text) or False
else:
Expand Down

0 comments on commit b909ebe

Please sign in to comment.