def button_clicked(self, widget): record = self.screen.current_record record_id = self.screen.save_current() attrs = widget.attrs if record_id: if not attrs.get('confirm', False) or \ common.sur(attrs['confirm']): button_type = attrs.get('type', 'object') context = record.context_get() if button_type == 'object': try: RPCExecute('model', self.screen.model_name, attrs['name'], [record_id], context=context) except RPCException: pass elif button_type == 'action': action_id = None try: action_id = RPCExecute('model', 'ir.action', 'get_action_id', int(attrs['name']), context=context) except RPCException: pass if action_id: Action.execute(action_id, { 'model': self.screen.model_name, 'id': record_id, 'ids': [record_id], }, context=context) else: raise Exception('Unallowed button type') self.screen.reload(written=True) else: self.screen.display()
def row_activate(self): if not self.screen.current_record: return if (self.screen.current_view.view_type == 'tree' and int( self.screen.current_view.attributes.get('keyword_open', 0))): GenericAction.exec_keyword( 'tree_open', { 'model': self.screen.model_name, 'id': (self.screen.current_record.id if self.screen.current_record else None), 'ids': [r.id for r in self.screen.selected_records], }, context=self.screen.group._context.copy(), warning=False) else: def callback(result): if result: self.screen.current_record.save() else: self.screen.current_record.cancel() WinForm(self.screen, callback, title=self.title.get_text())
def _action(self, action, atype): if not self.modified_save(): return action = action.copy() record_id = (self.screen.current_record.id if self.screen.current_record else None) if action.get('records') == 'listed': record_ids = [r.id for r in self.screen.listed_records] record_paths = self.screen.listed_paths else: record_ids = [r.id for r in self.screen.selected_records] record_paths = self.screen.selected_paths data = { 'model': self.screen.model_name, 'model_context': (self.screen.context_screen.model_name if self.screen.context_screen else None), 'id': record_id, 'ids': record_ids, 'paths': record_paths, } Action.execute(action, data, context=self.screen.local_context)
def _set_preferences(prefs): try: prefs = prefs() except RPCException: prefs = {} threads = [] for target in ( common.ICONFACTORY.load_icons, common.MODELACCESS.load_models, common.MODELHISTORY.load_history, common.VIEW_SEARCH.load_searches, ): t = threading.Thread(target=target) threads.append(t) t.start() for t in threads: t.join() if prefs and 'language_direction' in prefs: translate.set_language_direction(prefs['language_direction']) CONFIG['client.language_direction'] = \ prefs['language_direction'] self.sig_win_menu(prefs=prefs) for action_id in prefs.get('actions', []): Action.execute(action_id, {}) self.set_title(prefs.get('status_bar', '')) if prefs and 'language' in prefs: translate.setlang(prefs['language'], prefs.get('locale')) if CONFIG['client.lang'] != prefs['language']: self.favorite_unset() CONFIG['client.lang'] = prefs['language'] # Set placeholder after language is set to get correct translation self.global_search_entry.set_placeholder_text(_("Action")) CONFIG.save()
def _button_class(self, button): ids = [r.id for r in self.selected_records] context = self.context context['_timestamp'] = {} for record in self.selected_records: context['_timestamp'].update(record.get_timestamp()) try: action = RPCExecute('model', self.model_name, button['name'], ids, context=context) except RPCException: action = None # PJA: handle different returns values from button if isinstance(action, list): action_id, action = action elif isinstance(action, int): action_id, action = action, None else: action_id, action = None, action self.reload(ids, written=True) if isinstance(action, basestring): self.client_action(action) if action_id: Action.execute(action_id, { 'model': self.model_name, 'id': self.current_record.id, 'ids': ids, }, context=self.context, keyword=True)
def _button_class(self, button): ids = [r.id for r in self.selected_records] context = self.context.copy() context['_timestamp'] = {} for record in self.selected_records: context['_timestamp'].update(record.get_timestamp()) try: action = RPCExecute('model', self.model_name, button['name'], ids, context=context) except RPCException: action = None self.reload(ids, written=True) if isinstance(action, basestring): self.client_action(action) elif action: Action.execute(action, { 'model': self.model_name, 'id': self.current_record.id, 'ids': ids, }, context=self.context, keyword=True)
def activate(menuitem, action, atype): rec = load(record) action = Action.evaluate(action, atype, rec) data = {"model": model, "id": rec.id, "ids": [rec.id]} event = gtk.get_current_event() allow_similar = False if event.state & gtk.gdk.CONTROL_MASK or event.state & gtk.gdk.MOD1_MASK: allow_similar = True with Window(hide_current=True, allow_similar=allow_similar): Action._exec_action(action, data, {})
def _action_favorite(widget, id_): event = gtk.get_current_event() allow_similar = (event.state & gtk.gdk.MOD1_MASK or event.state & gtk.gdk.SHIFT_MASK) with Window(allow_similar=allow_similar): # ids is not defined to prevent to add suffix Action.exec_keyword('tree_open', { 'model': self.menu_screen.model_name, 'id': id_, })
def _action(self, action, atype): action = action.copy() if not self.screen.save_current(): return record_id = self.screen.id_get() record_ids = self.screen.sel_ids_get() action = Action.evaluate(action, atype, self.screen.current_record) data = { 'model': self.screen.model_name, 'id': record_id, 'ids': record_ids, } Action._exec_action(action, data, self.context)
def _action(self, action, atype): action = action.copy() if not self.screen.save_current(): return record_id = (self.screen.current_record.id if self.screen.current_record else None) record_ids = [r.id for r in self.screen.selected_records] action = Action.evaluate(action, atype, self.screen.current_record) data = { 'model': self.screen.model_name, 'id': record_id, 'ids': record_ids, } Action._exec_action(action, data, self.screen.context)
def activate(menuitem, action, atype): rec = load(record) data = { 'model': model, 'id': rec.id, 'ids': [rec.id], } event = Gtk.get_current_event() allow_similar = False if (event.state & Gdk.ModifierType.CONTROL_MASK or event.state & Gdk.ModifierType.MOD1_MASK): allow_similar = True with Window(hide_current=True, allow_similar=allow_similar): Action.execute(action, data, context=rec.get_context())
def _action(self, action, atype): if not self.modified_save(): return action = action.copy() record_id = (self.screen.current_record.id if self.screen.current_record else None) record_ids = [r.id for r in self.screen.selected_records] action = Action.evaluate(action, atype, self.screen.current_record) data = { 'model': self.screen.model_name, 'id': record_id, 'ids': record_ids, } Action.execute(action, data, context=self.screen.local_context)
def match_selected(completion, model, iter_): model, record_id, model_name = model.get(iter_, 2, 3, 4) if model == self.menu_screen.model_name: # ids is not defined to prevent to add suffix Action.exec_keyword('tree_open', { 'model': model, 'id': record_id, }) else: Window.create(model, res_id=record_id, mode=['form', 'tree'], name=model_name) self.global_search_entry.set_text('') return True
def activate(menuitem, action, atype): rec = load(record) action = Action.evaluate(action, atype, rec) data = { 'model': model, 'id': rec.id, 'ids': [rec.id], } event = gtk.get_current_event() allow_similar = False if (event.state & gtk.gdk.CONTROL_MASK or event.state & gtk.gdk.MOD1_MASK): allow_similar = True with Window(hide_current=True, allow_similar=allow_similar): Action._exec_action(action, data, rec.get_context())
def execute_actions(): for action in result.get('actions', []): for k, v in [ ('direct_print', self.direct_print), ('email_print', self.email_print), ('email', self.email), ]: action[0].setdefault(k, v) context = self.context.copy() # Remove wizard keys added by run del context['active_id'] del context['active_ids'] del context['active_model'] del context['action_id'] Action.execute(*action, context=context)
def click_and_action(self, atype, value, path): return Action.exec_keyword(atype, { 'model': self.screen.group.fields[ path[1].name].attrs['relation'], 'id': value or False, 'ids': [value], }, alwaysask=True)
def menu_row_activate(self): screen = self.menu_screen record_id = (screen.current_record.id if screen.current_record else None) # ids is not defined to prevent to add suffix return Action.exec_keyword('tree_open', { 'model': screen.model_name, 'id': record_id, }, warning=False)
def open_report(report): if not report: return try: data = json.loads(params.get('data'), object_hook=object_hook) direct_print = json.loads(params.get('direct_print', 'false')) context = json.loads(params.get('context', '{}'), object_hook=object_hook) except ValueError: return try: Action.exec_report(report, data, direct_print=direct_print, context=context) except Exception: # Prevent crashing the client return
def row_activate(self): if not self.screen.current_record: return if (self.screen.current_view.view_type == 'tree' and self.screen.current_view.treeview.keyword_open): GenericAction.exec_keyword('tree_open', { 'model': self.screen.model_name, 'id': self.screen.id_get(), 'ids': [self.screen.id_get()], }, context=self.screen.context.copy(), warning=False) else: def callback(result): if result: self.screen.current_record.save() else: self.screen.current_record.cancel() WinForm(self.screen, callback)
def get_preferences(self, date=''): RPCContextReload() try: prefs = RPCExecute('model', 'res.user', 'get_preferences', False) except RPCException: prefs = {} threads = [] for target in ( common.IconFactory.load_icons, common.MODELACCESS.load_models, common.MODELHISTORY.load_history, common.VIEW_SEARCH.load_searches, ): t = threading.Thread(target=target) threads.append(t) t.start() for t in threads: t.join() if prefs and 'language_direction' in prefs: translate.set_language_direction(prefs['language_direction']) CONFIG['client.language_direction'] = \ prefs['language_direction'] self.sig_win_menu(prefs=prefs) for action_id in prefs.get('actions', []): Action.execute(action_id, {}) # XXX: add connection date connection_date = date.strftime('%d/%m/%Y') if date else '' self.set_title(prefs.get('status_bar', ''), connection_date) # AKE: change bg color based on preferences color_bg = prefs.get('color_bg', None ) or os.environ.get('TRYTON_CLIENT_BG_COLOR', None) if color_bg: self.window.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(color_bg)) if prefs and 'language' in prefs: translate.setlang(prefs['language'], prefs.get('locale')) if CONFIG['client.lang'] != prefs['language']: self.favorite_unset() CONFIG['client.lang'] = prefs['language'] # Set placeholder after language is set to get correct translation self.global_search_entry.set_placeholder_text(_("Action")) CONFIG.save()
def row_activate(self): if not self.screen.current_record: return if (self.screen.current_view.view_type == 'tree' and self.screen.current_view.attributes.get('keyword_open')): GenericAction.exec_keyword('tree_open', { 'model': self.screen.model_name, 'id': (self.screen.current_record.id if self.screen.current_record else None), 'ids': [r.id for r in self.screen.selected_records], }, context=self.screen.context.copy(), warning=False) else: def callback(result): if result: self.screen.current_record.save() else: self.screen.current_record.cancel() WinForm(self.screen, callback)
def button_clicked(self, widget, path): if not path: return True store = self.treeview.get_model() record = store.get_value(store.get_iter(path), 0) state_changes = record.expr_eval( self.attrs.get('states', {}), check_load=False) if state_changes.get('invisible') \ or state_changes.get('readonly'): return True self.screen.current_record = record obj_id = self.screen.save_current() if obj_id: if not self.attrs.get('confirm', False) or \ common.sur(self.attrs['confirm']): button_type = self.attrs.get('type', 'object') ctx = record.context_get() if button_type == 'object': try: RPCExecute('model', self.screen.model_name, self.attrs['name'], [obj_id], context=ctx) except RPCException: pass elif button_type == 'action': try: action_id = RPCExecute('model', 'ir.action', 'get_action_id', int(self.attrs['name']), context=ctx) except RPCException: action_id = None if action_id: Action.execute(action_id, { 'model': self.screen.model_name, 'id': obj_id, 'ids': [obj_id], }, context=ctx) else: raise Exception('Unallowed button type') self.screen.reload(written=True) else: self.screen.display()
def _button_class(self, button): ids = [r.id for r in self.selected_records] context = self.context.copy() context['_timestamp'] = {} for record in self.selected_records: context['_timestamp'].update(record.get_timestamp()) try: action = RPCExecute('model', self.model_name, button['name'], ids, context=context) except RPCException: action = None self.reload(ids, written=True) if isinstance(action, basestring): self.client_action(action) elif action: Action.execute(action, { 'model': self.model_name, 'id': self.current_record.id, 'ids': ids, }, context=self.context)
def default_row_activate(self): if (self.current_view.view_type == 'tree' and self.current_view.attributes.get('keyword_open')): return Action.exec_keyword('tree_open', { 'model': self.model_name, 'id': self.current_record.id if self.current_record else None, 'ids': [r.id for r in self.selected_records], }, context=self.context.copy(), warning=False) else: self.switch_view(view_type='form') return True
def default_row_activate(self): if (self.current_view.view_type == 'tree' and self.current_view.widget_tree.keyword_open): return Action.exec_keyword('tree_open', { 'model': self.model_name, 'id': self.id_get(), 'ids': [self.id_get()], }, context=self.context.copy(), warning=False) else: self.switch_view(view_type='form') return True
def button(self, button): 'Execute button on the current record' if button.get('confirm', False) and not sur(button['confirm']): return record = self.current_record if not record.save(force_reload=False): return context = record.context_get() try: action_id = RPCExecute('model', self.model_name, button['name'], [record.id], context=context) except RPCException: action_id = None if action_id: Action.execute(action_id, { 'model': self.model_name, 'id': record.id, 'ids': [record.id], }, context=context) self.reload([record.id], written=True)
def action_keyword(self, ids): if not ids: return ctx = self.group._context.copy() if 'active_ids' in ctx: del ctx['active_ids'] if 'active_id' in ctx: del ctx['active_id'] event = Gtk.get_current_event() allow_similar = False if (event.state & Gdk.ModifierType.CONTROL_MASK or event.state & Gdk.ModifierType.MOD1_MASK): allow_similar = True with Window(hide_current=True, allow_similar=allow_similar): return Action.exec_keyword('graph_open', { 'model': self.model, 'id': ids[0], 'ids': ids, }, context=ctx, warning=False)
def action_keyword(self, ids): if not ids: return ctx = self.group.context.copy() if 'active_ids' in ctx: del ctx['active_ids'] if 'active_id' in ctx: del ctx['active_id'] event = gtk.get_current_event() allow_similar = False if (event.state & gtk.gdk.CONTROL_MASK or event.state & gtk.gdk.MOD1_MASK): allow_similar = True with Window(hide_current=True, allow_similar=allow_similar): return Action.exec_keyword('graph_open', { 'model': self.model, 'id': ids[0], 'ids': ids, }, context=ctx, warning=False)
def click_and_relate(self, action, value, path): data = {} context = {} act = action.copy() if not(value): message(_('You must select a record to use the relation!')) return False from tryton.gui.window.view_form.screen import Screen screen = Screen(self.screen.group.fields[ path[1].name].attrs['relation']) screen.load([value]) encoder = PYSONEncoder() act['domain'] = encoder.encode(screen.current_record.expr_eval( act.get('domain', []), check_load=False)) act['context'] = encoder.encode(screen.current_record.expr_eval( act.get('context', {}), check_load=False)) data['model'] = self.screen.model_name data['id'] = value data['ids'] = [value] return Action._exec_action(act, data, context)
def clicked(self, data): Action.execute(self.action_id, *data, keyword=True)