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

@@ -275,6 +275,74 @@ class TestEngagementWizard(TestEngagementBase):
).create({})
@tagged('post_install', '-at_install', 'fusion_helpdesk_central')
class TestOwnerAsFollower(TestEngagementBase):
"""The one-click 'add owner as follower' button — independent of the
engagement flow, just loops the owner into the chatter."""
def test_owner_display_renders_name_and_email(self):
t = self._make_ticket()
self.assertEqual(
t.x_fc_owner_display, 'Test Owner <owner@testclient.com>',
)
self.assertEqual(t.x_fc_owner_email_resolved, 'owner@testclient.com')
self.assertFalse(t.x_fc_owner_is_follower)
def test_owner_display_blank_when_no_client_label(self):
t = self._make_ticket(x_fc_client_label=False)
self.assertFalse(t.x_fc_owner_display)
self.assertFalse(t.x_fc_owner_email_resolved)
def test_owner_display_blank_when_client_key_has_no_owner(self):
self.client_key.write({'owner_email': False, 'owner_name': False})
t = self._make_ticket()
self.assertFalse(t.x_fc_owner_display)
def test_action_creates_partner_and_subscribes(self):
t = self._make_ticket()
# Pre-condition: no res.partner with that email exists.
existing = self.env['res.partner'].search(
[('email', '=ilike', 'owner@testclient.com')])
existing.unlink()
t.action_add_owner_as_follower()
# Partner created
partner = self.env['res.partner'].search(
[('email', '=ilike', 'owner@testclient.com')], limit=1)
self.assertTrue(partner)
self.assertEqual(partner.email, 'owner@testclient.com')
# And subscribed
self.assertIn(partner.id, t.message_partner_ids.ids)
self.assertTrue(t.x_fc_owner_is_follower)
def test_action_reuses_existing_partner(self):
t = self._make_ticket()
existing = self.env['res.partner'].create({
'name': 'Pre-existing Owner',
'email': 'owner@testclient.com',
})
t.action_add_owner_as_follower()
# No duplicate partner created
count = self.env['res.partner'].search_count(
[('email', '=ilike', 'owner@testclient.com')])
self.assertEqual(count, 1)
self.assertIn(existing.id, t.message_partner_ids.ids)
def test_action_is_idempotent_when_already_following(self):
t = self._make_ticket()
t.action_add_owner_as_follower()
followers_before = t.message_partner_ids.ids
t.action_add_owner_as_follower()
followers_after = t.message_partner_ids.ids
# Second call must not duplicate or re-trigger the subscribe
self.assertEqual(followers_before, followers_after)
def test_action_raises_when_no_owner_configured(self):
self.client_key.write({'owner_email': False})
t = self._make_ticket()
with self.assertRaises(UserError):
t.action_add_owner_as_follower()
@tagged('post_install', '-at_install', 'fusion_helpdesk_central')
class TestReminderCron(TestEngagementBase):