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:
15
fusion_repairs/models/__init__.py
Normal file
15
fusion_repairs/models/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2024-2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
|
||||
from . import repair_product_category
|
||||
from . import intake_template
|
||||
from . import intake_question
|
||||
from . import intake_answer
|
||||
from . import product_template
|
||||
from . import res_partner
|
||||
from . import res_users
|
||||
from . import res_config_settings
|
||||
from . import technician_task
|
||||
from . import repair_order
|
||||
from . import intake_service
|
||||
88
fusion_repairs/models/intake_answer.py
Normal file
88
fusion_repairs/models/intake_answer.py
Normal file
@@ -0,0 +1,88 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2024-2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class FusionRepairIntakeAnswer(models.Model):
|
||||
"""An answer to a single intake question on a specific repair order.
|
||||
|
||||
Persists raw answer values for audit + reporting + AI / catalogue matching.
|
||||
"""
|
||||
|
||||
_name = 'fusion.repair.intake.answer'
|
||||
_description = 'Repair Intake Answer'
|
||||
_order = 'repair_id, sequence, id'
|
||||
|
||||
repair_id = fields.Many2one(
|
||||
'repair.order',
|
||||
string='Repair Order',
|
||||
required=True,
|
||||
ondelete='cascade',
|
||||
index=True,
|
||||
)
|
||||
question_id = fields.Many2one(
|
||||
'fusion.repair.intake.question',
|
||||
string='Question',
|
||||
required=True,
|
||||
ondelete='restrict',
|
||||
)
|
||||
question_name = fields.Char(
|
||||
related='question_id.name',
|
||||
string='Question',
|
||||
store=True,
|
||||
)
|
||||
question_type = fields.Selection(
|
||||
related='question_id.question_type',
|
||||
store=True,
|
||||
)
|
||||
sequence = fields.Integer(
|
||||
related='question_id.sequence',
|
||||
store=True,
|
||||
)
|
||||
|
||||
# Typed value fields - one per supported type, plus a display string.
|
||||
value_char = fields.Char(string='Text Answer')
|
||||
value_text = fields.Text(string='Long Text Answer')
|
||||
value_selection = fields.Char(string='Choice Answer')
|
||||
value_boolean = fields.Boolean(string='Yes/No Answer')
|
||||
value_integer = fields.Integer(string='Number Answer')
|
||||
value_date = fields.Date(string='Date Answer')
|
||||
|
||||
value_display = fields.Char(
|
||||
string='Answer',
|
||||
compute='_compute_value_display',
|
||||
store=True,
|
||||
)
|
||||
|
||||
company_id = fields.Many2one(
|
||||
'res.company',
|
||||
related='repair_id.company_id',
|
||||
store=True,
|
||||
index=True,
|
||||
)
|
||||
|
||||
@api.depends(
|
||||
'question_type',
|
||||
'value_char', 'value_text', 'value_selection',
|
||||
'value_boolean', 'value_integer', 'value_date',
|
||||
)
|
||||
def _compute_value_display(self):
|
||||
for answer in self:
|
||||
if answer.question_type == 'char':
|
||||
answer.value_display = answer.value_char or ''
|
||||
elif answer.question_type == 'text':
|
||||
answer.value_display = (answer.value_text or '')[:200]
|
||||
elif answer.question_type == 'selection':
|
||||
answer.value_display = answer.value_selection or ''
|
||||
elif answer.question_type == 'boolean':
|
||||
answer.value_display = 'Yes' if answer.value_boolean else 'No'
|
||||
elif answer.question_type == 'integer':
|
||||
answer.value_display = str(answer.value_integer or 0)
|
||||
elif answer.question_type == 'date':
|
||||
answer.value_display = (
|
||||
fields.Date.to_string(answer.value_date) if answer.value_date else ''
|
||||
)
|
||||
else:
|
||||
answer.value_display = ''
|
||||
84
fusion_repairs/models/intake_question.py
Normal file
84
fusion_repairs/models/intake_question.py
Normal file
@@ -0,0 +1,84 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2024-2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
QUESTION_TYPES = [
|
||||
('char', 'Short Text'),
|
||||
('text', 'Long Text'),
|
||||
('selection', 'Single Choice'),
|
||||
('boolean', 'Yes / No'),
|
||||
('integer', 'Number'),
|
||||
('date', 'Date'),
|
||||
]
|
||||
|
||||
|
||||
class FusionRepairIntakeQuestion(models.Model):
|
||||
"""A single question on an intake template.
|
||||
|
||||
Supports basic conditional display: a question is only shown when the
|
||||
parent question's answer matches `parent_answer_value`. The wizard and
|
||||
portal forms render based on these rules.
|
||||
"""
|
||||
|
||||
_name = 'fusion.repair.intake.question'
|
||||
_description = 'Repair Intake Question'
|
||||
_order = 'sequence, id'
|
||||
|
||||
template_id = fields.Many2one(
|
||||
'fusion.repair.intake.template',
|
||||
string='Template',
|
||||
required=True,
|
||||
ondelete='cascade',
|
||||
index=True,
|
||||
)
|
||||
sequence = fields.Integer(string='Sequence', default=10)
|
||||
name = fields.Char(
|
||||
string='Question',
|
||||
required=True,
|
||||
translate=True,
|
||||
help='Text shown to the user.',
|
||||
)
|
||||
code = fields.Char(
|
||||
string='Code',
|
||||
help='Stable identifier for this question (used by automation rules and reporting).',
|
||||
)
|
||||
help_text = fields.Char(
|
||||
string='Help Text',
|
||||
translate=True,
|
||||
help='Optional shorter hint shown beneath the question (e.g. "e.g. SN-12345").',
|
||||
)
|
||||
question_type = fields.Selection(
|
||||
QUESTION_TYPES,
|
||||
string='Type',
|
||||
required=True,
|
||||
default='char',
|
||||
)
|
||||
required = fields.Boolean(default=False)
|
||||
|
||||
selection_options = fields.Text(
|
||||
string='Choices',
|
||||
help='One option per line, only used when type is "Single Choice".',
|
||||
)
|
||||
|
||||
# Conditional display
|
||||
parent_question_id = fields.Many2one(
|
||||
'fusion.repair.intake.question',
|
||||
string='Show Only If Question',
|
||||
domain="[('template_id', '=', template_id), ('id', '!=', id)]",
|
||||
ondelete='set null',
|
||||
help='Show this question only when the parent question matches the value below.',
|
||||
)
|
||||
parent_answer_value = fields.Char(
|
||||
string='Parent Answer Equals',
|
||||
help='Value the parent answer must equal for this question to be displayed.',
|
||||
)
|
||||
|
||||
# Symptom keyword classification - feeds the service catalogue matcher and AI prompt
|
||||
symptom_keywords = fields.Char(
|
||||
string='Symptom Keywords',
|
||||
help='Comma-separated keywords that, when present in the answer, tag the repair '
|
||||
'for catalogue matching (e.g. "battery,charge").',
|
||||
)
|
||||
347
fusion_repairs/models/intake_service.py
Normal file
347
fusion_repairs/models/intake_service.py
Normal file
@@ -0,0 +1,347 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2024-2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
|
||||
"""Shared intake service.
|
||||
|
||||
This AbstractModel is the SINGLE entry point for creating repair orders from
|
||||
any intake surface: the backend wizard (Phase 1), the sales rep portal
|
||||
(Phase 1+), and the public client self-service portal (Phase 1+).
|
||||
|
||||
All three surfaces call `create_repair_orders(payload, source='...')` so that
|
||||
business logic - activities, emails, warranty determination, AI summary,
|
||||
catalogue match, third-party flag, dispatch task creation - lives in one
|
||||
place and the surfaces never drift apart.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FusionRepairIntakeService(models.AbstractModel):
|
||||
_name = 'fusion.repair.intake.service'
|
||||
_description = 'Repair Intake Service (shared by backend / sales rep / client)'
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# PUBLIC API
|
||||
# ------------------------------------------------------------------
|
||||
@api.model
|
||||
def create_repair_orders(self, payload, source='backend_wizard'):
|
||||
"""Create one repair.order per equipment item in the payload.
|
||||
|
||||
:param payload: dict with keys:
|
||||
- partner_id: int (required) or partner_vals: dict to create new partner
|
||||
- intake_user_id: int (optional, defaults to env.user)
|
||||
- equipment_items: list of dicts, each with:
|
||||
- product_id: int (optional)
|
||||
- lot_id: int (optional)
|
||||
- repair_category_id: int (optional)
|
||||
- intake_template_id: int (optional)
|
||||
- third_party: bool (optional)
|
||||
- urgency: str (optional, default 'normal')
|
||||
- issue_summary: str (optional)
|
||||
- internal_notes: str (optional)
|
||||
- photo_attachment_ids: list[int] (optional)
|
||||
- answers: list of dicts with keys
|
||||
(question_id, value_char|value_text|value_selection|
|
||||
value_boolean|value_integer|value_date)
|
||||
:param source: str, one of repair_order.INTAKE_SOURCES values.
|
||||
:return: recordset of repair.order records created.
|
||||
"""
|
||||
partner_id = self._resolve_partner(payload)
|
||||
if not partner_id:
|
||||
raise UserError(_('A client is required to create a repair request.'))
|
||||
|
||||
intake_user = self.env['res.users'].browse(
|
||||
payload.get('intake_user_id') or self.env.uid
|
||||
)
|
||||
session_ref = (
|
||||
self.env['ir.sequence'].next_by_code('fusion.repair.intake.session')
|
||||
or 'RIS/NEW'
|
||||
)
|
||||
|
||||
equipment = payload.get('equipment_items') or [{}]
|
||||
repairs = self.env['repair.order']
|
||||
for item in equipment:
|
||||
repair = self._create_single_repair(
|
||||
partner_id=partner_id,
|
||||
intake_user=intake_user,
|
||||
session_ref=session_ref,
|
||||
source=source,
|
||||
item=item,
|
||||
)
|
||||
repairs |= repair
|
||||
|
||||
return repairs
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# PARTNER RESOLUTION
|
||||
# ------------------------------------------------------------------
|
||||
@api.model
|
||||
def _resolve_partner(self, payload):
|
||||
partner_id = payload.get('partner_id')
|
||||
if partner_id:
|
||||
return partner_id
|
||||
partner_vals = payload.get('partner_vals')
|
||||
if not partner_vals:
|
||||
return False
|
||||
partner = self.env['res.partner'].sudo().create(partner_vals)
|
||||
return partner.id
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# CORE CREATION
|
||||
# ------------------------------------------------------------------
|
||||
@api.model
|
||||
def _create_single_repair(self, partner_id, intake_user, session_ref, source, item):
|
||||
Repair = self.env['repair.order']
|
||||
product_id = item.get('product_id')
|
||||
|
||||
vals = {
|
||||
'partner_id': partner_id,
|
||||
'user_id': intake_user.id,
|
||||
'x_fc_intake_user_id': intake_user.id,
|
||||
'x_fc_intake_session_id': session_ref,
|
||||
'x_fc_intake_source': source,
|
||||
'x_fc_repair_category_id': item.get('repair_category_id') or False,
|
||||
'x_fc_intake_template_id': item.get('intake_template_id') or False,
|
||||
'x_fc_third_party_equipment': bool(item.get('third_party')),
|
||||
'x_fc_urgency': item.get('urgency') or 'normal',
|
||||
'x_fc_issue_category': item.get('issue_category') or False,
|
||||
'internal_notes': self._wrap_internal_notes(item),
|
||||
}
|
||||
if product_id:
|
||||
vals['product_id'] = product_id
|
||||
if item.get('lot_id'):
|
||||
vals['lot_id'] = item['lot_id']
|
||||
if item.get('schedule_date'):
|
||||
vals['schedule_date'] = item['schedule_date']
|
||||
|
||||
repair = Repair.create(vals)
|
||||
|
||||
# Determine warranty AFTER creation (needs product on record).
|
||||
if not repair.x_fc_third_party_equipment:
|
||||
self._auto_link_original_sale_order(repair)
|
||||
if repair._fc_compute_warranty_status():
|
||||
repair.under_warranty = True
|
||||
|
||||
# Persist intake answers.
|
||||
self._create_answers(repair, item.get('answers') or [])
|
||||
|
||||
# Attach photos.
|
||||
photo_ids = item.get('photo_attachment_ids') or []
|
||||
if photo_ids:
|
||||
attachments = self.env['ir.attachment'].sudo().browse(photo_ids).exists()
|
||||
attachments.write({
|
||||
'res_model': 'repair.order',
|
||||
'res_id': repair.id,
|
||||
})
|
||||
repair.write({'x_fc_photo_ids': [(6, 0, attachments.ids)]})
|
||||
|
||||
# Activities.
|
||||
self._schedule_activities(repair)
|
||||
|
||||
# Optional dispatch draft task (urgent / safety).
|
||||
if repair.x_fc_urgency in ('urgent', 'safety'):
|
||||
self._create_dispatch_task(repair)
|
||||
|
||||
# Emails (client + office).
|
||||
self._send_intake_emails(repair)
|
||||
|
||||
# Audit message in chatter.
|
||||
repair.message_post(
|
||||
body=_(
|
||||
'Service call submitted via <b>%(source)s</b> by %(user)s. '
|
||||
'Session reference: %(ref)s.',
|
||||
source=dict(repair._fields['x_fc_intake_source'].selection).get(source),
|
||||
user=intake_user.name,
|
||||
ref=session_ref,
|
||||
),
|
||||
)
|
||||
|
||||
return repair
|
||||
|
||||
@api.model
|
||||
def _wrap_internal_notes(self, item):
|
||||
notes = item.get('internal_notes') or ''
|
||||
summary = item.get('issue_summary') or ''
|
||||
if not (notes or summary):
|
||||
return False
|
||||
parts = []
|
||||
if summary:
|
||||
parts.append('<p><strong>Issue summary:</strong> %s</p>' % summary)
|
||||
if notes:
|
||||
parts.append('<p><strong>Notes:</strong> %s</p>' % notes)
|
||||
return ''.join(parts)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# ORIGINAL SO AUTO-LINK
|
||||
# ------------------------------------------------------------------
|
||||
@api.model
|
||||
def _auto_link_original_sale_order(self, repair):
|
||||
if not repair.partner_id or not repair.product_id:
|
||||
return
|
||||
SaleOrder = self.env['sale.order'].sudo()
|
||||
domain = [
|
||||
('partner_id', '=', repair.partner_id.id),
|
||||
('state', 'in', ('sale', 'done')),
|
||||
('order_line.product_id', '=', repair.product_id.id),
|
||||
]
|
||||
if repair.lot_id:
|
||||
domain.append(('order_line.lot_ids', 'in', repair.lot_id.id))
|
||||
candidate = SaleOrder.search(domain, order='date_order desc', limit=1)
|
||||
if candidate:
|
||||
repair.x_fc_original_sale_order_id = candidate
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# ANSWERS
|
||||
# ------------------------------------------------------------------
|
||||
@api.model
|
||||
def _create_answers(self, repair, answers):
|
||||
if not answers:
|
||||
return
|
||||
Answer = self.env['fusion.repair.intake.answer']
|
||||
for ans in answers:
|
||||
qid = ans.get('question_id')
|
||||
if not qid:
|
||||
continue
|
||||
Answer.create({
|
||||
'repair_id': repair.id,
|
||||
'question_id': qid,
|
||||
'value_char': ans.get('value_char'),
|
||||
'value_text': ans.get('value_text'),
|
||||
'value_selection': ans.get('value_selection'),
|
||||
'value_boolean': bool(ans.get('value_boolean')),
|
||||
'value_integer': int(ans.get('value_integer') or 0),
|
||||
'value_date': ans.get('value_date') or False,
|
||||
})
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# ACTIVITIES
|
||||
# ------------------------------------------------------------------
|
||||
@api.model
|
||||
def _schedule_activities(self, repair):
|
||||
"""Create the 4 intake activities described in the spec."""
|
||||
try:
|
||||
cs_callback_type = self.env.ref('fusion_repairs.mail_activity_type_cs_callback')
|
||||
tech_dispatch_type = self.env.ref('fusion_repairs.mail_activity_type_tech_dispatch')
|
||||
manager_review_type = self.env.ref('fusion_repairs.mail_activity_type_manager_review')
|
||||
except ValueError:
|
||||
_logger.warning('Repair activity types missing - skipping')
|
||||
return
|
||||
|
||||
# CS callback - always, intake user
|
||||
repair.activity_schedule(
|
||||
activity_type_id=cs_callback_type.id,
|
||||
summary=_('Call client back if any intake info was missing'),
|
||||
user_id=repair.x_fc_intake_user_id.id or self.env.uid,
|
||||
)
|
||||
|
||||
# Tech dispatch - assigned to responsible user, urgency-adjusted deadline
|
||||
deadline_days = {'safety': 0, 'urgent': 1, 'normal': 2}.get(repair.x_fc_urgency, 2)
|
||||
repair.activity_schedule(
|
||||
activity_type_id=tech_dispatch_type.id,
|
||||
summary=_('Assign a technician (urgency: %s)', repair.x_fc_urgency),
|
||||
user_id=repair.user_id.id or self.env.uid,
|
||||
date_deadline=fields.Date.context_today(self) + timedelta(days=deadline_days),
|
||||
)
|
||||
|
||||
# Manager review - only for third-party equipment
|
||||
if repair.x_fc_third_party_equipment:
|
||||
manager_group = self.env.ref(
|
||||
'fusion_repairs.group_fusion_repairs_manager',
|
||||
raise_if_not_found=False,
|
||||
)
|
||||
manager_user = self.env.user
|
||||
if manager_group:
|
||||
# res.groups has no .users field in Odoo 19;
|
||||
# query via res.users.all_group_ids (Odoo 19 renamed groups_id).
|
||||
candidate = self.env['res.users'].sudo().search(
|
||||
[('all_group_ids', 'in', manager_group.ids), ('active', '=', True)],
|
||||
limit=1,
|
||||
)
|
||||
if candidate:
|
||||
manager_user = candidate
|
||||
repair.activity_schedule(
|
||||
activity_type_id=manager_review_type.id,
|
||||
summary=_('Third-party equipment - manager awareness'),
|
||||
user_id=manager_user.id,
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# DISPATCH TASK
|
||||
# ------------------------------------------------------------------
|
||||
@api.model
|
||||
def _create_dispatch_task(self, repair):
|
||||
"""Create a draft fusion.technician.task for urgent / safety repairs.
|
||||
|
||||
Phase 1 simple approach: no date/technician assigned, dispatcher confirms.
|
||||
"""
|
||||
Task = self.env['fusion.technician.task'].sudo()
|
||||
try:
|
||||
vals = {
|
||||
'partner_id': repair.partner_id.id,
|
||||
'task_type': 'repair',
|
||||
'status': 'pending',
|
||||
'scheduled_date': fields.Date.context_today(self),
|
||||
'duration_hours': repair.x_fc_estimated_duration or 1.0,
|
||||
'x_fc_repair_order_id': repair.id,
|
||||
'description': repair.internal_notes or repair.name,
|
||||
}
|
||||
# technician_id is required on fusion.technician.task; we fall back to
|
||||
# the intake user. Dispatcher will reassign.
|
||||
vals['technician_id'] = (
|
||||
repair.user_id.id if repair.user_id and repair.user_id.x_fc_is_field_staff
|
||||
else self.env.uid
|
||||
)
|
||||
Task.create(vals)
|
||||
except Exception as e:
|
||||
_logger.warning('Failed to auto-create dispatch task for repair %s: %s',
|
||||
repair.name, e)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# EMAILS
|
||||
# ------------------------------------------------------------------
|
||||
@api.model
|
||||
def _send_intake_emails(self, repair):
|
||||
if not self._notifications_enabled():
|
||||
return
|
||||
# Client confirmation
|
||||
if repair.partner_id and repair.partner_id.email:
|
||||
try:
|
||||
self.env.ref('fusion_repairs.email_template_intake_received_client') \
|
||||
.send_mail(repair.id, force_send=False)
|
||||
except Exception as e:
|
||||
_logger.warning('Failed to send client intake email for %s: %s',
|
||||
repair.name, e)
|
||||
|
||||
# Office notification
|
||||
office_emails = self._office_emails(repair.company_id)
|
||||
if office_emails:
|
||||
try:
|
||||
tpl = self.env.ref('fusion_repairs.email_template_intake_received_office')
|
||||
tpl.with_context(default_email_to=','.join(office_emails)) \
|
||||
.send_mail(repair.id, force_send=False, email_values={
|
||||
'email_to': ','.join(office_emails),
|
||||
})
|
||||
except Exception as e:
|
||||
_logger.warning('Failed to send office intake email for %s: %s',
|
||||
repair.name, e)
|
||||
|
||||
@api.model
|
||||
def _notifications_enabled(self):
|
||||
ICP = self.env['ir.config_parameter'].sudo()
|
||||
return ICP.get_param('fusion_repairs.enable_email_notifications', 'True') == 'True'
|
||||
|
||||
@api.model
|
||||
def _office_emails(self, company):
|
||||
# Reuse the office notification recipients defined by fusion_claims.
|
||||
partners = company.sudo()
|
||||
recipients = getattr(partners, 'x_fc_office_notification_ids', False)
|
||||
if recipients:
|
||||
return [p.email for p in recipients if p.email]
|
||||
return []
|
||||
74
fusion_repairs/models/intake_template.py
Normal file
74
fusion_repairs/models/intake_template.py
Normal file
@@ -0,0 +1,74 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2024-2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class FusionRepairIntakeTemplate(models.Model):
|
||||
"""A reusable set of intake questions per medical equipment category.
|
||||
|
||||
Each template contains an ordered list of questions; the intake wizard
|
||||
(and sales-rep / client portals) render these dynamically with
|
||||
conditional show/hide based on prior answers.
|
||||
"""
|
||||
|
||||
_name = 'fusion.repair.intake.template'
|
||||
_description = 'Repair Intake Question Template'
|
||||
_order = 'sequence, name'
|
||||
|
||||
name = fields.Char(string='Template Name', required=True, translate=True)
|
||||
code = fields.Char(
|
||||
string='Code',
|
||||
help='Optional stable identifier for referencing this template from code/data.',
|
||||
)
|
||||
sequence = fields.Integer(string='Sequence', default=10)
|
||||
active = fields.Boolean(default=True)
|
||||
is_default = fields.Boolean(
|
||||
string='Default Fallback',
|
||||
help='Used when no template is explicitly configured for the selected category. '
|
||||
'Exactly one template should be flagged as default per company.',
|
||||
)
|
||||
description = fields.Html(string='Description', translate=True)
|
||||
|
||||
product_category_ids = fields.Many2many(
|
||||
'fusion.repair.product.category',
|
||||
'fusion_repair_intake_template_category_rel',
|
||||
'template_id',
|
||||
'category_id',
|
||||
string='Applies to Categories',
|
||||
help='Categories that automatically select this template during intake.',
|
||||
)
|
||||
|
||||
question_ids = fields.One2many(
|
||||
'fusion.repair.intake.question',
|
||||
'template_id',
|
||||
string='Questions',
|
||||
copy=True,
|
||||
)
|
||||
question_count = fields.Integer(
|
||||
compute='_compute_question_count',
|
||||
string='Question Count',
|
||||
)
|
||||
|
||||
company_id = fields.Many2one(
|
||||
'res.company',
|
||||
string='Company',
|
||||
default=lambda self: self.env.company,
|
||||
)
|
||||
|
||||
@api.depends('question_ids')
|
||||
def _compute_question_count(self):
|
||||
for tpl in self:
|
||||
tpl.question_count = len(tpl.question_ids)
|
||||
|
||||
def action_view_questions(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': self.name,
|
||||
'res_model': 'fusion.repair.intake.question',
|
||||
'view_mode': 'list,form',
|
||||
'domain': [('template_id', '=', self.id)],
|
||||
'context': {'default_template_id': self.id},
|
||||
}
|
||||
34
fusion_repairs/models/product_template.py
Normal file
34
fusion_repairs/models/product_template.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2024-2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
_inherit = 'product.template'
|
||||
|
||||
x_fc_repair_category_id = fields.Many2one(
|
||||
'fusion.repair.product.category',
|
||||
string='Repair Category',
|
||||
help='Medical equipment category - drives intake template selection and '
|
||||
'technician skills filter for repairs of this product.',
|
||||
)
|
||||
x_fc_warranty_months = fields.Integer(
|
||||
string='Warranty (Months)',
|
||||
default=12,
|
||||
help='Default warranty period for new units of this product. Used to auto-detect '
|
||||
'warranty status on repair intake (delivery date + warranty months >= today).',
|
||||
)
|
||||
x_fc_maintenance_interval_months = fields.Integer(
|
||||
string='Maintenance Interval (Months)',
|
||||
default=0,
|
||||
help='If > 0, delivering a unit of this product auto-creates a maintenance contract '
|
||||
'with this recurring interval. Phase 3 feature.',
|
||||
)
|
||||
x_fc_intake_template_id = fields.Many2one(
|
||||
'fusion.repair.intake.template',
|
||||
string='Intake Template Override',
|
||||
help='Optional override of the intake template normally chosen from the '
|
||||
'repair category. Leave empty to use category default.',
|
||||
)
|
||||
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,
|
||||
}
|
||||
49
fusion_repairs/models/repair_product_category.py
Normal file
49
fusion_repairs/models/repair_product_category.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2024-2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class FusionRepairProductCategory(models.Model):
|
||||
"""Medical equipment categories used to route repair intake and match skills."""
|
||||
|
||||
_name = 'fusion.repair.product.category'
|
||||
_description = 'Repair Product Category'
|
||||
_order = 'sequence, name'
|
||||
|
||||
name = fields.Char(string='Name', required=True, translate=True)
|
||||
code = fields.Char(
|
||||
string='Code',
|
||||
required=True,
|
||||
help='Stable identifier used by code (e.g. "stairlift"). Lowercase, no spaces.',
|
||||
)
|
||||
sequence = fields.Integer(string='Sequence', default=10)
|
||||
icon = fields.Char(
|
||||
string='Icon',
|
||||
default='fa-wrench',
|
||||
help='Font Awesome icon class shown next to the category in pickers.',
|
||||
)
|
||||
description = fields.Text(string='Description', translate=True)
|
||||
active = fields.Boolean(default=True)
|
||||
safety_critical = fields.Boolean(
|
||||
string='Safety-Critical',
|
||||
help='Categories where motor / mechanical issues warrant immediate escalation '
|
||||
'(stairlifts, porch lifts). Used by the AI self-check engine to skip '
|
||||
'self-help and force escalation when safety symptoms appear.',
|
||||
)
|
||||
|
||||
intake_template_id = fields.Many2one(
|
||||
'fusion.repair.intake.template',
|
||||
string='Default Intake Template',
|
||||
help='Default intake question set shown when this category is selected.',
|
||||
)
|
||||
|
||||
_sql_constraints = [
|
||||
('code_unique', 'unique(code)', 'Category code must be unique.'),
|
||||
]
|
||||
|
||||
@api.depends('name', 'code')
|
||||
def _compute_display_name(self):
|
||||
for cat in self:
|
||||
cat.display_name = cat.name or cat.code or ''
|
||||
64
fusion_repairs/models/res_config_settings.py
Normal file
64
fusion_repairs/models/res_config_settings.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2024-2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
# NOTE: res.config.settings only supports boolean/integer/float/char/
|
||||
# selection/many2one/datetime types per project Odoo 19 conventions.
|
||||
|
||||
fc_repairs_enable_email_notifications = fields.Boolean(
|
||||
string='Enable Repair Email Notifications',
|
||||
config_parameter='fusion_repairs.enable_email_notifications',
|
||||
default=True,
|
||||
help='Master toggle for automated repair-related emails to clients and office.',
|
||||
)
|
||||
|
||||
fc_repairs_outstanding_balance_threshold = fields.Float(
|
||||
string='Outstanding Balance Warning ($)',
|
||||
config_parameter='fusion_repairs.outstanding_balance_threshold',
|
||||
default=100.0,
|
||||
help='Show a warning banner during intake if the client has open invoices '
|
||||
'totalling more than this amount.',
|
||||
)
|
||||
|
||||
fc_repairs_duplicate_call_window_days = fields.Integer(
|
||||
string='Duplicate Call Window (Days)',
|
||||
config_parameter='fusion_repairs.duplicate_call_window_days',
|
||||
default=14,
|
||||
help='When the intake wizard finds an open repair from this many days back on '
|
||||
'the same phone number, it offers "add note to existing repair instead".',
|
||||
)
|
||||
|
||||
fc_repairs_variance_threshold_pct = fields.Integer(
|
||||
string='Pricing Variance Threshold (%)',
|
||||
config_parameter='fusion_repairs.variance_threshold_pct',
|
||||
default=20,
|
||||
help='If actual cost exceeds estimated cost by more than this percentage, '
|
||||
'invoicing is blocked until a manager reviews / a re-quote email is sent.',
|
||||
)
|
||||
|
||||
fc_repairs_variance_threshold_amount = fields.Float(
|
||||
string='Pricing Variance Threshold ($)',
|
||||
config_parameter='fusion_repairs.variance_threshold_amount',
|
||||
default=100.0,
|
||||
help='Absolute variance amount that also triggers re-quote (whichever hits first).',
|
||||
)
|
||||
|
||||
fc_repairs_client_portal_url = fields.Char(
|
||||
string='Public Client Portal URL Path',
|
||||
config_parameter='fusion_repairs.client_portal_url',
|
||||
default='/repair',
|
||||
help='URL path mentioned in voicemail greetings and printed on QR stickers. '
|
||||
'Phase 1 ships with the form at this path.',
|
||||
)
|
||||
|
||||
fc_repairs_client_portal_rate_limit_per_hour = fields.Integer(
|
||||
string='Client Portal Rate Limit (per hour, per IP)',
|
||||
config_parameter='fusion_repairs.client_portal_rate_limit_per_hour',
|
||||
default=10,
|
||||
)
|
||||
64
fusion_repairs/models/res_partner.py
Normal file
64
fusion_repairs/models/res_partner.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# -*- 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)
|
||||
57
fusion_repairs/models/res_users.py
Normal file
57
fusion_repairs/models/res_users.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2024-2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResUsers(models.Model):
|
||||
"""Extends res.users with fusion_repairs specific fields.
|
||||
|
||||
Reuses the existing x_fc_is_field_staff Boolean from fusion_tasks
|
||||
as the technician flag - do NOT recreate that field here.
|
||||
|
||||
All technician selectors in fusion_repairs use the same domain
|
||||
[('x_fc_is_field_staff', '=', True)] for consistency with fusion_tasks.
|
||||
"""
|
||||
|
||||
_inherit = 'res.users'
|
||||
|
||||
x_fc_repair_skills = fields.Many2many(
|
||||
'fusion.repair.product.category',
|
||||
'fusion_repair_user_skill_rel',
|
||||
'user_id',
|
||||
'category_id',
|
||||
string='Repair Skills',
|
||||
help='Medical equipment categories this user is qualified to service. '
|
||||
'Used by dispatcher to filter candidate technicians for a repair.',
|
||||
)
|
||||
|
||||
x_fc_tech_cost_rate = fields.Monetary(
|
||||
string='Tech Cost Rate (/h)',
|
||||
currency_field='company_currency_id',
|
||||
help='Internal cost per hour - used for repair margin calculation (Phase 4).',
|
||||
)
|
||||
|
||||
# On-call rotation - Phase 2 (simple priority-int approach).
|
||||
x_fc_on_call = fields.Boolean(
|
||||
string='On-Call Eligible',
|
||||
help='Tick if this user is eligible for the weekend / after-hours on-call rotation.',
|
||||
)
|
||||
x_fc_on_call_priority = fields.Integer(
|
||||
string='On-Call Priority',
|
||||
default=99,
|
||||
help='Lower number = paged first. The escalation cron picks the lowest priority '
|
||||
'available user when a safety repair is submitted after hours.',
|
||||
)
|
||||
x_fc_on_call_phone = fields.Char(
|
||||
string='On-Call Phone Override',
|
||||
help='Phone number to use for on-call SMS / calls. If empty, falls back to '
|
||||
'the user partner phone.',
|
||||
)
|
||||
|
||||
company_currency_id = fields.Many2one(
|
||||
'res.currency',
|
||||
related='company_id.currency_id',
|
||||
readonly=True,
|
||||
)
|
||||
42
fusion_repairs/models/technician_task.py
Normal file
42
fusion_repairs/models/technician_task.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2024-2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class FusionTechnicianTaskRepairs(models.Model):
|
||||
"""Adds the back-link from fusion.technician.task to repair.order so
|
||||
repairs and tasks share one timeline.
|
||||
"""
|
||||
|
||||
_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,
|
||||
)
|
||||
|
||||
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,
|
||||
}
|
||||
Reference in New Issue
Block a user