From 1dbf0926d6fba29d37f03b32e6a72d527af98160 Mon Sep 17 00:00:00 2001 From: eLBati Date: Wed, 8 Jul 2020 09:18:00 +0200 Subject: [PATCH] [PR #465] [IMP] helpdesk_mgmt: Set e-mail channel when creating ticket by fetchmail Forward port of fcf0a41bbf4099d7926cf542402d23970a3dcf39 --- helpdesk_mgmt/models/helpdesk_ticket.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/helpdesk_mgmt/models/helpdesk_ticket.py b/helpdesk_mgmt/models/helpdesk_ticket.py index ed1ba13e58..6b7caa8439 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket.py +++ b/helpdesk_mgmt/models/helpdesk_ticket.py @@ -127,6 +127,12 @@ def _onchange_partner_id(self): self.partner_email = self.partner_id.email self.partner_lang = self.partner_id.lang + def _get_default_email_channel(self): + return self.env.ref( + "helpdesk_mgmt.helpdesk_ticket_channel_email", + raise_if_not_found=False, + ) + # --------------------------------------------------- # CRUD # --------------------------------------------------- @@ -143,6 +149,14 @@ def create(self, vals_list): vals["team_id"] = self._prepare_team_id(vals) if vals.get("user_id") and not vals.get("assigned_date"): vals["assigned_date"] = fields.Datetime.now() + # Automatically set default e-mail channel when created from the + # fetchmail cron task + if self.env.context.get("fetchmail_cron_running") and not vals.get( + "channel_id" + ): + channel_email_id = self._get_default_email_channel() + if channel_email_id: + vals["channel_id"] = channel_email_id.id return super().create(vals_list) def copy(self, default=None):