Esempio n. 1
0
 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()
Esempio n. 2
0
    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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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()
Esempio n. 6
0
 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)
Esempio n. 7
0
 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())
Esempio n. 8
0
 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)
Esempio n. 9
0
    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()
Esempio n. 10
0
    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()
Esempio n. 11
0
 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)
Esempio n. 12
0
 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)
Esempio n. 13
0
 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)
Esempio n. 14
0
 def clicked(self, data):
     Action.execute(self.action_id, *data, keyword=True)