<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <!-- Hereda la vista de formulario de producto para añadir la pestaña de Análisis -->
        <record id="view_product_template_form_lims" model="ir.ui.view">
            <field name="name">product.template.form.lims</field>
            <field name="model">product.template</field>
            <field name="inherit_id" ref="product.product_template_form_view"/>
            <field name="arch" type="xml">
                <xpath expr="//notebook" position="inside">
                    <page string="Configuración de Análisis" name="analysis_config"
                          invisible="not is_analysis">
                        <group>
                            <group>
                                <field name="analysis_type"/>
                                <field name="required_sample_type_id"/>
                                <field name="sample_volume_ml" invisible="not required_sample_type_id"/>
                            </group>
                            <group>
                                <field name="technical_specifications"/>
                            </group>
                        </group>
                        <separator string="Parámetros del Análisis"/>
                        <field name="parameter_ids"
                               context="{'default_product_tmpl_id': id}">
                            <list editable="bottom">
                                <field name="sequence" widget="handle"/>
                                <field name="parameter_id" 
                                       options="{'no_create': True}"
                                       domain="[('active', '=', True)]"/>
                                <field name="parameter_code"/>
                                <field name="parameter_value_type"/>
                                <field name="parameter_unit"/>
                                <field name="required"/>
                                <field name="instructions" optional="show"/>
                            </list>
                        </field>
                    </page>
                </xpath>
                <!-- Añade el campo is_analysis cerca del nombre del producto para fácil acceso -->
                <xpath expr="//field[@name='name']" position="after">
                    <field name="is_analysis"/>
                </xpath>
            </field>
        </record>
        
        <!-- Vista de Lista para Productos de Análisis -->
        <record id="view_product_template_analysis_list" model="ir.ui.view">
            <field name="name">product.template.analysis.list</field>
            <field name="model">product.template</field>
            <field name="inherit_id" ref="product.product_template_tree_view"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='categ_id']" position="after">
                    <field name="is_analysis" optional="show"/>
                    <field name="analysis_type" optional="hide"/>
                    <field name="required_sample_type_id" optional="show"/>
                </xpath>
            </field>
        </record>
        
        <!-- Vista de Lista para Productos tipo Muestra -->
        <record id="view_product_template_sample_list" model="ir.ui.view">
            <field name="name">product.template.sample.list</field>
            <field name="model">product.template</field>
            <field name="inherit_id" ref="product.product_template_tree_view"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='categ_id']" position="after">
                    <field name="is_sample_type" optional="show"/>
                </xpath>
            </field>
        </record>
        
        <!-- Añadir is_sample_type al formulario de producto -->
        <record id="view_product_template_form_sample_type" model="ir.ui.view">
            <field name="name">product.template.form.sample.type</field>
            <field name="model">product.template</field>
            <field name="inherit_id" ref="product.product_template_form_view"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='is_analysis']" position="after">
                    <field name="is_sample_type"/>
                </xpath>
            </field>
        </record>
    </data>
</odoo>
