How can I automatically change a helpdeskticket's stage to 'Answered' after we send a reply to the customer and 'To be answered' after we receive a follow up reply from the customer?
Cette question a été signalée
Hello,
You can use an automation rule:
- Model: Message (mail.message)
- Trigger: On create
- Apply on: Related Document Model = helpdesk.ticket
- Action: Execute Code
mt_comment = env.ref('mail.mt_comment', raise_if_not_found=False)
if (
record.model == 'helpdesk.ticket'
and record.res_id
and record.message_type in ('email', 'comment')
and record.subtype_id == mt_comment
):
ticket = env['helpdesk.ticket'].browse(record.res_id).exists()
if ticket:
author = record.author_id
is_internal = any(not u.share and u.active for u in author.user_ids) if author else False
target_stage_name = 'Answered' if is_internal else 'To be answered'
target_stage = env['helpdesk.stage'].search([
('name', '=', target_stage_name),
'|',
('team_ids', '=', False),
('team_ids', 'in', ticket.team_id.ids),
], limit=1)
if target_stage and ticket.stage_id != target_stage:
ticket.with_context(tracking_disable=True).write({
'stage_id': target_stage.id,
})Disclaimer: I tested this solution in a standard Odoo 19.0 database. This server action looks for stages named exactly "Answered" and "To be answered". If your Helpdesk teams use different stage names, you must update those strings in the code. Be sure to configure the "Apply on" filter in the automation rule to avoid performance issues. As always, test the automation in a staging environment before deploying it to production.
Use Automated Actions on helpdesk.ticket.
Set two rules:
When an outgoing message is posted
Trigger: on message creation / update
Check message type or author is internal user
Set ticket stage to Answered
When an incoming customer email/message is received
Check author/partner is customer, not internal user
Set ticket stage to To be answered
In practice, this usually needs a small customization on mail.message, because the ticket stage depends on messages linked through the chatter.
Logic:
if message.model == "helpdesk.ticket":
ticket = env["helpdesk.ticket"].browse(message.res_id)
if message.author_id.user_ids:
ticket.stage_id = answered_stage
else:
ticket.stage_id = to_be_answered_stage
So: possible, but best done with automated action/custom module on mail.message linked to helpdesk.ticket.
@Muhammad The outgoing action only works when when sending a 'simple' message but doesn't change the stage when sending a message through a template. Do you know where could be the problem with that?
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !
Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !
S'inscrire| Publications associées | Réponses | Vues | Activité | |
|---|---|---|---|---|
|
|
0
sept. 20
|
6144 | ||
|
|
0
juin 20
|
4113 | ||
|
|
3
oct. 25
|
4686 | ||
|
|
2
nov. 23
|
6935 | ||
|
|
1
déc. 24
|
3067 |