I have call message_post
function from a wizard TransientModel. and use subtype of hr_recruitment.mt_job_applicant_hired
and also add depended module in manifest.json but its showing error
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")
How to resolve it in odoo 16?
The error message is telling you what to do. If it's not enough for clarification i advise to look into the code, where you will find the follwing.
# 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):
First thing you will see: there is no subtype
anymore. Instead Odoo developers have added a check on kwargs
which will give you the error message:
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."))
Instead of subtype
you have subtype_id
or subtype_xmlid
as new parameters. So your code have to be changed to:
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"
)