feat(fusion_repairs): Phase 1 MVP - backend intake wizard + core models
Scaffolds the fusion_repairs module that extends Odoo 19 repair.order with a guided medical-equipment intake workflow. Models - fusion.repair.product.category (8 medical equipment categories seeded) - fusion.repair.intake.template / .question / .answer (7 templates, 32 questions seeded across hospital bed, stairlift, porch lift, wheelchair, walker/rollator, mattress) - fusion.repair.intake.service (AbstractModel) - single entry point used by backend wizard, sales rep portal, and public client portal so all three surfaces produce identical outcomes - repair.order extensions (x_fc_intake_*, x_fc_third_party_equipment, x_fc_photo_ids, x_fc_urgency, x_fc_estimated/actual_cost, AI summary) - fusion.technician.task back-link (x_fc_repair_order_id) - res.partner service preferences (preferred tech, time window, access notes) - res.users repair extensions (skills, cost rate, on-call rotation fields) - res.config.settings for variance thresholds, portal URL, rate limit UI - Backend intake wizard with multi-equipment loop, third-party flag, photos - repair.order form: Intake tab, Photos, Pricing tab, AI tab, smart buttons (technician tasks, intake answers, original SO) - Kanban + list view urgency badges - Fusion Repairs app menu (New Service Call, Repair Orders, Config) Activities & Email - 4 follow-up activity types (CS callback, tech dispatch, visit follow-up, manager review) with urgency-tiered deadlines - 2 mail templates (client confirmation + office notification) with the same dark/light-safe styling as fusion_claims ADP templates Security - New res.groups.privilege + 3 groups (User, Dispatcher, Manager) - Reuses fusion_tasks.group_field_technician (do NOT recreate) - Reuses fusion_authorizer_portal.group_sales_rep_portal - Multi-company global rule + technician scoping rule on repair.order Verified end-to-end on local westin-v19 dev DB via odoo-shell - creates multiple repairs in one session, auto-creates dispatch task for urgent, attaches 4 activity types correctly per urgency tier and third-party flag. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
281
fusion_repairs/models/repair_order.py
Normal file
281
fusion_repairs/models/repair_order.py
Normal file
@@ -0,0 +1,281 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2024-2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
INTAKE_SOURCES = [
|
||||
('backend_wizard', 'Backend Wizard (CS)'),
|
||||
('sales_rep_portal', 'Sales Rep Portal'),
|
||||
('client_portal', 'Client Self-Service'),
|
||||
('manual', 'Manual / Other'),
|
||||
]
|
||||
|
||||
URGENCY_LEVELS = [
|
||||
('normal', 'Normal'),
|
||||
('urgent', 'Urgent'),
|
||||
('safety', 'Safety Issue'),
|
||||
]
|
||||
|
||||
|
||||
class RepairOrder(models.Model):
|
||||
"""Extend Odoo Repairs with intake context, dispatch link, warranty
|
||||
determination, and pricing variance tracking for Fusion Repairs."""
|
||||
|
||||
_inherit = 'repair.order'
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# INTAKE METADATA
|
||||
# ------------------------------------------------------------------
|
||||
x_fc_intake_source = fields.Selection(
|
||||
INTAKE_SOURCES,
|
||||
string='Intake Source',
|
||||
default='manual',
|
||||
tracking=True,
|
||||
help='Which intake surface created this repair (backend CS wizard, '
|
||||
'sales rep portal, public client portal, or manual entry).',
|
||||
)
|
||||
x_fc_intake_user_id = fields.Many2one(
|
||||
'res.users',
|
||||
string='Intake By',
|
||||
tracking=True,
|
||||
index=True,
|
||||
help='User who took the call / submitted the intake. For client portal, '
|
||||
'this is the OdooBot or admin user.',
|
||||
)
|
||||
x_fc_intake_session_id = fields.Char(
|
||||
string='Intake Session',
|
||||
index=True,
|
||||
copy=False,
|
||||
help='Reference shared by multiple repair orders created during the same call.',
|
||||
)
|
||||
x_fc_intake_template_id = fields.Many2one(
|
||||
'fusion.repair.intake.template',
|
||||
string='Intake Template',
|
||||
help='Question template used during intake.',
|
||||
)
|
||||
x_fc_intake_answer_ids = fields.One2many(
|
||||
'fusion.repair.intake.answer',
|
||||
'repair_id',
|
||||
string='Intake Answers',
|
||||
)
|
||||
x_fc_intake_answer_count = fields.Integer(
|
||||
compute='_compute_intake_answer_count',
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# EQUIPMENT / WARRANTY
|
||||
# ------------------------------------------------------------------
|
||||
x_fc_repair_category_id = fields.Many2one(
|
||||
'fusion.repair.product.category',
|
||||
string='Equipment Category',
|
||||
tracking=True,
|
||||
index=True,
|
||||
help='Medical equipment category - drives intake template and tech skills filter.',
|
||||
)
|
||||
x_fc_third_party_equipment = fields.Boolean(
|
||||
string='Third-Party Equipment',
|
||||
tracking=True,
|
||||
help='True if the equipment was not sold by us. Forces under_warranty=False '
|
||||
'and typically triggers a service call-out fee.',
|
||||
)
|
||||
x_fc_original_sale_order_id = fields.Many2one(
|
||||
'sale.order',
|
||||
string='Original Purchase SO',
|
||||
tracking=True,
|
||||
index=True,
|
||||
help='Sale order through which the customer originally purchased this unit. '
|
||||
'Auto-matched on intake by partner + lot/serial.',
|
||||
)
|
||||
x_fc_warranty_override_reason = fields.Char(
|
||||
string='Warranty Override Reason',
|
||||
help='Required when CS overrides the auto-detected warranty status.',
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# TRIAGE / URGENCY
|
||||
# ------------------------------------------------------------------
|
||||
x_fc_urgency = fields.Selection(
|
||||
URGENCY_LEVELS,
|
||||
string='Urgency',
|
||||
default='normal',
|
||||
tracking=True,
|
||||
index=True,
|
||||
)
|
||||
x_fc_issue_category = fields.Char(
|
||||
string='Issue Category',
|
||||
help='Symptom classification (e.g. "battery", "motor", "remote"). Used by '
|
||||
'service catalogue matcher and AI prompt context.',
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# PHOTOS
|
||||
# ------------------------------------------------------------------
|
||||
x_fc_photo_ids = fields.Many2many(
|
||||
'ir.attachment',
|
||||
'fusion_repair_order_photo_rel',
|
||||
'repair_id',
|
||||
'attachment_id',
|
||||
string='Intake Photos / Videos',
|
||||
help='Photos and videos uploaded during intake.',
|
||||
)
|
||||
x_fc_photo_count = fields.Integer(
|
||||
compute='_compute_photo_count',
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# PRICING (estimate vs actual - Phase 2 reconciliation)
|
||||
# ------------------------------------------------------------------
|
||||
x_fc_estimated_duration = fields.Float(
|
||||
string='Estimated Duration (h)',
|
||||
help='Estimated visit duration from service catalogue, used to size technician slot.',
|
||||
)
|
||||
x_fc_estimated_cost = fields.Monetary(
|
||||
string='Estimated Cost',
|
||||
currency_field='company_currency_id',
|
||||
help='Estimated total from catalogue match at intake (pre-visit).',
|
||||
)
|
||||
x_fc_actual_cost = fields.Monetary(
|
||||
string='Actual Cost',
|
||||
currency_field='company_currency_id',
|
||||
help='Actual total recorded from the visit report (post-visit).',
|
||||
)
|
||||
x_fc_cost_variance_pct = fields.Float(
|
||||
string='Cost Variance %',
|
||||
compute='_compute_cost_variance',
|
||||
store=True,
|
||||
help='(actual - estimated) / estimated * 100',
|
||||
)
|
||||
x_fc_requires_requote = fields.Boolean(
|
||||
string='Requires Re-Quote',
|
||||
help='Set when actual cost exceeds estimate beyond the configured threshold; '
|
||||
'blocks automatic invoicing until manager approves or client re-confirms.',
|
||||
)
|
||||
|
||||
company_currency_id = fields.Many2one(
|
||||
'res.currency',
|
||||
related='company_id.currency_id',
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# FIELD SERVICE LINK
|
||||
# ------------------------------------------------------------------
|
||||
x_fc_technician_task_ids = fields.One2many(
|
||||
'fusion.technician.task',
|
||||
'x_fc_repair_order_id',
|
||||
string='Technician Tasks',
|
||||
)
|
||||
x_fc_technician_task_count = fields.Integer(
|
||||
compute='_compute_technician_task_count',
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# AI SUMMARY (Phase 2)
|
||||
# ------------------------------------------------------------------
|
||||
x_fc_ai_summary = fields.Text(
|
||||
string='AI Pre-Visit Brief',
|
||||
help='AI-generated short brief for the technician based on intake answers. '
|
||||
'Optional - never blocks intake submit.',
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# COMPUTES
|
||||
# ------------------------------------------------------------------
|
||||
@api.depends('x_fc_intake_answer_ids')
|
||||
def _compute_intake_answer_count(self):
|
||||
for repair in self:
|
||||
repair.x_fc_intake_answer_count = len(repair.x_fc_intake_answer_ids)
|
||||
|
||||
@api.depends('x_fc_photo_ids')
|
||||
def _compute_photo_count(self):
|
||||
for repair in self:
|
||||
repair.x_fc_photo_count = len(repair.x_fc_photo_ids)
|
||||
|
||||
@api.depends('x_fc_technician_task_ids')
|
||||
def _compute_technician_task_count(self):
|
||||
for repair in self:
|
||||
repair.x_fc_technician_task_count = len(repair.x_fc_technician_task_ids)
|
||||
|
||||
@api.depends('x_fc_estimated_cost', 'x_fc_actual_cost')
|
||||
def _compute_cost_variance(self):
|
||||
for repair in self:
|
||||
if repair.x_fc_estimated_cost:
|
||||
repair.x_fc_cost_variance_pct = (
|
||||
(repair.x_fc_actual_cost - repair.x_fc_estimated_cost)
|
||||
/ repair.x_fc_estimated_cost * 100
|
||||
)
|
||||
else:
|
||||
repair.x_fc_cost_variance_pct = 0.0
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# WARRANTY DETERMINATION
|
||||
# ------------------------------------------------------------------
|
||||
def _fc_compute_warranty_status(self):
|
||||
"""Auto-detect warranty: not third-party AND within warranty window."""
|
||||
self.ensure_one()
|
||||
if self.x_fc_third_party_equipment:
|
||||
return False
|
||||
if not self.x_fc_original_sale_order_id:
|
||||
return False
|
||||
original = self.x_fc_original_sale_order_id
|
||||
delivery_date = original.commitment_date or original.date_order
|
||||
if not delivery_date:
|
||||
return False
|
||||
warranty_months = (
|
||||
self.product_id.product_tmpl_id.x_fc_warranty_months
|
||||
if self.product_id else 0
|
||||
)
|
||||
if not warranty_months:
|
||||
return False
|
||||
# Datetime + months: use simple 30-day approximation per month for now.
|
||||
cutoff = fields.Datetime.from_string(str(delivery_date)) + timedelta(days=warranty_months * 30)
|
||||
return fields.Datetime.now() <= cutoff
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# SMART BUTTONS
|
||||
# ------------------------------------------------------------------
|
||||
def action_view_intake_answers(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('Intake Answers'),
|
||||
'res_model': 'fusion.repair.intake.answer',
|
||||
'view_mode': 'list,form',
|
||||
'domain': [('repair_id', '=', self.id)],
|
||||
'context': {'default_repair_id': self.id},
|
||||
}
|
||||
|
||||
def action_view_technician_tasks(self):
|
||||
self.ensure_one()
|
||||
if len(self.x_fc_technician_task_ids) == 1:
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': self.x_fc_technician_task_ids.name,
|
||||
'res_model': 'fusion.technician.task',
|
||||
'view_mode': 'form',
|
||||
'res_id': self.x_fc_technician_task_ids.id,
|
||||
}
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('Technician Tasks'),
|
||||
'res_model': 'fusion.technician.task',
|
||||
'view_mode': 'list,form',
|
||||
'domain': [('x_fc_repair_order_id', '=', self.id)],
|
||||
'context': {'default_x_fc_repair_order_id': self.id},
|
||||
}
|
||||
|
||||
def action_view_original_sale_order(self):
|
||||
self.ensure_one()
|
||||
if not self.x_fc_original_sale_order_id:
|
||||
return False
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': self.x_fc_original_sale_order_id.name,
|
||||
'res_model': 'sale.order',
|
||||
'view_mode': 'form',
|
||||
'res_id': self.x_fc_original_sale_order_id.id,
|
||||
}
|
||||
Reference in New Issue
Block a user