The cross-instance sync silently drops tasks when x_fc_tech_sync_id is missing on the technician, and silently collapses duplicates via dict comprehension. Both make sync break in ways that are invisible until someone notices a missing task on the other instance. - _get_remote_tech_map / _get_local_syncid_to_uid: warn on duplicates - _push_tasks_to_remote: info-log when a task is skipped because the tech has no sync_id or no remote counterpart - res.users onchange: warn in the form when entering a sync_id that is already used by another active field staff Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright 2024-2026 Nexa Systems Inc.
|
|
# License OPL-1 (Odoo Proprietary License v1.0)
|
|
|
|
from odoo import models, fields, api
|
|
|
|
|
|
class ResUsers(models.Model):
|
|
_inherit = 'res.users'
|
|
|
|
x_fc_is_field_staff = fields.Boolean(
|
|
string='Field Staff',
|
|
default=False,
|
|
help='Check this to show the user in the Technician/Field Staff dropdown when scheduling tasks.',
|
|
)
|
|
x_fc_start_address = fields.Char(
|
|
related='partner_id.x_fc_start_address',
|
|
readonly=False,
|
|
string='Start Location',
|
|
)
|
|
x_fc_tech_sync_id = fields.Char(
|
|
string='Tech Sync ID',
|
|
help='Shared identifier for this technician across Odoo instances. '
|
|
'Must be the same value on all instances for the same person.',
|
|
copy=False,
|
|
)
|
|
|
|
@api.onchange('x_fc_tech_sync_id')
|
|
def _onchange_x_fc_tech_sync_id_dup_warning(self):
|
|
if not self.x_fc_tech_sync_id:
|
|
return
|
|
dup = self.env['res.users'].sudo().search([
|
|
('id', '!=', self._origin.id or self.id),
|
|
('x_fc_tech_sync_id', '=', self.x_fc_tech_sync_id),
|
|
('x_fc_is_field_staff', '=', True),
|
|
('active', '=', True),
|
|
], limit=1)
|
|
if dup:
|
|
return {
|
|
'warning': {
|
|
'title': "Duplicate Tech Sync ID",
|
|
'message': (
|
|
f"Tech Sync ID {self.x_fc_tech_sync_id!r} is already used "
|
|
f"by {dup.login} ({dup.partner_id.name}). Cross-instance "
|
|
f"task sync only routes to ONE user per sync ID — "
|
|
f"pick a unique value or only one tech's tasks will sync."
|
|
),
|
|
}
|
|
}
|