feat(fusion_repairs): sale.order smart buttons - repairs + maintenance
On the original purchase sale.order: - Repairs button (fa-wrench) lists all repair.order records where x_fc_original_sale_order_id = this SO - Maintenance button (fa-calendar-check-o) lists all fusion.repair.maintenance.contract records spawned from this SO - Both auto-hide when count is zero - Both gated by fusion_repairs.group_fusion_repairs_user Follows the count + action_view_* + oe_stat_button / statinfo pattern from fusion_claims/views/sale_order_views.xml line ~1176. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -15,4 +15,5 @@ from . import res_users
|
||||
from . import res_config_settings
|
||||
from . import technician_task
|
||||
from . import repair_order
|
||||
from . import sale_order
|
||||
from . import intake_service
|
||||
|
||||
80
fusion_repairs/models/sale_order.py
Normal file
80
fusion_repairs/models/sale_order.py
Normal file
@@ -0,0 +1,80 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2024-2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
|
||||
"""sale.order extensions: smart buttons that link an original purchase SO
|
||||
to its downstream repairs, maintenance contracts, and repair invoices.
|
||||
|
||||
Mirrors the count + action_view_* pattern from
|
||||
fusion_claims/views/sale_order_views.xml line ~1176.
|
||||
"""
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
x_fc_repair_order_ids = fields.One2many(
|
||||
'repair.order',
|
||||
'x_fc_original_sale_order_id',
|
||||
string='Repairs',
|
||||
)
|
||||
x_fc_repair_order_count = fields.Integer(
|
||||
compute='_compute_x_fc_repair_order_count',
|
||||
)
|
||||
|
||||
x_fc_maintenance_contract_ids = fields.One2many(
|
||||
'fusion.repair.maintenance.contract',
|
||||
'original_sale_order_id',
|
||||
string='Maintenance Contracts',
|
||||
)
|
||||
x_fc_maintenance_contract_count = fields.Integer(
|
||||
compute='_compute_x_fc_maintenance_contract_count',
|
||||
)
|
||||
|
||||
@api.depends('x_fc_repair_order_ids')
|
||||
def _compute_x_fc_repair_order_count(self):
|
||||
for so in self:
|
||||
so.x_fc_repair_order_count = len(so.x_fc_repair_order_ids)
|
||||
|
||||
@api.depends('x_fc_maintenance_contract_ids')
|
||||
def _compute_x_fc_maintenance_contract_count(self):
|
||||
for so in self:
|
||||
so.x_fc_maintenance_contract_count = len(so.x_fc_maintenance_contract_ids)
|
||||
|
||||
def action_view_repair_orders(self):
|
||||
self.ensure_one()
|
||||
if len(self.x_fc_repair_order_ids) == 1:
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': self.x_fc_repair_order_ids.name,
|
||||
'res_model': 'repair.order',
|
||||
'view_mode': 'form',
|
||||
'res_id': self.x_fc_repair_order_ids.id,
|
||||
}
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('Repairs from %(name)s', name=self.name),
|
||||
'res_model': 'repair.order',
|
||||
'view_mode': 'list,form',
|
||||
'domain': [('x_fc_original_sale_order_id', '=', self.id)],
|
||||
}
|
||||
|
||||
def action_view_maintenance_contracts(self):
|
||||
self.ensure_one()
|
||||
if len(self.x_fc_maintenance_contract_ids) == 1:
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': self.x_fc_maintenance_contract_ids.name,
|
||||
'res_model': 'fusion.repair.maintenance.contract',
|
||||
'view_mode': 'form',
|
||||
'res_id': self.x_fc_maintenance_contract_ids.id,
|
||||
}
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('Maintenance Contracts from %(name)s', name=self.name),
|
||||
'res_model': 'fusion.repair.maintenance.contract',
|
||||
'view_mode': 'list,form',
|
||||
'domain': [('original_sale_order_id', '=', self.id)],
|
||||
}
|
||||
Reference in New Issue
Block a user