def addreplace_predef(self, widget): iter = self.model2.get_iter_first() fields = [] while iter: field_name = self.model2.get_value(iter, 1) fields.append(field_name) iter = self.model2.iter_next(iter) if not fields: return selection = self.pref_export.get_selection().get_selected() if selection is None: return model, iter_ = selection if iter_ is None: pref_id = None name = common.ask(_('What is the name of this export?')) if not name: return else: pref_id = model.get_value(iter_, 0) name = model.get_value(iter_, 2) override = common.sur(_("Override '%s' definition?") % name) if not override: return try: if not pref_id: pref_id, = RPCExecute( 'model', 'ir.export', 'create', [{ 'name': name, 'resource': self.model, 'export_fields': [('create', [{ 'name': x, } for x in fields])], }], context=self.context) else: RPCExecute('model', 'ir.export', 'update', [pref_id], fields, context=self.context) except RPCException: return clear_cache('model.%s.view_toolbar_get' % self.model) if iter_ is None: self.predef_model.append((pref_id, fields, name)) else: model.set_value(iter_, 0, pref_id) model.set_value(iter_, 1, fields)
def remove_predef(self, widget): sel = self.pref_export.get_selection().get_selected() if sel is None: return None (model, i) = sel if not i: return None export_id = model.get_value(i, 0) try: RPCExecute('model', 'ir.export', 'delete', [export_id], context=self.context) except RPCException: return clear_cache('model.%s.view_toolbar_get' % self.model) for i in range(len(self.predef_model)): if self.predef_model[i][0] == export_id: del self.predef_model[i] break self.pref_export.set_model(self.predef_model)
def save_tree_state(self, store=True): parent = self.parent.id if self.parent else None for view in self.views: if view.view_type == 'form': for widgets in view.widgets.values(): for widget in widgets: if hasattr(widget, 'screen'): widget.screen.save_tree_state(store) if len(self.views) == 1 and self.current_record: path = self.current_record.id if path < 0: path = -self.current_record.group.index( self.current_record) self.tree_states[parent][view.children_field] = ( [], [[path]]) elif view.view_type == 'tree': paths = view.get_expanded_paths() selected_paths = view.get_selected_paths() self.tree_states[parent][view.children_field] = ( paths, selected_paths) if (store and int(view.attributes.get('tree_state', False)) and CONFIG['client.save_tree_state']): json_domain = self.get_tree_domain(parent) json_paths = json.dumps(paths, separators=(',', ':')) json_selected_path = json.dumps( selected_paths, separators=(',', ':')) try: RPCExecute('model', 'ir.ui.view_tree_state', 'set', self.model_name, json_domain, view.children_field, json_paths, json_selected_path, process_exception=False) clear_cache('model.ir.ui.view_tree_state.get') except Exception: logger.warn( _('Unable to set view tree state'), exc_info=True)