当前位置: 首页> 财经> 金融 > odoo16版本的render变更

odoo16版本的render变更

时间:2025/7/11 14:36:21来源:https://blog.csdn.net/fqfq123456/article/details/139153154 浏览次数:0次

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

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.modeldef _prepare_qcontext(self):""" Returns the qcontext : rendering context with website specific value (requiredto 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 contextdebug=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 marshmallingfloor=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 = Truefor 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 errorold_values['onboarding_state'] = 'just_done'else:old_values['onboarding_state'] = 'done'self[onboarding_state] = 'done'return old_values

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

request.env["ir.qweb"]中的render了
关键字:odoo16版本的render变更

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: