# -*- coding: utf-8 -*- # Copyright 2024-2026 Nexa Systems Inc. # License OPL-1 (Odoo Proprietary License v1.0) from odoo import fields, models PREFERRED_WINDOW = [ ('morning', 'Morning (9 AM - 12 PM)'), ('afternoon', 'Afternoon (12 PM - 5 PM)'), ('evening', 'Evening (after 5 PM)'), ('any', 'Any Time'), ] class ResPartner(models.Model): _inherit = 'res.partner' # ------------------------------------------------------------------ # SERVICE PREFERENCES (P1 - shown in client history sidebar) # ------------------------------------------------------------------ x_fc_preferred_tech_id = fields.Many2one( 'res.users', string='Preferred Technician', domain="[('x_fc_is_field_staff', '=', True)]", help='If set, this technician is suggested first on dispatch.', ) x_fc_preferred_window = fields.Selection( PREFERRED_WINDOW, string='Preferred Visit Window', default='any', ) x_fc_access_notes = fields.Text( string='Access Notes', help='Free-form notes for technicians arriving at this address: ' 'gate code, dog warning, where to park, side door entry, etc.', ) # ------------------------------------------------------------------ # CLIENT HISTORY SIDEBAR (C2 - pulled lazily on demand) # ------------------------------------------------------------------ x_fc_repair_count = fields.Integer( compute='_compute_x_fc_repair_count', string='Repairs Count', compute_sudo=True, help='Lightweight count of repair orders for this partner. Heavier history ' 'data is fetched lazily by the wizard / portal sidebar via RPC.', ) def _compute_x_fc_repair_count(self): # Non-stored compute - safe to omit @api.depends. if not self.ids: for partner in self: partner.x_fc_repair_count = 0 return Repair = self.env['repair.order'].sudo() data = Repair._read_group( [('partner_id', 'in', self.ids)], ['partner_id'], ['__count'], ) counts = {row[0].id: row[1] for row in data} for partner in self: partner.x_fc_repair_count = counts.get(partner.id, 0)