<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Vista de lista de visitas -->
    <record id="view_skeen_visita_tree" model="ir.ui.view">
        <field name="name">skeen.visita.tree</field>
        <field name="model">skeen.visita</field>
        <field name="arch" type="xml">
            <tree decoration-info="state=='en_curso'" decoration-success="state=='completada'" decoration-danger="state=='cancelada'">
                <field name="name"/>
                <field name="partner_id"/>
                <field name="servicio_id"/>
                <field name="doctor_id"/>
                <field name="date_start"/>
                <field name="date_end"/>
                <field name="state" widget="badge" decoration-info="state=='en_curso'" decoration-success="state=='completada'" decoration-danger="state=='cancelada'"/>
            </tree>
        </field>
    </record>

    <!-- Vista de formulario de visitas -->
    <record id="view_skeen_visita_form" model="ir.ui.view">
        <field name="name">skeen.visita.form</field>
        <field name="model">skeen.visita</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <button name="action_complete" string="Completar" type="object" invisible="state != 'en_curso'" class="oe_highlight"/>
                    <button name="action_cancel" string="Cancelar" type="object" invisible="state != 'en_curso'"/>
                    <field name="state" widget="statusbar" statusbar_visible="en_curso,completada,cancelada"/>
                </header>
                <sheet>
                    <group>
                        <group>
                            <field name="name" readonly="1"/>
                            <field name="partner_id" options="{'no_create': True}"/>
                            <field name="cita_id" readonly="1"/>
                        </group>
                        <group>
                            <field name="servicio_id"/>
                            <field name="motivo"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="Clínica">
                            <field name="diagnostico"/>
                            <field name="tratamiento"/>
                            <field name="notas"/>
                        </page>
                        <page string="Insumos">
                            <field name="insumo_ids" readonly="state != 'en_curso'">
                                <tree editable="bottom">
                                    <field name="item_id" options="{'no_create': True}"/>
                                    <field name="qty"/>
                                    <field name="notes"/>
                                </tree>
                            </field>
                        </page>
                        <page string="Fotos / Documentos">
                            <field name="adjunto_ids" readonly="state == 'cancelada'">
                                <tree editable="bottom">
                                    <field name="kind"/>
                                    <field name="name"/>
                                    <field name="file" filename="name"/>
                                    <field name="notes"/>
                                    <field name="create_date"/>
                                </tree>
                            </field>
                        </page>
                        <page string="Datos">
                            <group>
                                <group>
                                    <field name="date_start"/>
                                    <field name="date_end"/>
                                </group>
                                <group>
                                    <field name="doctor_id"/>
                                    <field name="cosmetologa_id"/>
                                </group>
                            </group>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Vista de búsqueda de visitas -->
    <record id="view_skeen_visita_search" model="ir.ui.view">
        <field name="name">skeen.visita.search</field>
        <field name="model">skeen.visita</field>
        <field name="arch" type="xml">
            <search>
                <field name="name"/>
                <field name="partner_id"/>
                <filter name="en_curso" string="En Curso" domain="[('state', '=', 'en_curso')]"/>
                <filter name="completada" string="Completadas" domain="[('state', '=', 'completada')]"/>
                <filter name="cancelada" string="Canceladas" domain="[('state', '=', 'cancelada')]"/>
                <group expand="0" string="Agrupar por">
                    <filter name="group_partner" string="Paciente" context="{'group_by': 'partner_id'}"/>
                    <filter name="group_doctor" string="Médico" context="{'group_by': 'doctor_id'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- Acción para visitas -->
    <record id="action_skeen_visita_tree" model="ir.actions.act_window">
        <field name="name">Visitas</field>
        <field name="res_model">skeen.visita</field>
        <field name="view_mode">tree,form</field>
        <field name="search_view_id" ref="view_skeen_visita_search"/>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                ¡Aún no hay visitas registradas!
            </p>
        </field>
    </record>

    <!-- Acción para visitas de hoy -->
    <record id="action_skeen_visita_today" model="ir.actions.act_window">
        <field name="name">Visitas de Hoy</field>
        <field name="res_model">skeen.visita</field>
        <field name="view_mode">tree,form</field>
        <field name="search_view_id" ref="view_skeen_visita_search"/>
        <field name="domain">[('date_start', '&gt;=', context_today().strftime('%Y-%m-%d 00:00:00')), ('date_start', '&lt;=', context_today().strftime('%Y-%m-%d 23:59:59'))]</field>
        <field name="context">{'search_default_en_curso': 1}</field>
    </record>
</odoo>
