Odoo消息中插入超链接 - xiaohao0576/odoo-doc GitHub Wiki
在Odoo的消息中,可以插入超链接,比如每个出库单的备注消息里面,都可以连接到销售订单,用鼠标点击就能查看。
其实这个超链接是使用_get_html_link
方法生成的,这个方法在BaseModel
中定义,所以任何model都可以调用这个方法
def _get_html_link(self, title=None):
"""Generate the record html reference for chatter use.
:param str title: optional reference title, the record display_name
is used if not provided. The title/display_name will be escaped.
:returns: generated html reference,
in the format <a href data-oe-model="..." data-oe-id="...">title</a>
:rtype: str
"""
self.ensure_one()
return Markup("<a href=# data-oe-model='%s' data-oe-id='%s'>%s</a>") % (
self._name, self.id, title or self.display_name)
Markup
类是markupsafe
这个第三方库提供的类
在备注消息中使用链接
link = record._get_html_link() #可选参数 title
record.message_post('原单据链接:' + link) # 使用+号运算符,不要使用join或者f-string