From 430bdb744ebde08e4568cce9d0329901819c4025 Mon Sep 17 00:00:00 2001 From: Laetitia Gangloff Date: Tue, 1 Sep 2015 17:51:44 +0200 Subject: [PATCH 1/2] export_scenario : remove some unused keys --- scripts/export_scenario.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/export_scenario.py b/scripts/export_scenario.py index c8ff79c9f0a..67c361b9361 100755 --- a/scripts/export_scenario.py +++ b/scripts/export_scenario.py @@ -104,6 +104,13 @@ 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: @@ -151,6 +158,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()) @@ -176,6 +185,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()) From b5207227ab540905949c00adc806a61daf34ba66 Mon Sep 17 00:00:00 2001 From: Laetitia Gangloff Date: Tue, 1 Sep 2015 18:00:17 +0200 Subject: [PATCH 2/2] improve import/export of group_ids and user_ids --- scripts/export_scenario.py | 12 ++++++++++++ scripts/import_scenario.py | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/scripts/export_scenario.py b/scripts/export_scenario.py index 67c361b9361..bc2401dccc3 100755 --- a/scripts/export_scenario.py +++ b/scripts/export_scenario.py @@ -97,6 +97,8 @@ 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: @@ -144,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 diff --git a/scripts/import_scenario.py b/scripts/import_scenario.py index 7dd2a36b2cb..80961f1aa60 100755 --- a/scripts/import_scenario.py +++ b/scripts/import_scenario.py @@ -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') @@ -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: