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:
@@ -81,6 +81,7 @@ Copyright (C) 2024-2026 Nexa Systems Inc. All rights reserved.
|
|||||||
'views/repair_warranty_views.xml',
|
'views/repair_warranty_views.xml',
|
||||||
'views/maintenance_contract_views.xml',
|
'views/maintenance_contract_views.xml',
|
||||||
'views/repair_order_views.xml',
|
'views/repair_order_views.xml',
|
||||||
|
'views/sale_order_views.xml',
|
||||||
'views/res_partner_views.xml',
|
'views/res_partner_views.xml',
|
||||||
'views/res_users_views.xml',
|
'views/res_users_views.xml',
|
||||||
'views/res_config_settings_views.xml',
|
'views/res_config_settings_views.xml',
|
||||||
|
|||||||
@@ -15,4 +15,5 @@ from . import res_users
|
|||||||
from . import res_config_settings
|
from . import res_config_settings
|
||||||
from . import technician_task
|
from . import technician_task
|
||||||
from . import repair_order
|
from . import repair_order
|
||||||
|
from . import sale_order
|
||||||
from . import intake_service
|
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)],
|
||||||
|
}
|
||||||
31
fusion_repairs/views/sale_order_views.xml
Normal file
31
fusion_repairs/views/sale_order_views.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="view_sale_order_form_inherit_fusion_repairs" model="ir.ui.view">
|
||||||
|
<field name="name">sale.order.form.inherit.fusion_repairs</field>
|
||||||
|
<field name="model">sale.order</field>
|
||||||
|
<field name="inherit_id" ref="sale.view_order_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//div[hasclass('oe_button_box')]" position="inside">
|
||||||
|
<button name="action_view_repair_orders"
|
||||||
|
type="object"
|
||||||
|
class="oe_stat_button"
|
||||||
|
icon="fa-wrench"
|
||||||
|
invisible="x_fc_repair_order_count == 0"
|
||||||
|
groups="fusion_repairs.group_fusion_repairs_user">
|
||||||
|
<field name="x_fc_repair_order_count" widget="statinfo" string="Repairs"/>
|
||||||
|
</button>
|
||||||
|
<button name="action_view_maintenance_contracts"
|
||||||
|
type="object"
|
||||||
|
class="oe_stat_button"
|
||||||
|
icon="fa-calendar-check-o"
|
||||||
|
invisible="x_fc_maintenance_contract_count == 0"
|
||||||
|
groups="fusion_repairs.group_fusion_repairs_user">
|
||||||
|
<field name="x_fc_maintenance_contract_count"
|
||||||
|
widget="statinfo" string="Maintenance"/>
|
||||||
|
</button>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user