def create_categories(cr, categories):
 p_id = None
 category = []
 while categories:
  category.append(categories[0])
  xml_id = ('module_category_' + '_'.join(map((lambda x: x.lower()), category)).replace('&', 'and').replace(' ', '_'))
  cr.execute('SELECT res_id FROM ir_model_data WHERE name=%s AND module=%s AND model=%s', (xml_id, 'base', 'ir.module.category'))
  c_id = cr.fetchone()
  if (not c_id):
   cr.execute('INSERT INTO ir_module_category                     (name, parent_id)                     VALUES (%s, %s) RETURNING id', (categories[0], p_id))
   c_id = cr.fetchone()[0]
   cr.execute('INSERT INTO ir_model_data (module, name, res_id, model)                        VALUES (%s, %s, %s, %s)', ('base', xml_id, c_id, 'ir.module.category'))
  else:
   c_id = c_id[0]
  p_id = c_id
  categories = categories[1:]
 return p_id

def create_categories ( cr , categories ) : p_id = None category = [ ] while categories : category . append ( categories [ 0 ] ) xml_id = ( 'module_category_' + '_' . join ( map ( ( lambda x : x . lower ( ) ) , category ) ) . replace ( '&' , 'and' ) . replace ( ' ' , '_' ) ) cr . execute ( 'SELECT res_id FROM ir_model_data WHERE name=%s AND module=%s AND model=%s' , ( xml_id , 'base' , 'ir.module.category' ) ) c_id = cr . fetchone ( ) if ( not c_id ) : cr . execute ( 'INSERT INTO ir_module_category                     (name, parent_id)                     VALUES (%s, %s) RETURNING id' , ( categories [ 0 ] , p_id ) ) c_id = cr . fetchone ( ) [ 0 ] cr . execute ( 'INSERT INTO ir_model_data (module, name, res_id, model)                        VALUES (%s, %s, %s, %s)' , ( 'base' , xml_id , c_id , 'ir.module.category' ) ) else : c_id = c_id [ 0 ] p_id = c_id categories = categories [ 1 : ] return p_id
create the ir_module_category entries for some categories .