feat(fusion_repairs): Phase 2 - service catalogue, visit report, warranty, Poynt
Service catalogue - New fusion.repair.service.catalog model: named service entries per equipment category with symptom keywords, estimated hours / cost, default parts, auto_schedule flag, optional pricelist override - find_best_match() scores candidates by symptom-keyword overlap against intake text hints (issue summary + category + notes) - Intake service wires it in: on submit, the matcher sets x_fc_service_catalog_id + x_fc_estimated_duration + x_fc_estimated_cost and (when auto_schedule=True) creates a draft dispatch task - Double-task guard: if catalogue match already created a task, the urgency-based dispatch skips so we never duplicate Visit report wizard - fusion.repair.visit.report.wizard with labour hours + parts lines + technician notes + 'found another issue' branch - Computes actual cost = (labour x service_product.list_price) + parts - Compares against estimate -> sets requires_requote when variance exceeds configured threshold (% or $); shows warning banner inline - On confirm: writes actuals back to repair, posts notes to chatter, optionally spawns a follow-up repair (T5 'found another issue') Repair warranty - New fusion.repair.warranty.coverage model (start/expiry, partner, product, lot, active flag) - find_active_for(partner, product, lot) returns the most-recent active coverage - Intake service auto-checks: when a new repair lands on an equipment that has active warranty coverage, posts a chatter banner so the office knows the work may be free under our 30/90-day re-do policy (manager review still required; never auto-zeros pricing) Repair form - Header: Visit Report + Collect Payment buttons (gated by group) - action_collect_payment looks up the linked posted unpaid invoice on the repair SO and opens the Poynt wizard (action_open_poynt_payment_wizard) AI intake summary - _generate_ai_summary calls self.env['fusion.api.service'].call_openai with consumer='fusion_repairs', feature='intake_triage' - Strict system prompt: no medical advice, no diagnoses, no recommending stop equipment use; ~80 words; plain English - Try/fallback per fusion-api-integration.mdc: if fusion_api not installed or call fails -> silently skip; intake never blocked Verified end-to-end on local westin-v19: - Stairlift motor intake -> catalogue match -> estimated $500/2h -> auto dispatch task (count=1, not duplicated) - Visit report: 2.5h x $250 + $100 parts = $725 actual vs $500 estimated = 45% variance -> requires_requote=True - Warranty: 30-day coverage on the completed repair; second repair on same partner triggers warranty banner in chatter Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -132,6 +132,15 @@ class FusionRepairIntakeService(models.AbstractModel):
|
||||
# Persist intake answers.
|
||||
self._create_answers(repair, item.get('answers') or [])
|
||||
|
||||
# Service catalogue auto-match.
|
||||
self._match_service_catalog(repair, item)
|
||||
|
||||
# Check our own repair-warranty (30/90 day re-do free).
|
||||
self._check_repair_warranty(repair)
|
||||
|
||||
# Optional AI brief generation - never blocks intake.
|
||||
self._generate_ai_summary(repair, item)
|
||||
|
||||
# Attach photos.
|
||||
photo_ids = item.get('photo_attachment_ids') or []
|
||||
if photo_ids:
|
||||
@@ -146,7 +155,11 @@ class FusionRepairIntakeService(models.AbstractModel):
|
||||
self._schedule_activities(repair)
|
||||
|
||||
# Optional dispatch draft task (urgent / safety).
|
||||
if repair.x_fc_urgency in ('urgent', 'safety'):
|
||||
# Skip if the catalogue match already auto-created one.
|
||||
if (
|
||||
repair.x_fc_urgency in ('urgent', 'safety')
|
||||
and not repair.x_fc_technician_task_ids
|
||||
):
|
||||
self._create_dispatch_task(repair)
|
||||
|
||||
# Emails (client + office).
|
||||
@@ -178,6 +191,102 @@ class FusionRepairIntakeService(models.AbstractModel):
|
||||
parts.append('<p><strong>Notes:</strong> %s</p>' % notes)
|
||||
return ''.join(parts)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# SERVICE CATALOGUE MATCH
|
||||
# ------------------------------------------------------------------
|
||||
@api.model
|
||||
def _match_service_catalog(self, repair, item):
|
||||
category = repair.x_fc_repair_category_id
|
||||
if not category:
|
||||
return
|
||||
text_hints = [
|
||||
(item.get('issue_summary') or ''),
|
||||
(item.get('issue_category') or ''),
|
||||
(item.get('internal_notes') or ''),
|
||||
]
|
||||
catalog = self.env['fusion.repair.service.catalog'].sudo().find_best_match(
|
||||
category.id, text_hints,
|
||||
)
|
||||
if not catalog:
|
||||
return
|
||||
repair.write({
|
||||
'x_fc_service_catalog_id': catalog.id,
|
||||
'x_fc_estimated_duration': catalog.estimated_hours,
|
||||
'x_fc_estimated_cost': catalog.estimated_cost,
|
||||
})
|
||||
# Auto-create dispatch task if catalogue says so (in addition to urgency rule).
|
||||
if catalog.auto_schedule and repair.x_fc_technician_task_count == 0:
|
||||
self._create_dispatch_task(repair)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# REPAIR WARRANTY (our 30/90-day re-do free)
|
||||
# ------------------------------------------------------------------
|
||||
@api.model
|
||||
def _check_repair_warranty(self, repair):
|
||||
if not repair.partner_id:
|
||||
return
|
||||
warranty = self.env['fusion.repair.warranty.coverage'].sudo() \
|
||||
.find_active_for(repair.partner_id.id, repair.product_id.id or None,
|
||||
repair.lot_id.id or None)
|
||||
if not warranty:
|
||||
return
|
||||
repair.message_post(
|
||||
body=_(
|
||||
'This repair MAY be covered by our active warranty <b>%(ref)s</b> '
|
||||
'(expires %(exp)s). Manager review recommended before invoicing.',
|
||||
ref=warranty.name,
|
||||
exp=warranty.expiry_date,
|
||||
),
|
||||
message_type='comment',
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# AI SUMMARY (try/fallback per fusion-api-integration rule)
|
||||
# ------------------------------------------------------------------
|
||||
@api.model
|
||||
def _generate_ai_summary(self, repair, item):
|
||||
try:
|
||||
ApiService = self.env.get('fusion.api.service')
|
||||
if not ApiService:
|
||||
return
|
||||
issue = (item.get('issue_summary') or '').strip()
|
||||
if not issue:
|
||||
return
|
||||
category = repair.x_fc_repair_category_id.name or 'medical equipment'
|
||||
urgency = repair.x_fc_urgency or 'normal'
|
||||
messages = [
|
||||
{
|
||||
'role': 'system',
|
||||
'content': (
|
||||
'You are an assistant for a medical equipment repair service. '
|
||||
'Given an intake note, output ONE short paragraph (under 80 words) '
|
||||
'briefing the technician about: likely cause, what to bring, and '
|
||||
'any safety considerations. NEVER provide medical advice. NEVER '
|
||||
'recommend stopping equipment use. NEVER claim a definitive cause. '
|
||||
'Plain English, no jargon.'
|
||||
),
|
||||
},
|
||||
{
|
||||
'role': 'user',
|
||||
'content': (
|
||||
f'Equipment category: {category}\n'
|
||||
f'Urgency: {urgency}\n'
|
||||
f'Issue: {issue}\n'
|
||||
f'Notes: {(item.get("internal_notes") or "").strip()}'
|
||||
),
|
||||
},
|
||||
]
|
||||
summary = ApiService.call_openai(
|
||||
consumer='fusion_repairs',
|
||||
feature='intake_triage',
|
||||
messages=messages,
|
||||
max_tokens=200,
|
||||
)
|
||||
if summary:
|
||||
repair.x_fc_ai_summary = summary.strip()
|
||||
except Exception as e:
|
||||
_logger.info('AI intake summary skipped: %s', e)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# ORIGINAL SO AUTO-LINK
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user