<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>

        <!-- Vista de Lista para Muestras de Laboratorio -->
        <record id="view_lab_sample_list" model="ir.ui.view">
            <field name="name">lab.sample.list</field>
            <field name="model">stock.lot</field>
            <field name="arch" type="xml">
                <list string="Muestras de Laboratorio">
                    <field name="name" string="Código"/>
                    <field name="patient_id" string="Paciente"/>
                    <field name="product_id" string="Tipo de Muestra"/>
                    <field name="sample_type_product_id" string="Tipo de Muestra"/>
                    <field name="collection_date" string="Fecha de Recolección"/>
                    <field name="collector_id" string="Recolectado por"/>
                    <field name="container_type" optional="hide" string="Tipo Contenedor (Obsoleto)"/>
                    <field name="state" string="Estado" decoration-success="state == 'analyzed'" decoration-info="state == 'in_process'" decoration-muted="state == 'stored' or state == 'disposed'" widget="badge"/>
                </list>
            </field>
        </record>

        <!-- Vista de Formulario para Muestras de Laboratorio -->
        <record id="view_lab_sample_form" model="ir.ui.view">
            <field name="name">lab.sample.form</field>
            <field name="model">stock.lot</field>
            <field name="arch" type="xml">
                <form string="Muestra de Laboratorio">
                    <header>
                        <button name="action_collect" string="Recolectar" type="object" class="oe_highlight" invisible="state != 'pending_collection'"/>
                        <button name="action_receive" string="Recibir" type="object" class="oe_highlight" invisible="state != 'collected'"/>
                        <button name="action_start_analysis" string="Iniciar Análisis" type="object" class="oe_highlight" invisible="state != 'received'"/>
                        <button name="action_complete_analysis" string="Completar Análisis" type="object" class="oe_highlight" invisible="state != 'in_process'"/>
                        <button name="action_store" string="Almacenar" type="object" invisible="state not in ['analyzed', 'in_process', 'received']"/>
                        <button name="action_dispose" string="Desechar" type="object" invisible="state == 'disposed'"/>
                        <field name="state" widget="statusbar" statusbar_visible="pending_collection,collected,received,in_process,analyzed,stored"/>
                    </header>
                    <sheet>
                        <div class="oe_title">
                            <h1>
                                <field name="name"/>
                            </h1>
                        </div>
                        <group>
                            <group>
                                <field name="patient_id" readonly="state not in ['pending_collection', 'collected']"/>
                                <field name="doctor_id" readonly="state not in ['pending_collection', 'collected']"/>
                                <field name="origin" readonly="1"/>
                                <field name="request_id" 
                                    readonly="state not in ['pending_collection', 'collected']"
                                    domain="[('is_lab_request', '=', True), '|', ('partner_id', '=', False), ('partner_id', '=', patient_id)]"/>
                                <field name="product_id"
                                    string="Sample Type"
                                    domain="[('is_sample_type', '=', True)]"
                                    options="{'no_create': True, 'no_create_edit': True}"
                                    readonly="state not in ['pending_collection', 'collected']"/>
                            </group>
                            <group>
                                <field name="barcode" readonly="1"/>
                                <field name="collection_date" readonly="state not in ['pending_collection', 'collected']"/>
                                <field name="collector_id" readonly="state not in ['pending_collection', 'collected']"/>
                                <field name="sample_type_product_id" 
                                    readonly="state not in ['pending_collection', 'collected']"
                                    options="{'no_create': True, 'no_create_edit': True}"/>
                                <field name="volume_ml" readonly="1"/>
                                <field name="analysis_names" readonly="1"/>
                                <field name="container_type" 
                                    readonly="state not in ['pending_collection', 'collected']"
                                    invisible="sample_type_product_id != False"/>
                            </group>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>

    </data>
</odoo>
