def update_params(self, params): super(DTLink, self).update_params(params) locale = get_locale() link = "jscal/lang/calendar-%s.js" % locale if tools.resources.resource_exists("openerp", "static", link): params['link'] = tools.url(["/openerp/static", link]) else: link = "jscal/lang/calendar-%s.js" % locale.language if tools.resources.resource_exists("openerp", "static", link): params['link'] = tools.url(["/openerp/static", link])
def __init__(self, **attrs): icon = attrs.get('name') attrs['name'] = attrs.get('name', 'Image').replace("-", "_") super(Image, self).__init__(**attrs) self.filename = attrs.get('filename', '') self.state = attrs.get('state') self.field = self.name.split('/')[-1] if attrs.get('widget'): extra_url_params = {} if not (self.id and self.id != 'None'): # during record creation provide current value (from default_get()) # so we do not need to call default_get() twice extra_url_params['default_value'] = self.value self.src = tools.url('/openerp/form/binary_image_get_image', model=self.model, id=self.id, field=self.field, nocache=random.randint(0, 2**32), **extra_url_params) self.height = attrs.get('img_height', attrs.get('height', None)) self.width = attrs.get('img_width', attrs.get('width', None)) self.validator = validators.Binary() else: self.src = icons.get_icon(icon) if self.readonly: self.editable = False
def default(self, view_id): try: view_id = eval(view_id) except: pass if isinstance(view_id, basestring) or not view_id: raise common.message(_("Invalid view id.")) res = rpc.RPCProxy('ir.ui.view').read([view_id], ['model', 'type'])[0] model = res['model'] view_type = res['type'] headers = [{ 'string': 'Name', 'name': 'string', 'type': 'char' }, { 'string': '', 'name': 'add', 'type': 'image', 'width': 2 }, { 'string': '', 'name': 'delete', 'type': 'image', 'width': 2 }, { 'string': '', 'name': 'edit', 'type': 'image', 'width': 2 }, { 'string': '', 'name': 'up', 'type': 'image', 'width': 2 }, { 'string': '', 'name': 'down', 'type': 'image', 'width': 2 }] tree = widgets.treegrid.TreeGrid( 'view_tree', model=model, headers=headers, url=url('/openerp/viewed/data?view_id=' + str(view_id))) tree.showheaders = False tree.onselection = 'onSelect' tree.onbuttonclick = 'onButtonClick' tree.expandall = True return dict(view_id=view_id, view_type=view_type, model=model, tree=tree)
def imp(self, error=None, records=None, success=None, **kw): params, data = TinyDict.split(kw) ctx = dict((params.context or {}), **rpc.session.context) views = {} if params.view_mode and params.view_ids: for i, view in enumerate(params.view_mode): views[view] = params.view_ids[i] headers = [{'string': 'Name', 'name': 'name', 'type': 'char'}] tree = treegrid.TreeGrid('import_fields', model=params.model, headers=headers, url=tools.url('/openerp/impex/get_fields'), field_parent='relation', views=views, context=ctx, is_importing=1) tree.show_headers = False return dict(error=error, records=records, success=success, model=params.model, source=params.source, tree=tree, fields=kw.get('fields', {}))
def login(self, db=None, user=None, password=None, style=None, location=None, message=None, **kw): location = url(location or '/', kw or {}) if cherrypy.request.params.get('tg_format') == 'json': if rpc.session.login(db, user, password) > 0: return dict(result=1) return dict(result=0) if style in ('ajax', 'ajax_small'): return dict( db=db, user=user, password=password, location=location, style=style, cp_template="/openerp/controllers/templates/login_ajax.mako") return tiny_login(target=location, db=db, user=user, password=password, action="login", message=message)
def update_params(self, params): if self.validator is openobject.validators.DefaultValidator: self.validator = openobject.validators.Schema() for f in self.fields: self.validator.add_field(f.name, f.validator) super(DBForm, self).update_params(params) params['attrs']['action'] = url(self.action)
def exp(self, import_compat="1", **kw): params, data = TinyDict.split(kw) ctx = dict((params.context or {}), **rpc.get_session().context) views = {} if params.view_mode and params.view_ids: for i, view in enumerate(params.view_mode): views[view] = params.view_ids[i] exports = rpc.RPCProxy('ir.exports') headers = [{'string' : 'Name', 'name' : 'name', 'type' : 'char'}] tree = treegrid.TreeGrid('export_fields', model=params.model, headers=headers, url=tools.url('/openerp/impex/get_fields'), field_parent='relation', context=ctx, views=views, import_compat=int(import_compat)) tree.show_headers = False existing_exports = exports.read( exports.search([('resource', '=', params.model)], context=ctx), [], ctx) return dict(existing_exports=existing_exports, model=params.model, ids=params.ids, ctx=ctx, search_domain=params.search_domain, source=params.source, tree=tree, import_compat=import_compat)
def get_link(self): m2o_link = int(self.attrs.get('link', 1)) if m2o_link == 1: return tools.url('/openerp/form/view', model=self.attrs['relation'], id=(self.value or False) and self.value[0]) else: return None
def exp(self, import_compat="0", **kw): params, data = TinyDict.split(kw) ctx = dict((params.context or {}), **rpc.session.context) views = {} if params.view_mode and params.view_ids: for i, view in enumerate(params.view_mode): views[view] = params.view_ids[i] export_format = data.get('export_format', 'excel') all_records = data.get('all_records', '0') if not params.ids: all_records = '1' exports = rpc.RPCProxy('ir.exports') headers = [{'string' : 'Name', 'name' : 'name', 'type' : 'char'}] tree = treegrid.TreeGrid('export_fields', model=params.model, headers=headers, url=tools.url('/openerp/impex/get_fields'), field_parent='relation', context=ctx, views=views, import_compat=int(import_compat)) tree.show_headers = False existing_exports = exports.read( exports.search([('resource', '=', params.model)], context=ctx), [], ctx) default = [] if params._terp_listheaders: default = [x.split(',',1) for x in params._terp_listheaders] elif kw.get('_terp_fields2') and kw.get('fields') and params.fields2: default = [] for i in range(0, len(kw.get('fields'))): if import_compat=='1' and '/' in kw.get('fields')[i] and kw.get('fields')[i].split('/')[-1] not in ('id', '.id'): continue default.append([kw['fields'][i], params.fields2[i]]) export_id = False if '_export_id' in kw and kw['_export_id']: export_id = int(kw['_export_id']) if params.model: proxy = rpc.RPCProxy(params.model) default = proxy.update_exported_fields(default) if params.model == 'product.product': default = [x for x in default if x[0] not in product_remove_fields] default = simplejson.dumps(default) group_by_no_leaf = ctx and ctx.get('group_by_no_leaf', False) if params.search_data and ctx and not ctx.get('group_by') and params.search_data.get('group_by_ctx'): ctx['group_by'] = params.search_data['group_by_ctx'] return dict(existing_exports=existing_exports, model=params.model, ids=params.ids, ctx=ctx, search_domain=params.search_domain, source=params.source, group_by_no_leaf=group_by_no_leaf, tree=tree, import_compat=import_compat, default=default, export_format=export_format, all_records=all_records, export_id=export_id)
def menu(self, active=None, next=None): from openerp.widgets import tree_view try: id = int(active) except: id = False form.Form().reset_notebooks() ctx = rpc.session.context.copy() menus = rpc.RPCProxy("ir.ui.menu") domain = [('parent_id', '=', False)] user_menu_action_id = rpc.RPCProxy("res.users").read([rpc.session.uid], ['menu_id'], ctx)[0]['menu_id'] if user_menu_action_id: act = rpc.RPCProxy('ir.actions.act_window').read([user_menu_action_id[0]], ['res_model', 'domain'], ctx)[0] if act['res_model'] == 'ir.ui.menu' and act['domain']: domain = literal_eval(act['domain']) ids = menus.search(domain, 0, 0, 0, ctx) parents = menus.read(ids, ['name', 'action', 'web_icon_data', 'web_icon_hover_data'], ctx) for parent in parents: if parent['id'] == id: parent['active'] = 'active' if parent.get('action') and not next: next = url('/openerp/custom_action', action=id) # If only the hover image exists, use it as regular image as well if parent['web_icon_hover_data'] and not parent['web_icon_data']: parent['web_icon_data'] = parent['web_icon_hover_data'] if next or active: if not id and ids: id = ids[0] ids = menus.search([('parent_id', '=', id)], 0, 0, 0, ctx) tools = menus.read(ids, ['name', 'action'], ctx) #searching id for the hierarchycal tree view of ir.ui.menu view_id = rpc.RPCProxy('ir.ui.view').search([('model','=','ir.ui.menu'),('type','=','tree')],0,0,'id')[0] view = cache.fields_view_get('ir.ui.menu', view_id, 'tree', {}) fields = cache.fields_get(view['model'], False, ctx) for tool in tools: tid = tool['id'] tool['tree'] = tree = tree_view.ViewTree(view, 'ir.ui.menu', tid, domain=[('parent_id', '=', tid)], context=ctx, action="/openerp/tree/action", fields=fields) tree._name = "tree_%s" %(tid) tree.tree.onselection = None tree.tree.onheaderclick = None tree.tree.showheaders = 0 else: # display home action tools = None return dict(parents=parents, tools=tools, load_content=(next and next or ''), welcome_messages=rpc.RPCProxy('publisher_warranty.contract').get_last_user_messages(_MAXIMUM_NUMBER_WELCOME_MESSAGES), show_close_btn=rpc.session.uid == 1, widgets=openobject.pooler.get_pool()\ .get_controller('/openerp/widgets')\ .user_home_widgets(ctx))
def get_link(self): m2o_link = int(self.attrs.get("link", 1)) if m2o_link == 1: return tools.url( "/openerp/form/view", model=self.attrs["relation"], id=(self.value or False) and self.value[0] ) else: return None
def info(self): return """ <html> <head></head> <body> <div align="center" style="padding: 50px;"> <img border="0" src="%s"></img> </div> </body> </html> """ % (url("/openerp/static/images/loading.gif"))
def login(self, db=None, user=None, password=None, style=None, location=None, message=None, **kw): location = url(location or '/', kw or {}) if cherrypy.request.params.get('tg_format') == 'json': if rpc.session.login(db, user, password) > 0: return dict(result=1) return dict(result=0) if style in ('ajax', 'ajax_small'): return dict(db=db, user=user, password=password, location=location, style=style, cp_template="/openerp/controllers/templates/login_ajax.mako") return tiny_login(target=location, db=db, user=user, password=password, action="login", message=message)
def __init__(self, **attrs): icon = attrs.get('name') attrs['name'] = attrs.get('name', 'Image').replace("-","_") super(Image, self).__init__(**attrs) self.filename = attrs.get('filename', '') self.state = attrs.get('state') self.field = self.name.split('/')[-1] if attrs.get('widget'): self.src = tools.url('/openerp/form/binary_image_get_image', model=self.model, id=self.id, field=self.field, nocache=random.randint(0,2**32)) self.height = attrs.get('img_height', attrs.get('height', None)) self.width = attrs.get('img_width', attrs.get('width', None)) self.validator = validators.Binary() else: self.src = icons.get_icon(icon) if self.readonly: self.editable = False
def __init__(self, **attrs): icon = attrs.get('name') attrs['name'] = attrs.get('name', 'Image').replace("-", "_") super(Image, self).__init__(**attrs) self.filename = attrs.get('filename', '') self.state = attrs.get('state') self.field = self.name.split('/')[-1] if attrs.get('widget'): self.src = tools.url('/openerp/form/binary_image_get_image', model=self.model, id=self.id, field=self.field, nocache=random.randint(0, 2**32)) self.height = attrs.get('img_height', attrs.get('height', None)) self.width = attrs.get('img_width', attrs.get('width', None)) self.validator = validators.Binary() else: self.src = icons.get_icon(icon) if self.readonly: self.editable = False
def exp(self, import_compat="1", **kw): params, data = TinyDict.split(kw) ctx = dict((params.context or {}), **rpc.session.context) if ctx.get("group_by_no_leaf", 0): raise common.warning(_("You cannot export these record(s) !"), _('Error')) views = {} if params.view_mode and params.view_ids: for i, view in enumerate(params.view_mode): views[view] = params.view_ids[i] exports = rpc.RPCProxy('ir.exports') headers = [{'string': 'Name', 'name': 'name', 'type': 'char'}] tree = treegrid.TreeGrid('export_fields', model=params.model, headers=headers, url=tools.url('/openerp/impex/get_fields'), field_parent='relation', context=ctx, views=views, import_compat=int(import_compat)) tree.show_headers = False existing_exports = exports.read( exports.search([('resource', '=', params.model)], context=ctx), [], ctx) return dict(existing_exports=existing_exports, model=params.model, ids=params.ids, ctx=ctx, search_domain=params.search_domain, source=params.source, tree=tree, import_compat=import_compat)
def __init__(self, **attrs): icon = attrs.get('name') attrs['name'] = attrs.get('name', 'Image').replace("-","_") super(Image, self).__init__(**attrs) self.filename = attrs.get('filename', '') self.state = attrs.get('state') self.field = self.name.split('/')[-1] if attrs.get('widget'): extra_url_params = {} if not (self.id and self.id != 'None'): # during record creation provide current value (from default_get()) # so we do not need to call default_get() twice extra_url_params['default_value'] = self.value self.src = tools.url('/openerp/form/binary_image_get_image', model=self.model, id=self.id, field=self.field, nocache=random.randint(0,2**32), **extra_url_params) self.height = attrs.get('img_height', attrs.get('height', None)) self.width = attrs.get('img_width', attrs.get('width', None)) self.validator = validators.Binary() else: self.src = icons.get_icon(icon) if self.readonly: self.editable = False
def __init__(self, **attrs): icon = attrs.get("name") attrs["name"] = attrs.get("name", "Image").replace("-", "_") super(Image, self).__init__(**attrs) self.filename = attrs.get("filename", "") self.state = attrs.get("state") self.field = self.name.split("/")[-1] if attrs.get("widget"): self.src = tools.url( "/openerp/form/binary_image_get_image", model=self.model, id=self.id, field=self.field, nocache=random.randint(0, 2 ** 32), ) self.height = attrs.get("img_height", attrs.get("height", None)) self.width = attrs.get("img_width", attrs.get("width", None)) self.validator = validators.Binary() else: self.src = icons.get_icon(icon) if self.readonly: self.editable = False
def imp(self, error=None, records=None, success=None, **kw): params, data = TinyDict.split(kw) ctx = dict((params.context or {}), **rpc.get_session().context) views = {} if params.view_mode and params.view_ids: for i, view in enumerate(params.view_mode): views[view] = params.view_ids[i] headers = [{'string' : 'Name', 'name' : 'name', 'type' : 'char'}] tree = treegrid.TreeGrid('import_fields', model=params.model, headers=headers, url=tools.url('/openerp/impex/get_fields'), field_parent='relation', views=views, context=ctx, is_importing=1) tree.show_headers = False return dict(error=error, records=records, success=success, model=params.model, source=params.source, tree=tree, fields=kw.get('fields', {}))
def __init__(self, view, model, res_id=False, domain=[], context={}, action=None, fields=None): super(ViewTree, self).__init__(name='view_tree', action=action) self.model = view['model'] self.domain2 = domain or [] self.context = context or {} self.domain = [] fields_info = dict(fields) self.field_parent = view.get("field_parent") or None if self.field_parent: self.domain = domain self.view = view self.view_id = view['view_id'] proxy = rpc.RPCProxy(self.model) ctx = dict(self.context, **rpc.session.context) dom = xml.dom.minidom.parseString(view['arch'].encode('utf-8')) root = dom.childNodes[0] attrs = node_attributes(root) self.string = attrs.get('string', 'Unknown') self.toolbar = attrs.get('toolbar', False) ids = [] id = res_id colors = {} for color_spec in attrs.get('colors', '').split(';'): if color_spec: colour, test = color_spec.split(':') colors[colour] = test if self.toolbar: ids = proxy.search(self.domain2, 0, 0, 0, ctx) self.toolbar = proxy.read(ids, ['name', 'icon'], ctx) if not id and ids: id = ids[0] if id: ids = proxy.read([id], [self.field_parent], ctx)[0][self.field_parent] elif not ids: ids = proxy.search(domain, 0, 0, 0, ctx) self.headers = [] self.parse(root, fields) self.tree = treegrid.TreeGrid(name="tree_%d" % (id), model=self.model, headers=self.headers, url=url("/openerp/tree/data"), ids=ids, domain=self.domain, context=self.context, field_parent=self.field_parent, onselection="onSelection", fields_info=fields_info, colors=colors) self.id = id self.ids = ids toolbar = {} for item, value in view.get('toolbar', {}).items(): if value: toolbar[item] = value if toolbar: self.sidebar = Sidebar(self.model, None, toolbar, context=self.context) # get the correct view title self.string = self.context.get('_terp_view_name', self.string) or self.string
def update_params(self, params): super(DBForm, self).update_params(params) params['attrs']['action'] = url(self.action)
def get_link(self): m2o_link = int(self.attrs.get('link', 1)) if m2o_link == 1 and self.refrel and self.refid: return tools.url('/openerp/form/view', model=self.refrel, id=self.refid) return None
def get_link(self): return tools.url('/%s/static/%s' % (self.modname, self.filename))
def __init__(self, view, model, res_id=False, domain=[], context={}, action=None, fields=None): super(ViewTree, self).__init__(name='view_tree', action=action) self.model = view['model'] self.domain2 = domain or [] self.context = context or {} self.domain = [] fields_info = dict(fields) self.field_parent = view.get("field_parent") or None if self.field_parent: self.domain = domain self.view = view self.view_id = view['view_id'] proxy = rpc.RPCProxy(self.model) ctx = dict(self.context, **rpc.session.context) dom = xml.dom.minidom.parseString(view['arch'].encode('utf-8')) root = dom.childNodes[0] attrs = node_attributes(root) self.string = attrs.get('string', 'Unknown') self.toolbar = attrs.get('toolbar', False) # Set the button to be optional self.expand_button = attrs.get('expand_button', False) nolink = attrs.get('nolink', '0') ids = [] id = res_id colors = {} for color_spec in attrs.get('colors', '').split(';'): if color_spec: colour, test = color_spec.split(':') colors[colour] = test if self.toolbar: ids = proxy.search(self.domain2, 0, 0, 0, ctx) self.toolbar = proxy.read(ids, ['name', 'icon'], ctx) if not id and ids: id = ids[0] if id: ids = proxy.read([id], [self.field_parent], ctx)[0][self.field_parent] elif not ids: ids = proxy.search(domain, 0, 0, 0, ctx) self.headers = [] self.parse(root, fields) self.tree = treegrid.TreeGrid(name="tree_%d" % (id), model=self.model, headers=self.headers, url=url("/openerp/tree/data"), ids=ids, domain=self.domain, context=self.context, field_parent=self.field_parent, onselection="onSelection", fields_info=fields_info, colors=colors, nolink=nolink) self.id = id self.ids = ids toolbar = {} for item, value in view.get('toolbar', {}).items(): if value: toolbar[item] = value if toolbar: self.sidebar = Sidebar(self.model, None, toolbar, context=self.context) # get the correct view title self.string = self.context.get('_terp_view_name', self.string) or self.string
def data(self, ids, model, fields, field_parent=None, icon_name=None, domain=[], context={}, sort_by=None, sort_order="asc", fields_info=None): if ids == 'None' or ids == '': ids = [] if isinstance(ids, basestring): ids = map(int, ids.split(',')) elif isinstance(ids, list): ids = map(int, ids) if isinstance(fields, basestring): fields = eval(fields) if isinstance(domain, basestring): domain = eval(domain) if isinstance(context, basestring): context = eval(context) if isinstance(fields_info, basestring): fields_info = simplejson.loads(fields_info) if field_parent and field_parent not in fields: fields.append(field_parent) proxy = rpc.RPCProxy(model) ctx = dict(context, **rpc.session.context) if icon_name: fields.append(icon_name) if model == 'ir.ui.menu' and 'action' not in fields: fields.append('action') result = proxy.read(ids, fields, ctx) if sort_by: fields_info_type = simplejson.loads(fields_info[sort_by]) result.sort(lambda a, b: self.sort_callback( a, b, sort_by, sort_order, type=fields_info_type['type'])) # format the data for field in fields: field_info = simplejson.loads(fields_info[field]) formatter = FORMATTERS.get(field_info['type']) for x in result: if x[field] and formatter: x[field] = formatter(x[field], field_info) records = [] for item in result: # empty string instead of False or None for k, v in item.items(): if v is None or v is False: item[k] = '' id = item.pop('id') record = { 'id': id, 'action': url('/openerp/tree/open', model=model, id=id, context=ctx), 'target': None, 'icon': None, 'children': [], 'items': item } if icon_name and item.get(icon_name): icon = item.pop(icon_name) record['icon'] = icons.get_icon(icon) if field_parent and field_parent in item: record['children'] = item.pop(field_parent) or None # For nested menu items, remove void action url # to suppress 'No action defined' error. if (model == 'ir.ui.menu' and record['children'] and not item['action']): record['action'] = None records.append(record) return {'records': records}
def data(self, ids, model, fields, field_parent=None, icon_name=None, domain=[], context={}, sort_by=None, sort_order="asc", fields_info=None): if ids == 'None' or ids == '': ids = [] if isinstance(ids, basestring): ids = map(int, ids.split(',')) elif isinstance(ids, list): ids = map(int, ids) if isinstance(fields, basestring): fields = eval(fields) if isinstance(domain, basestring): domain = eval(domain) if isinstance(context, basestring): context = eval(context) if isinstance(fields_info, basestring): fields_info = simplejson.loads(fields_info) if field_parent and field_parent not in fields: fields.append(field_parent) proxy = rpc.RPCProxy(model) ctx = dict(context, **rpc.session.context) if icon_name: fields.append(icon_name) if model == 'ir.ui.menu' and 'action' not in fields: fields.append('action') result = proxy.read(ids, fields, ctx) if sort_by: fields_info_type = simplejson.loads(fields_info[sort_by]) result.sort(lambda a,b: self.sort_callback(a, b, sort_by, sort_order, type=fields_info_type['type'])) # format the data for field in fields: field_info = simplejson.loads(fields_info[field]) formatter = FORMATTERS.get(field_info['type']) for x in result: if x[field] and formatter: x[field] = formatter(x[field], field_info) records = [] for item in result: # empty string instead of False or None for k, v in item.items(): if v is None or v is False: item[k] = '' id = item.pop('id') record = { 'id': id, 'action': url('/openerp/tree/open', model=model, id=id, context=ctx), 'target': None, 'icon': None, 'children': [], 'items': item } if icon_name and item.get(icon_name): icon = item.pop(icon_name) record['icon'] = icons.get_icon(icon) if field_parent and field_parent in item: record['children'] = item.pop(field_parent) or None # For nested menu items, remove void action url # to suppress 'No action defined' error. if (model == 'ir.ui.menu' and record['children'] and not item['action']): record['action'] = None records.append(record) return {'records': records}
def report_link(report_name, **kw): cherrypy.response.headers['X-Target'] = 'download' cherrypy.response.headers['Location'] = tools.url('/openerp/report', report_name=report_name, **kw) return dict(name=report_name, data=kw)
def report_link(report_name, **kw): cherrypy.response.headers['X-Target'] = 'download' cherrypy.response.headers['Location'] = tools.url( '/openerp/report', report_name=report_name, **kw) return dict(name=report_name, data=kw)
def default(self, view_id): try: view_id = eval(view_id) except: pass if isinstance(view_id, basestring) or not view_id: raise common.message(_("Invalid view id.")) res = rpc.RPCProxy('ir.ui.view').read([view_id], ['model', 'type'])[0] model = res['model'] view_type = res['type'] headers = [{'string' : 'Name', 'name' : 'string', 'type' : 'char'}, {'string' : '', 'name': 'add', 'type' : 'image', 'width': 2}, {'string' : '', 'name': 'delete', 'type' : 'image', 'width': 2}, {'string' : '', 'name': 'edit', 'type' : 'image', 'width': 2}, {'string' : '', 'name': 'up', 'type' : 'image', 'width': 2}, {'string' : '', 'name': 'down', 'type' : 'image', 'width': 2}] tree = widgets.treegrid.TreeGrid('view_tree', model=model, headers=headers, url=url('/openerp/viewed/data?view_id='+str(view_id))) tree.showheaders = False tree.onselection = 'onSelect' tree.onbuttonclick = 'onButtonClick' tree.expandall = True return dict(view_id=view_id, view_type=view_type, model=model, tree=tree)
def __init__(self, view, model, res_id=False, domain=[], context={}, action=None, fields=None): super(ViewTree, self).__init__(name='view_tree', action=action) self.model = view['model'] self.domain2 = domain or [] self.context = context or {} self.domain = [] fields_info = dict(fields) self.field_parent = view.get("field_parent") or None if self.field_parent: self.domain = domain self.view = view self.view_id = view['view_id'] proxy = rpc.RPCProxy(self.model) ctx = dict(self.context, **rpc.get_session().context) dom = xml.dom.minidom.parseString(view['arch'].encode('utf-8')) root = dom.childNodes[0] attrs = node_attributes(root) self.string = attrs.get('string', 'Unknown') self.toolbar = attrs.get('toolbar', False) ids = [] id = res_id if self.toolbar: ids = proxy.search(self.domain2, 0, 0, 0, ctx) self.toolbar = proxy.read(ids, ['name', 'icon'], ctx) if not id and ids: id = ids[0] if id: ids = proxy.read([id], [self.field_parent])[0][self.field_parent] elif not ids: ids = proxy.search(domain, 0, 0, 0, ctx) self.headers = [] self.parse(root, fields) self.tree = treegrid.TreeGrid(name="tree_%d" % (id), model=self.model, headers=self.headers, url=url("/openerp/tree/data"), ids=ids, domain=self.domain, context=self.context, field_parent=self.field_parent, onselection="onSelection", fields_info=fields_info) self.id = id self.ids = ids self.view_type = view.get('type') toolbar = {} for item, value in view.get('toolbar', {}).items(): if value: toolbar[item] = value if toolbar: self.sidebar = Sidebar(self.model, None, toolbar, self.id, self.view_type, context=self.context) else: if attrs.get('toolbar') and attrs['toolbar']: self.sidebar = Sidebar(self.model, None, None, self.id, self.view_type, context=self.context) # get the correct view title self.string = self.context.get('_terp_view_name', self.string) or self.string