Beispiel #1
0
    def _tag_act_window(self, cr, rec, data_node=None, mode=None):
        name = rec.get('name','').encode('utf-8')
        xml_id = rec.get('id','').encode('utf8')
        self._test_xml_id(xml_id)
        type = rec.get('type','').encode('utf-8') or 'ir.actions.act_window'
        view_id = False
        if rec.get('view_id'):
            view_id = self.id_get(cr, rec.get('view_id','').encode('utf-8'))
        domain = rec.get('domain','').encode('utf-8') or '[]'
        res_model = rec.get('res_model','').encode('utf-8')
        src_model = rec.get('src_model','').encode('utf-8')
        view_type = rec.get('view_type','').encode('utf-8') or 'form'
        view_mode = rec.get('view_mode','').encode('utf-8') or 'tree,form'
        usage = rec.get('usage','').encode('utf-8')
        limit = rec.get('limit','').encode('utf-8')
        auto_refresh = rec.get('auto_refresh','').encode('utf-8')
        uid = self.uid

        # Act_window's 'domain' and 'context' contain mostly literals
        # but they can also refer to the variables provided below
        # in eval_context, so we need to eval() them before storing.
        # Among the context variables, 'active_id' refers to
        # the currently selected items in a list view, and only
        # takes meaning at runtime on the client side. For this
        # reason it must remain a bare variable in domain and context,
        # even after eval() at server-side. We use the special 'unquote'
        # class to achieve this effect: a string which has itself, unquoted,
        # as representation.
        active_id = unquote("active_id")
        active_ids = unquote("active_ids")
        active_model = unquote("active_model")

        def ref(str_id):
            return self.id_get(cr, str_id)

        # Include all locals() in eval_context, for backwards compatibility
        eval_context = {
            'name': name,
            'xml_id': xml_id,
            'type': type,
            'view_id': view_id,
            'domain': domain,
            'res_model': res_model,
            'src_model': src_model,
            'view_type': view_type,
            'view_mode': view_mode,
            'usage': usage,
            'limit': limit,
            'auto_refresh': auto_refresh,
            'uid' : uid,
            'active_id': active_id,
            'active_ids': active_ids,
            'active_model': active_model,
            'ref' : ref,
        }
        context = self.get_context(data_node, rec, eval_context)

        try:
            domain = unsafe_eval(domain, eval_context)
        except NameError:
            # Some domains contain references that are only valid at runtime at
            # client-side, so in that case we keep the original domain string
            # as it is. We also log it, just in case.
            _logger.debug('Domain value (%s) for element with id "%s" does not parse '\
                'at server-side, keeping original string, in case it\'s meant for client side only',
                domain, xml_id or 'n/a', exc_info=True)
        res = {
            'name': name,
            'type': type,
            'view_id': view_id,
            'domain': domain,
            'context': context,
            'res_model': res_model,
            'src_model': src_model,
            'view_type': view_type,
            'view_mode': view_mode,
            'usage': usage,
            'limit': limit,
            'auto_refresh': auto_refresh,
        }

        if rec.get('groups'):
            g_names = rec.get('groups','').split(',')
            groups_value = []
            for group in g_names:
                if group.startswith('-'):
                    group_id = self.id_get(cr, group[1:])
                    groups_value.append((3, group_id))
                else:
                    group_id = self.id_get(cr, group)
                    groups_value.append((4, group_id))
            res['groups_id'] = groups_value

        if rec.get('target'):
            res['target'] = rec.get('target','')
        if rec.get('multi'):
            res['multi'] = eval(rec.get('multi', 'False'))
        id = self.pool['ir.model.data']._update(cr, self.uid, 'ir.actions.act_window', self.module, res, xml_id, noupdate=self.isnoupdate(data_node), mode=self.mode)
        self.idref[xml_id] = int(id)

        if src_model:
            #keyword = 'client_action_relate'
            keyword = rec.get('key2','').encode('utf-8') or 'client_action_relate'
            value = 'ir.actions.act_window,'+str(id)
            replace = rec.get('replace','') or True
            self.pool['ir.model.data'].ir_set(cr, self.uid, 'action', keyword, xml_id, [src_model], value, replace=replace, isobject=True, xml_id=xml_id)
Beispiel #2
0
    def _tag_act_window(self, cr, rec, data_node=None, mode=None):
        name = rec.get('name', '').encode('utf-8')
        xml_id = rec.get('id', '').encode('utf8')
        self._test_xml_id(xml_id)
        type = rec.get('type', '').encode('utf-8') or 'ir.actions.act_window'
        view_id = False
        if rec.get('view_id'):
            view_id = self.id_get(cr, rec.get('view_id', '').encode('utf-8'))
        domain = rec.get('domain', '').encode('utf-8') or '[]'
        res_model = rec.get('res_model', '').encode('utf-8')
        src_model = rec.get('src_model', '').encode('utf-8')
        view_type = rec.get('view_type', '').encode('utf-8') or 'form'
        view_mode = rec.get('view_mode', '').encode('utf-8') or 'tree,form'
        usage = rec.get('usage', '').encode('utf-8')
        limit = rec.get('limit', '').encode('utf-8')
        auto_refresh = rec.get('auto_refresh', '').encode('utf-8')
        uid = self.uid

        # Act_window's 'domain' and 'context' contain mostly literals
        # but they can also refer to the variables provided below
        # in eval_context, so we need to eval() them before storing.
        # Among the context variables, 'active_id' refers to
        # the currently selected items in a list view, and only
        # takes meaning at runtime on the client side. For this
        # reason it must remain a bare variable in domain and context,
        # even after eval() at server-side. We use the special 'unquote'
        # class to achieve this effect: a string which has itself, unquoted,
        # as representation.
        active_id = unquote("active_id")
        active_ids = unquote("active_ids")
        active_model = unquote("active_model")

        def ref(str_id):
            return self.id_get(cr, str_id)

        # Include all locals() in eval_context, for backwards compatibility
        eval_context = {
            'name': name,
            'xml_id': xml_id,
            'type': type,
            'view_id': view_id,
            'domain': domain,
            'res_model': res_model,
            'src_model': src_model,
            'view_type': view_type,
            'view_mode': view_mode,
            'usage': usage,
            'limit': limit,
            'auto_refresh': auto_refresh,
            'uid': uid,
            'active_id': active_id,
            'active_ids': active_ids,
            'active_model': active_model,
            'ref': ref,
        }
        context = self.get_context(data_node, rec, eval_context)

        try:
            domain = unsafe_eval(domain, eval_context)
        except NameError:
            # Some domains contain references that are only valid at runtime at
            # client-side, so in that case we keep the original domain string
            # as it is. We also log it, just in case.
            _logger.debug('Domain value (%s) for element with id "%s" does not parse '\
                'at server-side, keeping original string, in case it\'s meant for client side only',
                domain, xml_id or 'n/a', exc_info=True)
        res = {
            'name': name,
            'type': type,
            'view_id': view_id,
            'domain': domain,
            'context': context,
            'res_model': res_model,
            'src_model': src_model,
            'view_type': view_type,
            'view_mode': view_mode,
            'usage': usage,
            'limit': limit,
            'auto_refresh': auto_refresh,
        }

        if rec.get('groups'):
            g_names = rec.get('groups', '').split(',')
            groups_value = []
            for group in g_names:
                if group.startswith('-'):
                    group_id = self.id_get(cr, group[1:])
                    groups_value.append((3, group_id))
                else:
                    group_id = self.id_get(cr, group)
                    groups_value.append((4, group_id))
            res['groups_id'] = groups_value

        if rec.get('target'):
            res['target'] = rec.get('target', '')
        if rec.get('multi'):
            res['multi'] = eval(rec.get('multi', 'False'))
        id = self.pool['ir.model.data']._update(
            cr,
            self.uid,
            'ir.actions.act_window',
            self.module,
            res,
            xml_id,
            noupdate=self.isnoupdate(data_node),
            mode=self.mode)
        self.idref[xml_id] = int(id)

        if src_model:
            #keyword = 'client_action_relate'
            keyword = rec.get('key2',
                              '').encode('utf-8') or 'client_action_relate'
            value = 'ir.actions.act_window,' + str(id)
            replace = rec.get('replace', '') or True
            self.pool['ir.model.data'].ir_set(cr,
                                              self.uid,
                                              'action',
                                              keyword,
                                              xml_id, [src_model],
                                              value,
                                              replace=replace,
                                              isobject=True,
                                              xml_id=xml_id)
Beispiel #3
0
    def _tag_act_window(self, cr, rec, data_node=None):
        name = rec.get("name", "").encode("utf-8")
        xml_id = rec.get("id", "").encode("utf8")
        self._test_xml_id(xml_id)
        type = rec.get("type", "").encode("utf-8") or "ir.actions.act_window"
        view_id = False
        if rec.get("view_id"):
            view_id = self.id_get(cr, rec.get("view_id", "").encode("utf-8"))
        domain = rec.get("domain", "").encode("utf-8") or "[]"
        res_model = rec.get("res_model", "").encode("utf-8")
        src_model = rec.get("src_model", "").encode("utf-8")
        view_type = rec.get("view_type", "").encode("utf-8") or "form"
        view_mode = rec.get("view_mode", "").encode("utf-8") or "tree,form"
        usage = rec.get("usage", "").encode("utf-8")
        limit = rec.get("limit", "").encode("utf-8")
        auto_refresh = rec.get("auto_refresh", "").encode("utf-8")
        uid = self.uid

        # Act_window's 'domain' and 'context' contain mostly literals
        # but they can also refer to the variables provided below
        # in eval_context, so we need to eval() them before storing.
        # Among the context variables, 'active_id' refers to
        # the currently selected items in a list view, and only
        # takes meaning at runtime on the client side. For this
        # reason it must remain a bare variable in domain and context,
        # even after eval() at server-side. We use the special 'unquote'
        # class to achieve this effect: a string which has itself, unquoted,
        # as representation.
        active_id = unquote("active_id")
        active_ids = unquote("active_ids")
        active_model = unquote("active_model")

        def ref(str_id):
            return self.id_get(cr, str_id)

        # Include all locals() in eval_context, for backwards compatibility
        eval_context = {
            "name": name,
            "xml_id": xml_id,
            "type": type,
            "view_id": view_id,
            "domain": domain,
            "res_model": res_model,
            "src_model": src_model,
            "view_type": view_type,
            "view_mode": view_mode,
            "usage": usage,
            "limit": limit,
            "auto_refresh": auto_refresh,
            "uid": uid,
            "active_id": active_id,
            "active_ids": active_ids,
            "active_model": active_model,
            "ref": ref,
        }
        context = self.get_context(data_node, rec, eval_context)

        try:
            domain = unsafe_eval(domain, eval_context)
        except NameError:
            # Some domains contain references that are only valid at runtime at
            # client-side, so in that case we keep the original domain string
            # as it is. We also log it, just in case.
            _logger.debug(
                'Domain value (%s) for element with id "%s" does not parse '
                "at server-side, keeping original string, in case it's meant for client side only",
                domain,
                xml_id or "n/a",
                exc_info=True,
            )
        res = {
            "name": name,
            "type": type,
            "view_id": view_id,
            "domain": domain,
            "context": context,
            "res_model": res_model,
            "src_model": src_model,
            "view_type": view_type,
            "view_mode": view_mode,
            "usage": usage,
            "limit": limit,
            "auto_refresh": auto_refresh,
        }

        if rec.get("groups"):
            g_names = rec.get("groups", "").split(",")
            groups_value = []
            for group in g_names:
                if group.startswith("-"):
                    group_id = self.id_get(cr, group[1:])
                    groups_value.append((3, group_id))
                else:
                    group_id = self.id_get(cr, group)
                    groups_value.append((4, group_id))
            res["groups_id"] = groups_value

        if rec.get("target"):
            res["target"] = rec.get("target", "")
        if rec.get("multi"):
            res["multi"] = rec.get("multi", False)
        id = self.pool.get("ir.model.data")._update(
            cr,
            self.uid,
            "ir.actions.act_window",
            self.module,
            res,
            xml_id,
            noupdate=self.isnoupdate(data_node),
            mode=self.mode,
        )
        self.idref[xml_id] = int(id)

        if src_model:
            # keyword = 'client_action_relate'
            keyword = rec.get("key2", "").encode("utf-8") or "client_action_relate"
            value = "ir.actions.act_window," + str(id)
            replace = rec.get("replace", "") or True
            self.pool.get("ir.model.data").ir_set(
                cr,
                self.uid,
                "action",
                keyword,
                xml_id,
                [src_model],
                value,
                replace=replace,
                isobject=True,
                xml_id=xml_id,
            )