我从向导 TransientModel 中调用了
message_post
函数。并使用hr_recruitment.mt_job_applicant_hired
的子类型,并在manifest.json中添加依赖的模块,但它显示错误
ValueError: message_post does not support subtype parameter anymore. Please give a valid subtype_id or subtype_xmlid value instead.
applicant.job_id.message_post(
body=_(
'New Employee %s Hired') % applicant.partner_name if applicant.partner_name else applicant.name,
subtype="hr_recruitment.mt_job_applicant_hired")
如何在odoo 16中解决这个问题?
错误消息告诉您该怎么做。如果这还不足以说明问题,我建议您查看代码,您将在其中找到以下内容。
# the definition of the method with type annotation
@api.returns('mail.message', lambda value: value.id)
def message_post(self, *,
body='', subject=None, message_type='notification',
email_from=None, author_id=None, parent_id=False,
subtype_xmlid=None, subtype_id=False, partner_ids=None,
attachments=None, attachment_ids=None,
**kwargs):
您首先会看到:不再有
subtype
了。相反,Odoo 开发人员添加了对 kwargs
的检查,这将为您提供错误消息:
if 'subtype' in kwargs:
raise ValueError(_("message_post does not support subtype parameter anymore. Please give a valid subtype_id or subtype_xmlid value instead."))
您使用
subtype
或 subtype_id
作为新参数,而不是 subtype_xmlid
。所以你的代码必须更改为:
applicant.job_id.message_post(
body=_(
'New Employee %s Hired') % applicant.partner_name if applicant.partner_name else applicant.name,
subtype_xmlid="hr_recruitment.mt_job_applicant_hired"
)