def createWindow(view_ids, model, res_id=False, domain=None, view_type='form', window=None, context=None, mode=None, name=False, autoReload=False, target='current'): if context is None: context = {} context.update(Rpc.session.context) if view_type == 'form': QApplication.setOverrideCursor(Qt.WaitCursor) mode = (mode or 'form,tree').split(',') try: widget = FormWidget(model, res_id, domain, view_type=mode, view_ids=(view_ids or []), context=context, name=name) except Rpc.RpcException as e: QApplication.restoreOverrideCursor() return if target == 'new': widget.setStatusBarVisible(False) widget.setAutoReload(autoReload) QApplication.restoreOverrideCursor() Api.instance.windowCreated(widget, target) elif view_type == 'tree': QApplication.setOverrideCursor(Qt.WaitCursor) try: if view_ids and view_ids[0]: view_base = Rpc.session.execute('/object', 'execute', 'ir.ui.view', 'read', [view_ids[0]], ['model', 'type'], context)[0] model = view_base['model'] view = Rpc.session.execute('/object', 'execute', view_base['model'], 'fields_view_get', view_ids[0], view_base['type'], context) else: view = Rpc.session.execute('/object', 'execute', model, 'fields_view_get', False, view_type, context) win = TreeWidget(view, model, domain, context, name=name) except Rpc.RpcException as e: QApplication.restoreOverrideCursor() return QApplication.restoreOverrideCursor() Api.instance.windowCreated(win, target) else: Debug.error('unknown view type: ' + view_type)
def tagStart(self, name, attrs): if name == 'tree': self.title = attrs.get('string', _('Tree')) self.toolbar = bool(attrs.get('toolbar', False)) elif name == 'field': if 'icon' in attrs: self.fieldsOrder.append(str(attrs['icon'])) self.fieldsOrder.append(str(attrs['name'])) else: Debug.error('unknown tag: ' + str(name))
def evaluateExpression(self, dom, checkLoad=True, firstTry=True): """ Evaluates the string expression given by dom. Before passing the dom expression to Rpc.session.evaluateExpression a context with 'current_date', 'time', 'context', 'active_id' and 'parent' (if applies) is prepared. :param dom: :param checkLoad: :param firstTry: :return: """ if not isinstance(dom, str): return dom if checkLoad: self.ensureIsLoaded() d = {} for name in self.values: d[name] = self.group.fieldObjects[name].get(self, checkLoad=checkLoad) d['current_date'] = time.strftime('%Y-%m-%d') d['time'] = time d['context'] = self.context() # Avoid setting None in the context as it might be sent to # the server and RPC doesn't support None d['active_id'] = self.id or False # It seems that some modules depend on the existance of 'id' # instead of 'active_id'. It has solved, for example, a problem # with the c2c_budget module. d['id'] = self.id or False if self.parent: d['parent'] = EvalEnvironment(self.parent) try: val = Rpc.session.evaluateExpression(dom, d) except NameError as exception: # If evaluateExpression raises a NameError exception like this one: # NameError: name 'unit_amount' is not defined # It may be because not all fields are loaded yet, so we'll ensure # the model is loaded and re-evaluate. If that doesn't solve the # problem (that is firstTry == False) then raise the exception # because it's really an issue on the view definition. if firstTry: self.group.ensureRecordLoaded(self) val = self.evaluateExpression(dom, checkLoad, firstTry=False) else: Debug.error( _('Error evaluating expression: %s') % exception.args) val = False return val