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了
相关推荐
v_for_van4 分钟前
C语言__attribute__
服务器·c语言·开发语言·mcu·嵌入式·嵌入式实时数据库
单线程1213813 分钟前
从案例分析 Vue3 Tokenizer 源码
前端·javascript·vue.js
明月_清风15 分钟前
🖥️ Electron 三进程 Host 实战:从架构设计到生产落地的完整指南
前端·electron·客户端
工业一体机老司机27 分钟前
Python实现工业一体机Modbus-TCP通信-从协议解析到多设备轮询实战
开发语言·python·tcp/ip
GIS数据转换器29 分钟前
智慧林草“一张图“平台
java·大数据·服务器·前端·javascript·数据库·人工智能
2401_8858850433 分钟前
国际语音php接口代码示例:PHP使用cURL快速调用语音发送API
android·开发语言·前端·人工智能·python·php·语音识别
leoZ23133 分钟前
AI+前端提效-08 AI自动化文档:前端组件、接口、项目文档自动生成
前端·人工智能·深度学习·神经网络·目标检测·自然语言处理·自动化
智恒百亿36 分钟前
5090八卡服务器整机技术解析与部署常见问题(FAQ)
运维·服务器
lilian23338 分钟前
HarmonyOS 7 新特性(五)|ContainerReader 容器断点与自适应布局
前端·华为·harmonyos
萌动的小火苗41 分钟前
Linux进程线程面试题【无答案】
linux·运维·服务器·c语言·开发语言