[18.0][FIX] helpdesk_ticket_partner_response: Error on New Ticket - #964
CristianoMafraJunior wants to merge 1 commit into
Conversation
|
Hi @peluko00, |
|
The issue is mentioning a problem in the previous line: ticket = self.env["helpdesk.ticket"].sudo().browse(int(ticket_id))
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'so this is not solving that problem, as the line remains untouched. |
5ebf458 to
b29c8f6
Compare
The email routing can send
|
| ) | ||
| # When the email creates the ticket/thread, Odoo can route the message | ||
| # with a missing (None) id. In that case we must not crash. | ||
| if ticket_id is None: |
| ticket_id_int = int(ticket_id) | ||
| except (TypeError, ValueError): | ||
| return | ||
|
|
There was a problem hiding this comment.
Don't add empty lines inside the method.
|
There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |

Fixes #963
Summary
Fix stage auto-update not working when tickets are received via fetchmail,
and prevent a crash when a new email creates a ticket for the first time.
Problems Fixed
1.
TypeErroron new incoming emailsWhen a brand new email arrived with no existing ticket,
routes[0][1](the ticket ID) was
None. The code calledint(None)without any guard,crashing with:
This happened every time a customer sent a new support request by email,
making it impossible to receive tickets from the inbox.
2. Stage never changed when email arrived via fetchmail
The original code identified the sender by looking up the route user
(
routes[0][3]) and comparing their partner with the ticket customer:When emails are processed via fetchmail, that user is always OdooBot or
the cron user, never the actual customer. So the partner comparison always
failed and the stage update never happened — the feature was silently broken
for all email-based workflows.
3.
browse()result not validated against the databasebrowse(id)in Odoo always returns a non-empty recordset even if the recorddoes not exist in the database. A bare
if ticket:check would always beTruefor any non-zero ID.ticket.exists()was added to perform theactual database check.
Changes
models/mail_thread.pyif ticket_id:guard beforebrowse()to safely skip new incomingemails with no existing ticket
message_dictis now passed tochange_status_ticket_from_portalso thereal email sender (
author_id) can be read from the parsed message headersmessage_dict.get("author_id")tocorrectly identify the customer regardless of how the email was delivered
(portal, fetchmail, etc.)
if ticket:withticket.exists()for a proper databaseexistence check
Before:
After:
tests/test_partner_response.pymessage_process()helper now accepts an optionalemail_fromparameterto allow simulating different senders in tests
test_no_change_stage_non_customer_through_mail: verifies that anemail from a non-customer (e.g. internal user) does not trigger a stage
change — this is the key behavioral test for the
author_idfixtest_new_ticket_via_email_no_crash: reproduces theTypeErrorscenario (no
thread_id) and ensures no exception is raisedtest_ticket_without_team_no_crash: ensures a ticket with no teamassigned does not crash on an incoming email reply; stage must remain
unchanged since there is no autoupdate configuration
Test Coverage
test_change_stage_customer_answeredtest_no_change_stage_customer_answeredtest_change_stage_deactivatedtest_change_stage_customer_answered_through_mailtest_no_change_stage_customer_answered_through_mailtest_change_stage_deactivated_through_mailtest_no_change_stage_non_customer_through_mailtest_new_ticket_via_email_no_crashtest_ticket_without_team_no_crashcc @agent-z28