Files
Odoo-Modules/fusion_repairs/models/technician_task.py
gsinghpal b4b59cc3c9 feat(fusion_repairs): Bundle 7 - tech mobile (T3 + T4 + T6 + T7)
T3 Labour timer on technician task
- Two new fields on fusion.technician.task: x_fc_timer_running_since
  (Datetime) + x_fc_timer_accumulated_minutes (Float).
- action_timer_start / action_timer_stop methods, idempotent (start when
  already running is a no-op, stop when not running is a no-op).
- Multiple start/stop cycles accumulate into the same total.
- Two header buttons (Start Timer green / Stop Timer amber), invisible
  based on the running_since field so the right one shows at any time.
- Stop posts a chatter line 'Labour timer stopped. Added X.X min, total
  Y.Y min.' so audit history shows every shift.

T4 Client signature on visit report
- New client_signature Binary field on the visit-report wizard with
  Odoo native widget='signature' that draws on canvas + base64-encodes
  the PNG.
- client_signature_name Char for typed name (audit).
- Persisted as an ir.attachment on the repair.order via the new
  _persist_mobile_artefacts helper.
- Chatter post 'Client signature captured (Jane Smith).'.

T6 Replaced parts - serial capture
- parts_serial_capture Text on the wizard (one per line per the spec).
- On confirm, posted to chatter wrapped in <pre> so line breaks survive.
- Used by OEM warranty filing in future M8.

T7 Client no-show photo proof
- no_show Boolean + no_show_photo Binary with widget='image' (visible
  only when no_show=True via Odoo 19 invisible= conditional).
- Photo saved as ir.attachment on the repair when present.
- Chatter post 'Visit recorded as client no-show (photo attached)'.

Verified end-to-end on local westin-v19:
  T3 timer started -> 2s sleep -> stopped -> 0.0357 min recorded
  T4 attachment 'signature-RO-202605-17.png' created on repair
  T6 chatter shows 'SN-AAA-111 / SN-BBB-222'
  T4 chatter shows 'Client signature captured (Jane Smith)'

Bumped to 19.0.1.7.0.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-21 00:24:35 -04:00

154 lines
5.9 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2024-2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)
from urllib.parse import quote_plus
from markupsafe import Markup
from odoo import _, fields, models
from odoo.exceptions import UserError
class FusionTechnicianTaskRepairs(models.Model):
"""Adds the back-link from fusion.technician.task to repair.order so
repairs and tasks share one timeline. Also hooks task completion to
roll a linked maintenance contract to its next cycle.
"""
_inherit = 'fusion.technician.task'
x_fc_repair_order_id = fields.Many2one(
'repair.order',
string='Repair Order',
ondelete='set null',
index=True,
tracking=True,
help='Repair order this task fulfils. Set automatically when the intake '
'wizard auto-creates a draft task for urgent / safety calls.',
)
x_fc_repair_intake_session_id = fields.Char(
related='x_fc_repair_order_id.x_fc_intake_session_id',
string='Intake Session',
store=True,
index=True,
)
# X2: per-task day-before reminder flag. Per-task (not per-repair) so
# a repair with multiple visits gets a separate reminder for each one.
x_fc_day_before_reminder_sent = fields.Boolean(
string='Day-Before Reminder Sent',
copy=False,
)
# ------------------------------------------------------------------
# T3 - Labour timer. The tech taps Start when they begin work and
# Stop when done; the accumulated minutes feeds the visit-report
# actual hours field. Multiple start/stop cycles are accumulated.
# ------------------------------------------------------------------
x_fc_timer_running_since = fields.Datetime(
string='Timer Running Since',
copy=False,
)
x_fc_timer_accumulated_minutes = fields.Float(
string='Accumulated Minutes',
default=0.0,
copy=False,
help='Total labour minutes captured by the tech timer. '
'Divide by 60 for the hours that prefill the visit report.',
)
def action_timer_start(self):
for t in self:
if t.x_fc_timer_running_since:
continue # already running
t.x_fc_timer_running_since = fields.Datetime.now()
t.message_post(body=Markup(_('Labour timer <b>started</b>.')))
def action_timer_stop(self):
for t in self:
if not t.x_fc_timer_running_since:
continue
from datetime import datetime
elapsed_minutes = (
datetime.now() - t.x_fc_timer_running_since
).total_seconds() / 60.0
t.x_fc_timer_accumulated_minutes = (
t.x_fc_timer_accumulated_minutes or 0.0
) + elapsed_minutes
t.x_fc_timer_running_since = False
t.message_post(body=Markup(_(
'Labour timer <b>stopped</b>. Added %(mins).1f min, total %(tot).1f min.'
)) % {
'mins': elapsed_minutes,
'tot': t.x_fc_timer_accumulated_minutes or 0.0,
})
def write(self, vals):
"""When a maintenance task transitions to 'completed', roll the
linked contract to its next cycle. Failure to roll never blocks
the underlying task write.
"""
res = super().write(vals)
if vals.get('status') == 'completed':
for task in self:
if task.task_type != 'maintenance':
continue
repair = task.x_fc_repair_order_id
contract = repair.x_fc_maintenance_contract_id if repair else False
if not contract:
continue
try:
contract.last_service_date = fields.Date.context_today(task)
contract.roll_next_due_date()
contract.message_post(body=Markup(
'Rolled forward after maintenance task '
'<b>%s</b> completed. Next due %s.'
) % (task.name or '', str(contract.next_due_date or '')))
except Exception:
# Never let a contract roll failure block the task write.
pass
return res
def action_view_repair_order(self):
self.ensure_one()
if not self.x_fc_repair_order_id:
return False
return {
'type': 'ir.actions.act_window',
'name': self.x_fc_repair_order_id.name,
'res_model': 'repair.order',
'view_mode': 'form',
'res_id': self.x_fc_repair_order_id.id,
}
# ------------------------------------------------------------------
# T1: Open in Maps - returns an act_url action that opens the device's
# default maps app (Apple Maps on iOS, Google Maps on Android, browser
# otherwise). Address is built from the task's address fields with the
# partner address as a fallback.
# ------------------------------------------------------------------
def action_open_in_maps(self):
self.ensure_one()
# Prefer fusion_tasks.address_display because in real data address_street
# often contains the full Google-Places-formatted address; concatenating
# the other address_* fields would duplicate city/zip.
addr = (getattr(self, 'address_display', '') or '').strip()
if not addr and self.partner_id:
p = self.partner_id
parts = [
p.street, p.street2, p.city,
p.state_id.name if p.state_id else False,
p.zip,
p.country_id.name if p.country_id else False,
]
addr = ', '.join(str(x) for x in parts if x)
if not addr:
raise UserError(_('No address on this task or its client.'))
return {
'type': 'ir.actions.act_url',
'url': f'https://www.google.com/maps?q={quote_plus(addr)}',
'target': 'new',
}