<data><!-- HEADER RELSUM: workflow stage + transiciones rápidas -->
            <xpath expr="//sheet" position="before">

                <header>
                    <button name="action_stage_diagnostic" string="→ Diagnóstico" type="object" class="btn-primary" invisible="relsum_workflow_stage != 'received'"/>
                    <button name="action_stage_quoted" string="→ Presupuestada" type="object" class="btn-primary" invisible="relsum_workflow_stage not in ['received','diagnostic']"/>
                    <button name="action_stage_in_progress" string="→ En reparación" type="object" class="btn-primary" invisible="relsum_workflow_stage not in ['quoted','diagnostic']"/>
                    <button name="action_stage_ready" string="→ Lista entrega" type="object" class="btn-primary" invisible="relsum_workflow_stage != 'in_progress'"/>
                    <button name="action_stage_delivered" string="→ Entregada" type="object" class="btn-primary" invisible="relsum_workflow_stage != 'ready'"/>
                    <button name="action_stage_invoiced" string="→ Facturada" type="object" class="btn-primary" invisible="relsum_workflow_stage not in ['delivered','ready']"/>
                    <field name="relsum_workflow_stage" widget="statusbar" statusbar_visible="received,diagnostic,quoted,in_progress,ready,delivered,invoiced"/>
                </header>

                <div class="oe_button_box" name="button_box">

                    <button type="object" name="action_view_sale_orders" class="oe_stat_button" icon="fa-shopping-cart">
                        <field name="sale_order_count" widget="statinfo" string="Presupuestos"/>
                    </button>

                    <button type="object" name="action_view_purchase_orders" class="oe_stat_button" icon="fa-truck">
                        <field name="purchase_order_count" widget="statinfo" string="Compras"/>
                    </button>

                    <button type="object" name="action_view_pickings" class="oe_stat_button" icon="fa-exchange">
                        <field name="picking_count" widget="statinfo" string="Albaranes"/>
                    </button>

                    <button type="object" name="action_view_invoices" class="oe_stat_button" icon="fa-pencil-square-o">
                        <field name="invoice_count" widget="statinfo" string="Facturas"/>
                    </button>

                    <button type="object" name="action_view_technical_reports" class="oe_stat_button" icon="fa-file-text-o">
                        <field name="technical_report_count" widget="statinfo" string="Informes"/>
                    </button>

                    <button type="object" name="action_view_petty_cash" class="oe_stat_button" icon="fa-money">
                        <field name="petty_cash_ref_count" widget="statinfo" string="Cajas RH"/>
                    </button>

                </div>

            </xpath>

            <!-- ATAJOS "CREAR X DESDE LA OT" (justo después del título, antes de los datos) -->
            <xpath expr="//sheet/group[1]" position="before">
                <div class="o_row" style="margin-bottom: 8px;">
                    <button name="action_create_machine" string="+ Máquina" type="object" class="btn-secondary" invisible="relsum_machine_id" help="Crea la máquina del cliente (la asocia a esta OT)"/>
                    <button name="action_create_sale" string="+ Presupuesto" type="object" class="btn-secondary" help="Crea un nuevo presupuesto pre-vinculado a esta OT"/>
                    <button name="action_create_purchase" string="+ Pedido proveedor" type="object" class="btn-secondary" help="Crea un pedido a proveedor asociado a esta OT"/>
                    <button name="action_create_picking" string="+ Albarán" type="object" class="btn-secondary" help="Crea un albarán de salida al cliente"/>
                    <button name="action_create_invoice" string="+ Factura" type="object" class="btn-secondary" invisible="not sale_order_id and sale_order_count == 0" help="Crea la factura desde el presupuesto vinculado"/>
                </div>
            </xpath>

            <!-- CABECERA: identificación + presupuesto principal + máquina -->
            <xpath expr="//sheet/group/group[1]" position="inside">

                <field name="sale_order_id"/>
                <field name="relsum_machine_id"/>

            </xpath>

            <!-- NOTEBOOK: tabs limpios alineados con checklist -->
            <xpath expr="//notebook" position="inside">

                <!-- COMERCIAL: presupuestos relacionados (puntos 2, 3) -->
                <page string="Comercial" name="comercial">
                    <group>
                        <group>
                            <field name="sale_order_ids" widget="many2many_tags"/>
                        </group>
                    </group>
                </page>

                <!-- DATOS TÉCNICOS: derivados de la máquina (punto 1) -->
                <page string="Datos Técnicos" name="datos_tecnicos">
                    <div invisible="relsum_machine_id" class="alert alert-info" role="alert">
                        <p>Esta OT aún no tiene máquina asignada. Selecciónala en la cabecera.</p>
                    </div>
                    <group invisible="not relsum_machine_id">
                        <group string="Identificación">
                            <field name="machine_marca"/>
                            <field name="machine_tipo"/>
                            <field name="machine_numero_serie"/>
                            <field name="machine_planta_id"/>
                        </group>
                        <group string="Características eléctricas">
                            <field name="machine_voltios"/>
                            <field name="machine_kva"/>
                            <field name="machine_rpm"/>
                            <field name="machine_amperios"/>
                            <field name="machine_hz"/>
                        </group>
                    </group>
                </page>

                <!-- ALBARANES (punto 5) -->
                <page string="Albaranes" name="albaranes">
                    <field name="picking_ids">
                        <list>
                            <field name="name"/>
                            <field name="partner_id"/>
                            <field name="scheduled_date"/>
                            <field name="state"/>
                            <field name="tipo_albaran"/>
                            <field name="legacy_reference" optional="hide"/>
                        </list>
                    </field>
                </page>

                <!-- COMPRAS (punto 4) -->
                <page string="Compras" name="compras">
                    <field name="purchase_order_ids">
                        <list>
                            <field name="name"/>
                            <field name="partner_id"/>
                            <field name="date_order"/>
                            <field name="state"/>
                            <field name="amount_total"/>
                        </list>
                    </field>
                </page>

                <!-- PARTES DE TRABAJO (punto 4) -->
                <page string="Partes de trabajo" name="partes_trabajo">
                    <group>
                        <group string="Resumen">
                            <field name="timesheet_hours" readonly="1"/>
                        </group>
                        <group string="Contabilidad analítica" groups="analytic.group_analytic_accounting">
                            <field name="analytic_account_id"/>
                        </group>
                    </group>
                    <field name="timesheet_ids" context="{'default_repair_order_id': id}">
                        <list editable="bottom">
                            <field name="date"/>
                            <field name="employee_id" optional="show"/>
                            <field name="name"/>
                            <field name="unit_amount" string="Horas"/>
                        </list>
                    </field>
                </page>

                <!-- INFORMES TÉCNICOS (punto 6) -->
                <page string="Informes técnicos" name="informes">
                    <field name="technical_report_ids" context="{'default_repair_order_id': id}">
                        <list editable="bottom">
                            <field name="name" readonly="1"/>
                            <field name="report_type"/>
                            <field name="sequence_number"/>
                            <field name="year"/>
                            <field name="date"/>
                        </list>
                    </field>
                </page>

                <!-- CAJA RH (punto 7) -->
                <page string="Caja RH" name="caja_rh">
                    <field name="petty_cash_ref_ids" context="{'default_repair_order_id': id}">
                        <list editable="bottom">
                            <field name="name"/>
                            <field name="date"/>
                            <field name="amount"/>
                            <field name="notes"/>
                        </list>
                    </field>
                </page>

                <!-- DATOS LEGACY MIGRACIÓN (oculto excepto admin)
                     Se mantienen los x_* en BD para no perder los datos
                     importados del Excel. Se eliminarán definitivamente
                     una vez completado el re-link a entidades reales. -->
                <page string="Datos legacy (migración)" name="legacy" groups="base.group_no_one">
                    <group>
                        <group string="Crosswalk legacy">
                            <field name="x_numero_ot" readonly="1"/>
                            <field name="x_presupuesto" readonly="1"/>
                            <field name="x_numero_pedido" readonly="1"/>
                        </group>
                        <group string="Datos máquina (importados)">
                            <field name="x_marca" readonly="1"/>
                            <field name="x_tipo_maquina" readonly="1"/>
                            <field name="x_numero_serie" readonly="1"/>
                            <field name="x_planta" readonly="1"/>
                            <field name="x_kva" readonly="1"/>
                            <field name="x_voltios" readonly="1"/>
                            <field name="x_rpm" readonly="1"/>
                            <field name="x_amperios" readonly="1"/>
                            <field name="x_hz" readonly="1"/>
                        </group>
                    </group>
                    <group string="Texto libre legacy">
                        <field name="x_albaran" readonly="1"/>
                        <field name="x_albaran_nota" readonly="1"/>
                        <field name="x_pedido_proveedor" readonly="1"/>
                        <field name="x_comentarios" readonly="1"/>
                    </group>
                </page>

            </xpath>

        </data>