コード例 #1
0
ファイル: ir_rule.py プロジェクト: ccdos/OpenERP
 def _eval_context_for_combinations(self):
     """Returns a dictionary to use as evaluation context for
        ir.rule domains, when the goal is to obtain python lists
        that are easier to parse and combine, but not to
        actually execute them."""
     return {'user': unquote('user'),
             'time': unquote('time')}
コード例 #2
0
ファイル: ir_rule.py プロジェクト: shivaniamrutiya/odoo-dev
 def _eval_context_for_combinations(self):
     """Returns a dictionary to use as evaluation context for
        ir.rule domains, when the goal is to obtain python lists
        that are easier to parse and combine, but not to
        actually execute them."""
     return {'user': unquote('user'),
             'time': unquote('time')}
コード例 #3
0
 def _read_flat(self, cr, uid, ids, fields_to_read, context=None, load='_classic_read'):
     res = super(IrActionsActWindow, self)._read_flat(cr, uid, ids, fields_to_read, context, load)
     if (not fields_to_read or 'context' in fields_to_read) and isinstance(ids, list):
         eval_dict = {'active_id': unquote("active_id"), 'active_ids': unquote("active_ids"),
                      'active_model': unquote("active_model"), 'uid': uid, 'context': context}
         for vals in res:
             try:
                 vals['context'] = eval(vals['context'], eval_dict) or {}
             except:
                 continue
             if 'window_action_id' not in context:
                 vals['context']['window_action_id'] = vals['id']
             vals['context'] = unicode(vals['context'])
     return res
コード例 #4
0
ファイル: ir_actions.py プロジェクト: tate11/odoo8_module
 def _update_context(self):
     eval_dict = {
         'active_id': unquote("active_id"),
         'active_ids': unquote("active_ids"),
         'active_model': unquote("active_model"),
         'uid': self._uid,
         'context': self._context,
     }
     try:
         context = eval(self.context or '{}', eval_dict) or {}
         if 'act_window_id' not in context:
             context['act_window_id'] = self.id
             self.context = '%s' % context
     except:
         pass
コード例 #5
0
ファイル: ir_values.py プロジェクト: A-Gut/odoo_addons
    def get_actions(self, cr, uid, action_slot, model, res_id=False, context=None):
        """Retrieves the list of actions bound to the given model's action slot.
           See the class description for more details about the various action
           slots: :class:`~.ir_values`.

           :param string action_slot: the action slot to which the actions should be
                                      bound to - one of ``client_action_multi``,
                                      ``client_print_multi``, ``client_action_relate``,
                                      ``tree_but_open``.
           :param string model: model name
           :param int res_id: optional record id - will bind the action only to a
                              specific record of the model, not all records.
           :return: list of action tuples of the form ``(id, name, action_def)``,
                    where ``id`` is the ID of the default entry, ``name`` is the
                    action label, and ``action_def`` is a dict containing the
                    action definition as obtained by calling
                    :meth:`~openerp.osv.osv.osv.read` on the action record.
        """
        assert action_slot in ACTION_SLOTS, 'Illegal action slot value: %s' % action_slot
        # use a direct SQL query for performance reasons,
        # this is called very often
        # Add by Smile #
        context = context or {}
        query = """SELECT v.id, v.name, v.value FROM ir_values v
                   WHERE v.key = %s AND v.key2 = %s
                        AND v.model = %s
                        AND (v.res_id = %s
                             OR v.res_id IS NULL
                             OR v.res_id = 0)
                         AND (v.window_actions IS NULL
                              OR v.window_actions=', , '
                              OR v.window_actions like %s)
                    ORDER BY v.sequence, v.id"""
        cr.execute(query, ('action', action_slot, model, res_id or None, ', %s, ' % context.get('window_action_id', '')))
        ################
        results = {}
        for action in cr.dictfetchall():
            if not action['value']:
                continue    # skip if undefined
            action_model, id = action['value'].split(',')
            fields = [field for field in self.pool.get(action_model)._all_columns
                      if field not in EXCLUDED_FIELDS]
            # FIXME: needs cleanup
            try:
                action_def = self.pool.get(action_model).read(cr, uid, int(id), fields, context)
                if action_def:
                    if action_model in ('ir.actions.report.xml', 'ir.actions.act_window',
                                        'ir.actions.wizard'):
                        groups = action_def.get('groups_id')
                        if groups:
                            cr.execute('SELECT 1 FROM res_groups_users_rel WHERE gid IN %s AND uid=%s',
                                       (tuple(groups), uid))
                            if not cr.fetchone():
                                if action['name'] == 'Menuitem':
                                    raise orm.except_orm('Error !',
                                                         'You do not have the permission to perform this operation !!!')
                                continue
                # keep only the first action registered for each action name
                # Add by Smile #
                if action_slot == 'tree_but_open' and action_def['type'] == 'ir.actions.act_window':
                    try:
                        action_context = eval(action_def['context'], {'active_id': unquote("active_id"), 'uid': uid})
                        action_context['window_action_id'] = action_def['id']
                        action_def['context'] = unicode(action_context)
                    except Exception as e:
                        logging.getLogger('smile.base').warning('Error in eval: %s - %s' % (action_def['context'], repr(e)))
                ################
                results[action['name']] = (action['id'], action['name'], action_def)
            except orm.except_orm:
                continue
        return sorted(results.values())
コード例 #6
0
    def get_actions(self,
                    cr,
                    uid,
                    action_slot,
                    model,
                    res_id=False,
                    context=None):
        """Retrieves the list of actions bound to the given model's action slot.
           See the class description for more details about the various action
           slots: :class:`~.ir_values`.

           :param string action_slot: the action slot to which the actions should be
                                      bound to - one of ``client_action_multi``,
                                      ``client_print_multi``, ``client_action_relate``,
                                      ``tree_but_open``.
           :param string model: model name
           :param int res_id: optional record id - will bind the action only to a
                              specific record of the model, not all records.
           :return: list of action tuples of the form ``(id, name, action_def)``,
                    where ``id`` is the ID of the default entry, ``name`` is the
                    action label, and ``action_def`` is a dict containing the
                    action definition as obtained by calling
                    :meth:`~openerp.osv.osv.osv.read` on the action record.
        """
        assert action_slot in ACTION_SLOTS, 'Illegal action slot value: %s' % action_slot
        # use a direct SQL query for performance reasons,
        # this is called very often
        # Add by Smile #
        context = context or {}
        query = """SELECT v.id, v.name, v.value FROM ir_values v
                   WHERE v.key = %s AND v.key2 = %s
                        AND v.model = %s
                        AND (v.res_id = %s
                             OR v.res_id IS NULL
                             OR v.res_id = 0)
                         AND (v.window_actions IS NULL
                              OR v.window_actions=', , '
                              OR v.window_actions like %s)
                    ORDER BY v.sequence, v.id"""
        cr.execute(query,
                   ('action', action_slot, model, res_id
                    or None, ', %s, ' % context.get('window_action_id', '')))
        ################
        results = {}
        for action in cr.dictfetchall():
            if not action['value']:
                continue  # skip if undefined
            action_model, id = action['value'].split(',')
            fields = [
                field for field in self.pool.get(action_model)._all_columns
                if field not in EXCLUDED_FIELDS
            ]
            # FIXME: needs cleanup
            try:
                action_def = self.pool.get(action_model).read(
                    cr, uid, int(id), fields, context)
                if action_def:
                    if action_model in ('ir.actions.report.xml',
                                        'ir.actions.act_window',
                                        'ir.actions.wizard'):
                        groups = action_def.get('groups_id')
                        if groups:
                            cr.execute(
                                'SELECT 1 FROM res_groups_users_rel WHERE gid IN %s AND uid=%s',
                                (tuple(groups), uid))
                            if not cr.fetchone():
                                if action['name'] == 'Menuitem':
                                    raise orm.except_orm(
                                        'Error !',
                                        'You do not have the permission to perform this operation !!!'
                                    )
                                continue
                # keep only the first action registered for each action name
                # Add by Smile #
                if action_slot == 'tree_but_open' and action_def[
                        'type'] == 'ir.actions.act_window':
                    try:
                        action_context = eval(action_def['context'], {
                            'active_id': unquote("active_id"),
                            'uid': uid
                        })
                        action_context['window_action_id'] = action_def['id']
                        action_def['context'] = unicode(action_context)
                    except Exception as e:
                        logging.getLogger('smile.base').warning(
                            'Error in eval: %s - %s' %
                            (action_def['context'], repr(e)))
                ################
                results[action['name']] = (action['id'], action['name'],
                                           action_def)
            except orm.except_orm:
                continue
        return sorted(results.values())