feat(fusion_repairs): Bundle 8 - rush service + emergency pricing + parts-ordered workflow
The grumpy-old-customer-with-broken-stairlift scenario. Four real workflows
the office faces every week, with comms baked in so the client never has to
call back asking for status.
NEW MODELS
- fusion.repair.emergency.charge (rate card)
Per (category, tier) rate with per_tech_multiplier; 5 tiers
(same_day / next_day / after_hours / weekend / holiday). Each category
can have its own rates - bed motors need 2 techs, stairlift is single.
Seeded with realistic Westin rates: stairlift same-day $250, weekend
$450; porch lift same-day $300; bed same-day $175 with 0.6 multiplier
(2-tech jobs frequent); powerchair same-day $200.
- fusion.repair.part.order (procurement-facing record)
One per distinct part the tech needs from the manufacturer. Carries
description + OEM # + manufacturer + quantity + photos + notes.
4-state lifecycle: draft -> ordered -> received -> fitted (or
cancelled). On state transitions:
draft -> ordered: email client "ordered, expected by X"
ordered -> received: email client "arrived, scheduling return visit"
+ auto-create follow-up dispatch task when ALL
outstanding parts on the repair have arrived.
REPAIR.ORDER EXTENSIONS
- Rush fields: x_fc_rush_requested, x_fc_rush_tier,
x_fc_rush_techs_required, x_fc_rush_surcharge (computed via rate card),
x_fc_rush_acknowledged_at + x_fc_rush_acknowledged_by_id (audit trail
proving CS got verbal OK before charging).
- Parts-awaiting fields: x_fc_parts_awaiting + x_fc_parts_eta_date +
x_fc_part_order_ids One2many + x_fc_part_order_count.
- New methods:
* action_acknowledge_rush() - one-click "client agreed" with audit.
* action_squeeze_into_today() - picks the lightest-loaded skilled tech,
finds their first free 1-hour slot between 9am-6pm, schedules the
task in it, sends:
1) live bus.bus push to the tech (sticky notification in their
web client - so they see it MID-SHIFT)
2) rush-alert email (force_send=True - this can't wait in the queue)
3) chatter post on the tech task itself
Validates against fusion_tasks' time-conflict rule by passing
force_schedule via context (intake.service honours it).
* action_view_part_orders() - smart button.
WIZARD EXTENSIONS
- repair.intake.wizard:
New rush_requested + rush_tier + rush_techs_required + rush_acknowledged
controls. Live rush_surcharge_preview compute shows CS the price in
real-time as they change category / tier / tech count. Yellow alert
reminds CS to read the price to the client BEFORE submitting.
- repair.visit.report.wizard:
New outcome radio: completed / parts_needed / rescheduled.
When outcome=parts_needed, needs_parts_line_ids One2many appears for
the tech to capture each part (description, OEM, manufacturer, qty,
lead days, notes, photos). On submit each line creates a
fusion.repair.part.order, the repair flips to x_fc_parts_awaiting=True
with an ETA, and the client gets the "we found the problem, here's the
plan" email immediately.
INTAKE SERVICE
- _create_dispatch_task now honours force_schedule (date + time_start +
time_end) via context so squeeze + auto-redispatch don't crash on
fusion_tasks' time-window validator.
- _create_single_repair carries rush_requested/tier/techs through to
the new repair fields.
MAIL TEMPLATES (4 new)
- email_template_rush_tech_alert: red 4px accent, address + phone + the
$surcharge - what the tech needs to know mid-shift.
- email_template_repair_awaiting_parts: amber accent, "we found the
problem, parts ordered, return visit ~ETA, no action needed".
- email_template_parts_ordered: blue, per-part confirmation.
- email_template_parts_received: green, "arrived, office will call to
confirm visit".
UI / NAVIGATION
- Backend wizard: rush controls + live surcharge preview + verbal-OK alert.
- repair.order form: new Rush / Parts notebook tab with all the fields
+ linked part orders list. Two new header buttons (Squeeze into
Today / Client Agreed to Rush Price). Two new search filters
(Rush, Awaiting Parts).
- Part Order form: statusbar with the 4 transitions + Cancel; notes +
photos notebook tabs; full chatter for audit.
- Menus: 'Parts to Order' under root; 'Emergency Surcharges' under
Configuration.
SECURITY
- 8 new ACL entries (emergency_charge user/manager; part_order
user/dispatcher/manager/technician; visit_report partline for office
and field tech). Office sees parts but only managers can edit
emergency rates.
Verified end-to-end on local westin-v19 - all 4 scenarios green:
S1 Same-day rush stairlift -> $250 surcharge, ack stamped, squeeze
assigned garry@ at first free 1h slot today, alert email queued,
chatter posted.
S2 Next-day priority bed -> $0 surcharge (no rate seeded for bed
next_day - office can configure), 4 emails queued (client + office).
S3 2-tech weekend stairlift -> $675 (450 base + 0.5x base for 2nd tech).
S4 Parts-needed visit-report -> 2 PART-#### records created, repair
awaiting_parts=True, ETA=2026-06-06, office activity scheduled,
client email sent. Marking part ordered -> client mail. Marking
all parts received -> auto-dispatch follow-up + client mail.
Bumped to 19.0.1.9.1.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -99,6 +99,54 @@ class RepairIntakeWizard(models.TransientModel):
|
||||
'is gathering quotes or has not yet authorised the repair.',
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Bundle 8: rush / emergency options + live surcharge preview
|
||||
# ------------------------------------------------------------------
|
||||
rush_requested = fields.Boolean(
|
||||
string='Rush / Emergency Service',
|
||||
help='Tick when the client needs faster-than-normal turnaround. '
|
||||
'Surcharge is calculated automatically from the rate card.',
|
||||
)
|
||||
rush_tier = fields.Selection(
|
||||
[
|
||||
('same_day', 'Same Day (during business hours)'),
|
||||
('next_day', 'Next Day Priority'),
|
||||
('after_hours', 'After Hours (5pm-9pm weekday)'),
|
||||
('weekend', 'Weekend'),
|
||||
('holiday', 'Statutory Holiday'),
|
||||
],
|
||||
string='Rush Tier',
|
||||
)
|
||||
rush_techs_required = fields.Integer(
|
||||
string='Technicians Required',
|
||||
default=1,
|
||||
)
|
||||
rush_surcharge_preview = fields.Monetary(
|
||||
string='Quoted Surcharge',
|
||||
compute='_compute_rush_surcharge_preview',
|
||||
currency_field='currency_id',
|
||||
)
|
||||
rush_acknowledged = fields.Boolean(
|
||||
string='Client Agreed to Price',
|
||||
help='Tick this AFTER you have read the surcharge to the client over the '
|
||||
'phone and they have said yes. The repair will record the '
|
||||
'acknowledgement timestamp + your user id for audit.',
|
||||
)
|
||||
|
||||
@api.depends('rush_tier', 'rush_techs_required', 'equipment_ids.repair_category_id')
|
||||
def _compute_rush_surcharge_preview(self):
|
||||
Rates = self.env['fusion.repair.emergency.charge'].sudo()
|
||||
for w in self:
|
||||
if not w.rush_tier or not w.equipment_ids:
|
||||
w.rush_surcharge_preview = 0.0
|
||||
continue
|
||||
# Use the FIRST equipment's category for the preview - per-equipment
|
||||
# surcharges land on each repair.order after create.
|
||||
cat = w.equipment_ids[:1].repair_category_id
|
||||
w.rush_surcharge_preview = Rates.calculate(
|
||||
cat, w.rush_tier, w.rush_techs_required or 1,
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# EQUIPMENT (one-or-many)
|
||||
# ------------------------------------------------------------------
|
||||
@@ -193,6 +241,10 @@ class RepairIntakeWizard(models.TransientModel):
|
||||
'partner_id': self.partner_id.id,
|
||||
'intake_user_id': self.intake_user_id.id,
|
||||
'quote_only': self.quote_only,
|
||||
'rush_requested': self.rush_requested,
|
||||
'rush_tier': self.rush_tier if self.rush_requested else False,
|
||||
'rush_techs_required': self.rush_techs_required if self.rush_requested else 1,
|
||||
'rush_acknowledged': self.rush_acknowledged,
|
||||
'equipment_items': [self._equipment_payload(eq) for eq in self.equipment_ids],
|
||||
}
|
||||
|
||||
@@ -202,6 +254,12 @@ class RepairIntakeWizard(models.TransientModel):
|
||||
payload, source='backend_wizard',
|
||||
)
|
||||
|
||||
# If CS ticked "rush" and "client agreed", stamp the ack on every spawned repair.
|
||||
if self.rush_requested and self.rush_acknowledged:
|
||||
for r in repairs:
|
||||
r.x_fc_rush_acknowledged_at = fields.Datetime.now()
|
||||
r.x_fc_rush_acknowledged_by_id = self.intake_user_id.id or self.env.uid
|
||||
|
||||
if len(repairs) == 1:
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
|
||||
@@ -95,6 +95,31 @@
|
||||
<group>
|
||||
<field name="quote_only"/>
|
||||
</group>
|
||||
|
||||
<!-- Bundle 8: rush / emergency surcharge -->
|
||||
<separator string="Rush / Emergency Service"/>
|
||||
<group>
|
||||
<field name="rush_requested"/>
|
||||
<field name="rush_tier"
|
||||
required="rush_requested"
|
||||
invisible="not rush_requested"/>
|
||||
<field name="rush_techs_required"
|
||||
invisible="not rush_requested"/>
|
||||
<field name="rush_surcharge_preview"
|
||||
widget="monetary"
|
||||
readonly="1"
|
||||
invisible="not rush_requested"/>
|
||||
<field name="currency_id" invisible="1"/>
|
||||
<field name="rush_acknowledged"
|
||||
invisible="not rush_requested"/>
|
||||
</group>
|
||||
<div class="alert alert-warning"
|
||||
role="alert"
|
||||
invisible="not rush_requested or rush_acknowledged">
|
||||
<i class="fa fa-exclamation-triangle me-1"/>
|
||||
<strong>Read the surcharge to the client and get verbal OK.</strong>
|
||||
Then tick the "Client Agreed to Price" box above before submitting.
|
||||
</div>
|
||||
</sheet>
|
||||
<footer>
|
||||
<button string="Submit"
|
||||
|
||||
@@ -19,6 +19,7 @@ On confirm:
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
from markupsafe import Markup
|
||||
|
||||
@@ -108,6 +109,29 @@ class RepairVisitReportWizard(models.TransientModel):
|
||||
help='One serial per line. Used for OEM warranty claims.',
|
||||
)
|
||||
|
||||
# ----- Bundle 8: Cannot Fix Today - Needs Parts -----
|
||||
outcome = fields.Selection(
|
||||
[
|
||||
('completed', 'Repair Complete - Close It'),
|
||||
('parts_needed', "Can't Fix Today - Need to Order Parts"),
|
||||
('rescheduled', 'Could Not Reach / Rescheduled'),
|
||||
],
|
||||
string='Visit Outcome',
|
||||
default='completed',
|
||||
required=True,
|
||||
help='Drives what happens after you submit: completed -> closes the '
|
||||
"repair; parts_needed -> captures the part info, emails the client, "
|
||||
"schedules follow-up; rescheduled -> repair stays open.",
|
||||
)
|
||||
needs_parts_line_ids = fields.One2many(
|
||||
'fusion.repair.visit.report.wizard.partline',
|
||||
'wizard_id',
|
||||
string='Parts To Order',
|
||||
help='ONE line per distinct part. Description + OEM number + photos go to '
|
||||
'procurement so they can place the manufacturer order from your input '
|
||||
'alone.',
|
||||
)
|
||||
|
||||
# Variance display
|
||||
estimated_cost = fields.Monetary(
|
||||
related='repair_id.x_fc_estimated_cost',
|
||||
@@ -228,17 +252,26 @@ class RepairVisitReportWizard(models.TransientModel):
|
||||
if not repair.x_fc_is_quote_only:
|
||||
self._burn_service_plan_visit(repair)
|
||||
|
||||
# Bundle 8: parts-needed branch - capture the parts, flag the repair,
|
||||
# email the client, leave the repair OPEN with awaiting_parts substate.
|
||||
if self.outcome == 'parts_needed':
|
||||
self._handle_parts_needed(repair)
|
||||
elif self.outcome == 'rescheduled':
|
||||
repair.message_post(body=Markup(_(
|
||||
'Visit reported as <b>rescheduled</b>. Repair kept open.'
|
||||
)))
|
||||
# BUG-B1 fix: actually close the repair so the whole downstream chain
|
||||
# (NPS cron, dashboard "done this month" stats, customer survey) fires.
|
||||
# Leave open if requote needed - the office will re-quote and the tech
|
||||
# will revisit. No-show or quote-only also stays open.
|
||||
if (not self.requires_requote
|
||||
# will revisit. No-show / parts-needed / rescheduled / quote-only also
|
||||
# stay open.
|
||||
elif (self.outcome == 'completed'
|
||||
and not self.requires_requote
|
||||
and not self.no_show
|
||||
and not repair.x_fc_is_quote_only
|
||||
and not stub):
|
||||
self._close_repair(repair)
|
||||
elif self.no_show:
|
||||
# No-show: drop back to draft for re-scheduling.
|
||||
repair.message_post(body=Markup(_(
|
||||
'Repair kept <b>open</b> due to no-show. Office to reschedule.'
|
||||
)))
|
||||
@@ -306,6 +339,72 @@ class RepairVisitReportWizard(models.TransientModel):
|
||||
'Replaced part serials captured:<br/><pre>%s</pre>'
|
||||
)) % self.parts_serial_capture.strip())
|
||||
|
||||
def _handle_parts_needed(self, repair):
|
||||
"""Capture each part line as a fusion.repair.part.order record,
|
||||
flag the repair as Awaiting Parts, and email the client a
|
||||
"we found the problem - here's the timeline" note."""
|
||||
if not self.needs_parts_line_ids:
|
||||
raise UserError(_(
|
||||
'Tick "Can\'t Fix Today - Need to Order Parts" but no parts '
|
||||
'are captured. Add at least one part line so procurement can '
|
||||
'place the order.'
|
||||
))
|
||||
PartOrder = self.env['fusion.repair.part.order'].sudo()
|
||||
Attachment = self.env['ir.attachment'].sudo()
|
||||
max_lead = 0
|
||||
for line in self.needs_parts_line_ids:
|
||||
# Copy any uploaded photos onto attachments owned by the part order.
|
||||
photo_ids = []
|
||||
for att in line.photo_ids:
|
||||
copied = Attachment.create({
|
||||
'name': att.name,
|
||||
'datas': att.datas,
|
||||
'mimetype': att.mimetype,
|
||||
})
|
||||
photo_ids.append(copied.id)
|
||||
part = PartOrder.create({
|
||||
'repair_order_id': repair.id,
|
||||
'description': line.description,
|
||||
'oem_part_number': line.oem_part_number,
|
||||
'manufacturer': line.manufacturer,
|
||||
'quantity': line.quantity or 1.0,
|
||||
'notes': line.notes,
|
||||
'photo_ids': [(6, 0, photo_ids)] if photo_ids else False,
|
||||
'expected_date': line.expected_lead_days and (
|
||||
fields.Date.context_today(self)
|
||||
+ timedelta(days=line.expected_lead_days)
|
||||
) or False,
|
||||
})
|
||||
max_lead = max(max_lead, int(line.expected_lead_days or 0))
|
||||
repair.write({
|
||||
'x_fc_parts_awaiting': True,
|
||||
'x_fc_parts_eta_date': (
|
||||
fields.Date.context_today(self) + timedelta(days=max_lead + 2)
|
||||
if max_lead else False
|
||||
),
|
||||
})
|
||||
# Office activity - "place these orders today".
|
||||
repair.activity_schedule(
|
||||
summary='Order parts from manufacturer(s)',
|
||||
note=_('Tech captured %d part(s) - place the order(s) today.'
|
||||
) % len(self.needs_parts_line_ids),
|
||||
user_id=repair.user_id.id or self.env.uid,
|
||||
)
|
||||
# Client comms.
|
||||
tpl = self.env.ref(
|
||||
'fusion_repairs.email_template_repair_awaiting_parts',
|
||||
raise_if_not_found=False,
|
||||
)
|
||||
if tpl and repair.partner_id and repair.partner_id.email:
|
||||
try:
|
||||
tpl.send_mail(repair.id, force_send=False)
|
||||
except Exception:
|
||||
_logger.exception('Awaiting-parts email failed for %s', repair.name)
|
||||
repair.message_post(body=Markup(_(
|
||||
'Visit reported as <b>parts needed</b>. Captured %(n)d part order(s); '
|
||||
'repair flagged "Awaiting Parts". Client notified.'
|
||||
)) % {'n': len(self.needs_parts_line_ids)})
|
||||
|
||||
def _close_repair(self, repair):
|
||||
"""Drive the Odoo native state machine from draft -> done.
|
||||
|
||||
@@ -437,3 +536,40 @@ class RepairVisitReportWizardLine(models.TransientModel):
|
||||
def _compute_subtotal(self):
|
||||
for line in self:
|
||||
line.subtotal = line.quantity * line.unit_price
|
||||
|
||||
|
||||
class RepairVisitReportWizardPartLine(models.TransientModel):
|
||||
"""Bundle 8: parts the tech needs the office to ORDER from the manufacturer.
|
||||
|
||||
Captured during the visit report when outcome='parts_needed'; one record per
|
||||
distinct part. On wizard confirm, each line creates a
|
||||
fusion.repair.part.order which is the procurement-facing record.
|
||||
"""
|
||||
_name = 'fusion.repair.visit.report.wizard.partline'
|
||||
_description = 'Visit Report - Part to Order'
|
||||
|
||||
wizard_id = fields.Many2one(
|
||||
'fusion.repair.visit.report.wizard',
|
||||
required=True,
|
||||
ondelete='cascade',
|
||||
)
|
||||
description = fields.Char(
|
||||
string='Description',
|
||||
required=True,
|
||||
help='Plain English (e.g. "Handicare 1100 right armrest").',
|
||||
)
|
||||
oem_part_number = fields.Char(string='OEM #')
|
||||
manufacturer = fields.Char(string='Manufacturer')
|
||||
quantity = fields.Float(default=1.0, required=True)
|
||||
expected_lead_days = fields.Integer(
|
||||
string='Lead Time (days)',
|
||||
default=7,
|
||||
help='Tech estimate. Office uses this to set client ETA expectations.',
|
||||
)
|
||||
notes = fields.Text(string='Notes for Procurement')
|
||||
photo_ids = fields.Many2many(
|
||||
'ir.attachment',
|
||||
'fusion_repair_visit_partline_photo_rel',
|
||||
'partline_id', 'attachment_id',
|
||||
string='Photos',
|
||||
)
|
||||
|
||||
@@ -47,9 +47,31 @@
|
||||
</div>
|
||||
|
||||
<separator string="Outcome"/>
|
||||
<group>
|
||||
<field name="outcome" widget="radio"/>
|
||||
</group>
|
||||
<field name="notes"/>
|
||||
<field name="found_another_issue"/>
|
||||
<field name="issue_inspection_cert"/>
|
||||
|
||||
<!-- Bundle 8: parts-needed branch - rendered only when chosen -->
|
||||
<separator string="Parts to Order"
|
||||
invisible="outcome != 'parts_needed'"/>
|
||||
<field name="needs_parts_line_ids"
|
||||
invisible="outcome != 'parts_needed'">
|
||||
<list editable="bottom">
|
||||
<field name="description"/>
|
||||
<field name="oem_part_number"/>
|
||||
<field name="manufacturer"/>
|
||||
<field name="quantity"/>
|
||||
<field name="expected_lead_days"/>
|
||||
<field name="notes" optional="show"/>
|
||||
<field name="photo_ids" widget="many2many_binary"/>
|
||||
</list>
|
||||
</field>
|
||||
|
||||
<field name="found_another_issue"
|
||||
invisible="outcome != 'completed'"/>
|
||||
<field name="issue_inspection_cert"
|
||||
invisible="outcome != 'completed'"/>
|
||||
|
||||
<separator string="No-Show (T7)"/>
|
||||
<group>
|
||||
|
||||
Reference in New Issue
Block a user