From 15470426eb26bbc1329f8b339c46c2291814b1e9 Mon Sep 17 00:00:00 2001 From: gsinghpal Date: Wed, 27 May 2026 13:21:08 -0400 Subject: [PATCH] refactor(fusion_helpdesk): owner contact is a res.partner, not two text fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Smaller UX simplification on the client side: the owner is already a contact in entech's address book, so picking one is faster + safer than re-typing their email and name (and avoids typos creeping into the approval-email To: header). What changed: - Entech settings: drop fhd_owner_email + fhd_owner_name char fields; add fhd_owner_partner_id Many2one to res.partner exposed in the same "Owner Approval" block as a single partner selector. Quick-create + create-and-edit kept enabled so admins can spin up a new partner inline if the owner isn't already in the system. - controllers/main.py::_read_config: derives owner_email + owner_name from the selected partner via the new _resolve_owner_contact helper. Missing / dangling partner id → blank email + name → central simply won't see the keys and the Engage button stays disabled (correct "not configured" behaviour). - Nexa side: ZERO changes. Still receives owner_email + owner_name strings on the ticket payload, still upserts client_key.owner_email/ name. The partner abstraction stops at the entech boundary. - migrations/19.0.2.1.0/post-migration.py auto-resolves the legacy fusion_helpdesk.owner_email ICP value to an existing res.partner (lowest-id match on lowercased email), writes the new fusion_helpdesk.owner_partner_id key, and deletes the obsolete owner_email + owner_name ICP rows so a future reader doesn't trip over stale config. Verified live on entech: kris@enplating.ca → res.partner #2308 ("Kris Pathinather"), legacy keys purged, controller._resolve_owner_contact returns the expected (email, name). The piggyback payload is unchanged so existing client_key sync continues to work without a central redeploy. Bumps fusion_helpdesk to 19.0.2.1.0. fusion_helpdesk_central stays at 19.0.2.0.0 (no central-side changes required). --- fusion_helpdesk/__manifest__.py | 2 +- fusion_helpdesk/controllers/main.py | 29 +++++-- .../migrations/19.0.2.1.0/post-migration.py | 81 +++++++++++++++++++ fusion_helpdesk/models/res_config_settings.py | 33 ++++---- .../views/res_config_settings_views.xml | 15 ++-- 5 files changed, 127 insertions(+), 33 deletions(-) create mode 100644 fusion_helpdesk/migrations/19.0.2.1.0/post-migration.py diff --git a/fusion_helpdesk/__manifest__.py b/fusion_helpdesk/__manifest__.py index bb02ce30..59e410af 100644 --- a/fusion_helpdesk/__manifest__.py +++ b/fusion_helpdesk/__manifest__.py @@ -3,7 +3,7 @@ # License OPL-1 (Odoo Proprietary License v1.0) { 'name': 'Fusion Helpdesk Reporter', - 'version': '19.0.2.0.0', + 'version': '19.0.2.1.0', 'category': 'Productivity', 'summary': 'One-click in-app bug reporting & feature requesting — ' 'auto-creates a helpdesk.ticket on a central Odoo Helpdesk.', diff --git a/fusion_helpdesk/controllers/main.py b/fusion_helpdesk/controllers/main.py index 24efe2e8..60529a2b 100644 --- a/fusion_helpdesk/controllers/main.py +++ b/fusion_helpdesk/controllers/main.py @@ -228,12 +228,29 @@ class FusionHelpdeskController(http.Controller): 'client_label': ( ICP.get_param('fusion_helpdesk.client_label') or '' ).strip(), - 'owner_email': ( - ICP.get_param('fusion_helpdesk.owner_email') or '' - ).strip(), - 'owner_name': ( - ICP.get_param('fusion_helpdesk.owner_name') or '' - ).strip(), + # Owner contact is configured as a res.partner reference; we + # derive email + name on read so the rest of the submit path + # doesn't have to know about the partner. Missing / dangling + # partner id → blank email + name → central simply won't see + # the keys and the Engage button stays disabled (which is the + # correct "not configured" behaviour). + **self._resolve_owner_contact(ICP), + } + + def _resolve_owner_contact(self, ICP): + raw = (ICP.get_param('fusion_helpdesk.owner_partner_id') or '').strip() + try: + partner_id = int(raw) + except (TypeError, ValueError): + return {'owner_email': '', 'owner_name': ''} + if partner_id <= 0: + return {'owner_email': '', 'owner_name': ''} + partner = request.env['res.partner'].sudo().browse(partner_id).exists() + if not partner: + return {'owner_email': '', 'owner_name': ''} + return { + 'owner_email': (partner.email or '').strip(), + 'owner_name': (partner.name or '').strip(), } def _authenticate(self, cfg): diff --git a/fusion_helpdesk/migrations/19.0.2.1.0/post-migration.py b/fusion_helpdesk/migrations/19.0.2.1.0/post-migration.py new file mode 100644 index 00000000..9e830937 --- /dev/null +++ b/fusion_helpdesk/migrations/19.0.2.1.0/post-migration.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Nexa Systems Inc. +# License OPL-1 +"""Migrate owner contact settings from email/name strings to a partner ref. + +Pre-19.0.2.1.0, fusion_helpdesk stored two ICP keys: + fusion_helpdesk.owner_email + fusion_helpdesk.owner_name + +19.0.2.1.0 replaces them with a single Many2one to res.partner exposed +as a partner-id string in: + fusion_helpdesk.owner_partner_id + +This script auto-resolves the email to an existing res.partner (best +effort — exact case-insensitive match), so admins don't have to re-pick +the owner contact after the upgrade. The old keys are then deleted to +avoid stale-config confusion. If no matching partner is found, the +owner_partner_id is left blank — admin reconfigures via Settings. +""" +import logging + +_logger = logging.getLogger(__name__) + + +def migrate(cr, version): + cr.execute( + "SELECT value FROM ir_config_parameter " + "WHERE key = 'fusion_helpdesk.owner_email'" + ) + row = cr.fetchone() + email = (row[0] or '').strip().lower() if row else '' + if not email: + _logger.info( + 'fusion_helpdesk: no legacy owner_email to migrate, skipping.' + ) + _purge_legacy_keys(cr) + return + # Exact (lowercased) match on res_partner.email. The legacy ICP value + # was free text — could be uppercase, have trailing spaces, etc. — + # so normalise both sides. If multiple partners share the email, + # pick the oldest (lowest id) — same convention used elsewhere in + # the customer-followup partner backfill. + cr.execute( + "SELECT id, name FROM res_partner " + "WHERE lower(email) = %s " + "ORDER BY id ASC LIMIT 1", + (email,), + ) + match = cr.fetchone() + if not match: + _logger.warning( + 'fusion_helpdesk: legacy owner_email %s does not match any ' + 'res.partner — owner_partner_id left blank, admin must ' + 're-pick under Settings → Fusion Helpdesk → Owner Approval.', + email, + ) + _purge_legacy_keys(cr) + return + partner_id, partner_name = match + cr.execute( + "INSERT INTO ir_config_parameter (key, value) " + "VALUES ('fusion_helpdesk.owner_partner_id', %s) " + "ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value", + (str(partner_id),), + ) + _logger.info( + 'fusion_helpdesk: migrated owner_email "%s" → res.partner #%s ' + '("%s"). Legacy keys purged.', email, partner_id, partner_name, + ) + _purge_legacy_keys(cr) + + +def _purge_legacy_keys(cr): + """Delete the obsolete owner_email / owner_name ICP rows so a future + reader doesn't trip over stale config. Safe — the new partner_id key + is the only source of truth after this migration.""" + cr.execute( + "DELETE FROM ir_config_parameter " + "WHERE key IN ('fusion_helpdesk.owner_email', " + " 'fusion_helpdesk.owner_name')" + ) diff --git a/fusion_helpdesk/models/res_config_settings.py b/fusion_helpdesk/models/res_config_settings.py index 58a5a92f..0b20eb6a 100644 --- a/fusion_helpdesk/models/res_config_settings.py +++ b/fusion_helpdesk/models/res_config_settings.py @@ -50,22 +50,21 @@ class ResConfigSettings(models.TransientModel): 'can tell which client deployment a ticket came from. ' 'e.g. "ENTECH" → "[ENTECH] My subject"', ) - # Owner contact for the central engagement / approval flow. Optional — - # leaving these blank disables the "Request Owner Approval" button on - # the central side for this client. Both values piggyback on every - # ticket submission (see controllers/main.py::submit) so central always - # has the latest contact without a dedicated sync endpoint. - fhd_owner_email = fields.Char( - string='Owner Email', - config_parameter='fusion_helpdesk.owner_email', - help='Email of the real decision-maker at your company — the ' - 'person who can approve feature requests or bug-fix scope. ' - 'Used when central support hits a ticket that needs sign-off. ' + # Owner contact for the central engagement / approval flow. Picked + # from the existing res.partner — the owner is already a contact in + # the system, no point retyping their email and name. Email + name + # are derived from the partner at submit-time and piggybacked on + # every ticket payload (see controllers/main.py::submit) so central + # always has the latest contact without a dedicated sync endpoint. + # Leaving the partner blank disables the "Request Owner Approval" + # button on the central side for this client. + fhd_owner_partner_id = fields.Many2one( + 'res.partner', + string='Owner Contact', + config_parameter='fusion_helpdesk.owner_partner_id', + help='The real decision-maker at your company — the person who ' + 'can approve feature requests or bug-fix scope. Used when ' + 'central support hits a ticket that needs sign-off. ' + 'Email and name are taken from the selected contact. ' 'Leave blank if your deployment doesn\'t require approvals.', ) - fhd_owner_name = fields.Char( - string='Owner Name', - config_parameter='fusion_helpdesk.owner_name', - help='Display name for the owner — shown in the approval email ' - 'greeting and in the chatter attribution after they decide.', - ) diff --git a/fusion_helpdesk/views/res_config_settings_views.xml b/fusion_helpdesk/views/res_config_settings_views.xml index fd5ddbd2..b9a4d5b3 100644 --- a/fusion_helpdesk/views/res_config_settings_views.xml +++ b/fusion_helpdesk/views/res_config_settings_views.xml @@ -45,15 +45,12 @@ - - - - - + +