odoo16版本的render变更

今天在整理文件上传功能时,发现

odoo16的ir_ui_view.py中_render方法不见了,引用出错AttributeError: 'ir.ui.view' object has no attribute '_render'

复制代码
    def _render(self, values=None, engine='ir.qweb', minimal_qcontext=False):
        assert isinstance(self.id, int)

        qcontext = dict() if minimal_qcontext else self._prepare_qcontext()
        qcontext.update(values or {})

        return self.env[engine]._render(self.id, qcontext)

    @api.model
    def _prepare_qcontext(self):
        """ Returns the qcontext : rendering context with website specific value (required
            to render website layout template)
        """
        qcontext = dict(
            env=self.env,
            user_id=self.env["res.users"].browse(self.env.user.id),
            res_company=self.env.company.sudo(),
            keep_query=keep_query,
            request=request,  # might be unbound if we're not in an httprequest context
            debug=request.session.debug if request else '',
            test_mode_enabled=bool(config['test_enable'] or config['test_file']),
            json=json_scriptsafe,
            quote_plus=werkzeug.urls.url_quote_plus,
            time=safe_eval.time,
            datetime=safe_eval.datetime,
            relativedelta=relativedelta,
            xmlid=self.sudo().key,
            viewid=self.id,
            to_text=pycompat.to_text,
            image_data_uri=image_data_uri,
            # specific 'math' functions to ease rounding in templates and lessen controller marshmalling
            floor=math.floor,
            ceil=math.ceil,
        )
        return qcontext

仔细一追,变的还不少

复制代码
# 以下四行为与15引
import werkzeug, werkzeug.urls
from odoo.tools.json import scriptsafe as json_scriptsafe
from dateutil.relativedelta import relativedelta
from odoo.tools.image import image_data_uri

AttributeError: 'ir.ui.view' object has no attribute '_render'

复制代码
    # ----------------------------------------------------------
    # Functions
    # ----------------------------------------------------------
    def get_and_update_onbarding_state(self, onboarding_state, steps_states):
        """odoo15有,16版本去除了 Needed to display onboarding animations only one time. """
        old_values = {}
        all_done = True
        for step_state in steps_states:
            old_values[step_state] = self[step_state]
            if self[step_state] == 'just_done':
                self[step_state] = 'done'
            all_done = all_done and self[step_state] == 'done'

        if all_done:
            if self[onboarding_state] == 'not_done':
                # string `onboarding_state` instead of variable name is not an error
                old_values['onboarding_state'] = 'just_done'
            else:
                old_values['onboarding_state'] = 'done'
            self[onboarding_state] = 'done'
        return old_values

以后用到render方法时只用借用新的

复制代码
request.env["ir.qweb"]中的render了
相关推荐
cly12 分钟前
Ansible自动化(十四):Roles(角色)
服务器·自动化·ansible
二哈喇子!2 分钟前
前端HTML、CSS、JS、VUE 汇总
开发语言·前端
小白路过3 分钟前
node-sass和sass兼容性使用
前端·rust·sass
IT_陈寒3 分钟前
Python 3.12 新特性实战:这5个改进让我的开发效率提升40%
前端·人工智能·后端
两个西柚呀5 分钟前
每日前端面试题-防抖和节流
前端
2501_9311624310 分钟前
大疆相机:空中影像新境界
python
阿眠12 分钟前
前端面试题
前端
测试199813 分钟前
Web自动化测试入门
自动化测试·软件测试·python·功能测试·selenium·测试工具·测试用例
Nobody__113 分钟前
解决多台服务器 UID/GID 做对齐后,文件系统元数据未更新的情况
运维·服务器
予枫的编程笔记14 分钟前
【论文解读】DLF:以语言为核心的多模态情感分析新范式 (AAAI 2025)
人工智能·python·算法·机器学习