def update_relatives(nid, ref_id, ref_model): relatives = [] for dummy, tr in transitions.items(): if tr['source'] == nid: relatives.append(tr['target']) if tr['target'] == nid: relatives.append(tr['source']) if not ref_id: nodes[nid]['res'] = False return nodes[nid]['res'] = resource = {'id': ref_id, 'model': ref_model} refobj = pool.get(ref_model).browse(cr, uid, ref_id, context=context) fields = pool.get(ref_model).fields_get(cr, uid, context=context) # check for directory_id from inherited from document module if nodes[nid].get('directory_id', False): resource['directory'] = self.pool.get( 'document.directory').get_resource_path( cr, uid, nodes[nid]['directory_id'], ref_model, ref_id) resource['name'] = refobj.name_get(context)[0][1] resource['perm'] = pool.get(ref_model).perm_read( cr, uid, [ref_id], context)[0] ref_expr_context = Env(refobj, current_user) try: if not nodes[nid]['gray']: nodes[nid]['active'] = eval(nodes[nid]['model_states'], ref_expr_context) except: pass for r in relatives: node = nodes[r] if 'res' not in node: for n, f in fields.items(): if node['model'] == ref_model: update_relatives(r, ref_id, ref_model) elif f.get('relation') == node['model']: rel = refobj[n] if rel and isinstance(rel, list): rel = rel[0] try: # XXX: rel has been reported as string (check it) _id = (rel or False) and rel.id _model = node['model'] update_relatives(r, _id, _model) except: pass
def update_relatives(nid, ref_id, ref_model): relatives = [] for dummy, tr in transitions.items(): if tr['source'] == nid: relatives.append(tr['target']) if tr['target'] == nid: relatives.append(tr['source']) if not ref_id: nodes[nid]['res'] = False return nodes[nid]['res'] = resource = {'id': ref_id, 'model': ref_model} refobj = pool.get(ref_model).browse(cr, uid, ref_id, context=context) fields = pool.get(ref_model).fields_get(cr, uid, context=context) # check for directory_id from inherited from document module if nodes[nid].get('directory_id', False): resource['directory'] = self.pool.get('document.directory').get_resource_path(cr, uid, nodes[nid]['directory_id'], ref_model, ref_id) resource['name'] = refobj.name_get(context)[0][1] resource['perm'] = pool.get(ref_model).perm_read(cr, uid, [ref_id], context)[0] ref_expr_context = Env(refobj, current_user) try: if not nodes[nid]['gray']: nodes[nid]['active'] = eval(nodes[nid]['model_states'], ref_expr_context) except: pass for r in relatives: node = nodes[r] if 'res' not in node: for n, f in fields.items(): if node['model'] == ref_model: update_relatives(r, ref_id, ref_model) elif f.get('relation') == node['model']: rel = refobj[n] if rel and isinstance(rel, list) : rel = rel[0] try: # XXX: rel has been reported as string (check it) _id = (rel or False) and rel.id _model = node['model'] update_relatives(r, _id, _model) except: pass
def get_resources_with_lang(self, cr, uid, external_session, resources, primary_key, context=None): new_resources = {} for resource_id, resource in resources.items(): new_resource = {} for lang, fields in resource.items(): if lang == 'no_lang': if resource['no_lang'].get('ext_id'): resource['no_lang']['id'] = resource['no_lang'].pop('ext_id') new_resource.update(resource['no_lang']) else: lang_id = self.pool.get('res.lang').search(cr, uid, [('code', '=', lang)], context=context)[0] presta_id = self.pool.get('res.lang').get_extid(cr, uid, lang_id, external_session.referential_id.id, context=context) for field, value in fields.items(): if field == 'ext_id': continue lang_and_value = {'attrs': {'id': '%s' %presta_id}, 'value': value} if not new_resource.get(field): new_resource[field] = {'language' : [lang_and_value]} else: new_resource[field]['language'].append(lang_and_value) new_resources[resource_id] = {primary_key : new_resource} return new_resources