feat(fusion_helpdesk_central): Owner Contact field + Add-as-Follower button

Adds a one-click 'loop the owner into the chatter' shortcut on the
ticket form — separate from the engagement approval flow, just keeps
the owner in the loop on ongoing communication.

What's new on helpdesk.ticket:

- x_fc_owner_display (computed Char): 'Kris Pathinather <kris@…>',
  read live from fusion.helpdesk.client.key so a change to the owner
  contact reflects immediately on every existing ticket.
- x_fc_owner_email_resolved (computed Char): email-only slice, drives
  view visibility (the field + button only render when an owner is
  configured).
- x_fc_owner_is_follower (computed Boolean): True when a partner with
  the owner email is in message_partner_ids. Swaps the button for a
  green 'Following' badge when the owner is already on the thread.
- action_add_owner_as_follower(): find-or-create the owner partner by
  email and message_subscribe. Idempotent — second call is a no-op,
  no duplicate partner. Raises UserError with a clear message if no
  owner is configured.

View extension on the helpdesk ticket form: injects right after the
existing partner_id ('Customer') field in the customer side group,
so it reads as 'Customer | Owner Contact [Add as Follower]' — same
row, no layout shift when the state flips to 'Following'.

Tests cover the compute display in three states (configured,
no-client-label, no-owner-on-key), the action's three paths
(create-and-subscribe, reuse-existing-partner, idempotent-when-
already-following), and the UserError when nothing is configured.

Smoke-tested live on nexa: ticket with x_fc_client_label='ENTECH'
displays 'Kris Pathinather <kris@enplating.ca>'; first click adds
res.partner #723 to followers and flips owner_is_follower to True;
second click is a no-op.

Bumps fusion_helpdesk_central to 19.0.2.1.0.
This commit is contained in:
gsinghpal
2026-05-27 13:28:18 -04:00
parent 40b3205274
commit 8cc02759b8
4 changed files with 182 additions and 1 deletions

View File

@@ -93,11 +93,63 @@ class HelpdeskTicket(models.Model):
'turnaround per ticket", not "summed wait-time".',
)
# ------------------------------------------------------------------
# Owner-contact display + follower shortcut (read from client_key,
# never stored — single source of truth stays the client_key row).
# ------------------------------------------------------------------
x_fc_owner_display = fields.Char(
string='Owner Contact',
compute='_compute_owner_display',
help='The client deployment\'s decision-maker, pulled live from '
'their fusion.helpdesk.client.key row. Empty when no owner '
'is configured for this client.',
)
x_fc_owner_email_resolved = fields.Char(
compute='_compute_owner_display',
help='Internal helper field — drives view visibility for the '
'Add-as-Follower button. Email-only slice of '
'x_fc_owner_display.',
)
x_fc_owner_is_follower = fields.Boolean(
compute='_compute_owner_is_follower',
help='True when the configured owner is already subscribed to '
'this ticket\'s thread. Used to swap the button for a '
'"following" badge.',
)
# message_post-friendly index for the reminder cron + token resolution.
_engagement_state_idx = models.Index(
'(x_fc_engagement_state, x_fc_engagement_sent_at)'
)
# ------------------------------------------------------------------
@api.depends('x_fc_client_label')
def _compute_owner_display(self):
for rec in self:
email, name = (False, False)
if rec.x_fc_client_label:
email, name = rec._fc_owner_contact()
rec.x_fc_owner_email_resolved = email or ''
if email and name:
rec.x_fc_owner_display = '%s <%s>' % (name, email)
elif email:
rec.x_fc_owner_display = email
else:
rec.x_fc_owner_display = ''
@api.depends('x_fc_client_label', 'message_partner_ids',
'message_partner_ids.email')
def _compute_owner_is_follower(self):
for rec in self:
email = (rec.x_fc_owner_email_resolved or '').strip().lower()
if not email:
rec.x_fc_owner_is_follower = False
continue
rec.x_fc_owner_is_follower = any(
(p.email or '').strip().lower() == email
for p in rec.message_partner_ids
)
# ------------------------------------------------------------------
# Lifecycle
# ------------------------------------------------------------------
@@ -210,6 +262,39 @@ class HelpdeskTicket(models.Model):
'x_fc_ai_summary': ai_summary or '',
})
def action_add_owner_as_follower(self):
"""Find-or-create the owner partner and subscribe them as a follower
on this ticket. One-click "loop the owner in" — different from the
engagement flow which gates on a magic-link decision; this is just
"they should be on the thread".
Idempotent: if the owner is already following, no-op. Uses the same
find-or-create-by-email pattern as the engagement portal so the
owner partner is consistent between flows.
"""
self.ensure_one()
email, name = self._fc_owner_contact()
if not email:
raise UserError(_(
'No owner contact configured for client "%s". Ask the client '
'to set it in Settings → Fusion Helpdesk → Owner Approval.'
) % (self.x_fc_client_label or '(unset)',))
norm = email_normalize(email) or email.strip().lower()
Partner = self.env['res.partner'].sudo()
partner = Partner.search(
[('email', '=ilike', norm)], order='id asc', limit=1,
)
if not partner:
partner = Partner.create({
'name': (name or '').strip() or norm.split('@')[0].title(),
'email': norm,
})
if partner.id not in self.message_partner_ids.ids:
self.message_subscribe(partner_ids=[partner.id])
# Force the compute to refresh on the next form render.
self.invalidate_recordset(['x_fc_owner_is_follower'])
return True
def action_open_engagement_wizard(self):
"""Form-button handler: open the wizard targeting this single ticket.