Skip to content

Commit

Permalink
[PR OCA#465] [IMP] helpdesk_mgmt: Set e-mail channel when creating ti…
Browse files Browse the repository at this point in the history
…cket by fetchmail

Forward port of fcf0a41
  • Loading branch information
eLBati authored and renda-dev committed Apr 23, 2024
1 parent 16b85aa commit 1dbf092
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions helpdesk_mgmt/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ---------------------------------------------------
Expand All @@ -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):
Expand Down

0 comments on commit 1dbf092

Please sign in to comment.