<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Vista de lista de items de inventario -->
    <record id="view_skeen_inventario_item_tree" model="ir.ui.view">
        <field name="name">skeen.inventario.item.tree</field>
        <field name="model">skeen.inventario.item</field>
        <field name="arch" type="xml">
            <tree decoration-danger="stock_level=='out'" decoration-warning="stock_level in ('critical','low')" decoration-success="stock_level=='optimal'">
                <field name="name"/>
                <field name="sku"/>
                <field name="kind"/>
                <field name="category"/>
                <field name="unit"/>
                <field name="qty"/>
                <field name="qty_min"/>
                <field name="qty_optimal"/>
                <field name="cost"/>
                <field name="price"/>
                <field name="genera_monedero"/>
                <field name="inventory_value" sum="Total"/>
                <field name="stock_level" widget="badge"
                       decoration-danger="stock_level=='out'"
                       decoration-warning="stock_level in ('critical','low')"
                       decoration-success="stock_level=='optimal'"/>
                <field name="expiry_date"/>
            </tree>
        </field>
    </record>

    <!-- Vista de formulario de item -->
    <record id="view_skeen_inventario_item_form" model="ir.ui.view">
        <field name="name">skeen.inventario.item.form</field>
        <field name="model">skeen.inventario.item</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <group>
                        <group>
                            <field name="name"/>
                            <field name="sku"/>
                            <field name="kind"/>
                            <field name="category"/>
                            <field name="unit"/>
                            <field name="active"/>
                            <field name="genera_monedero"/>
                        </group>
                        <group>
                            <field name="qty"/>
                            <field name="qty_min"/>
                            <field name="qty_optimal"/>
                            <field name="cost"/>
                            <field name="price"/>
                            <field name="inventory_value" readonly="1"/>
                            <field name="stock_level" readonly="1"/>
                            <field name="expiry_date"/>
                            <field name="last_count_date" readonly="1"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="Movimientos">
                            <field name="move_ids" readonly="1">
                                <tree>
                                    <field name="date"/>
                                    <field name="type"/>
                                    <field name="qty"/>
                                    <field name="before_qty"/>
                                    <field name="after_qty"/>
                                    <field name="reference"/>
                                    <field name="notes"/>
                                </tree>
                            </field>
                        </page>
                        <page string="Notas">
                            <field name="notes"/>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Filtros de búsqueda -->
    <record id="view_skeen_inventario_item_search" model="ir.ui.view">
        <field name="name">skeen.inventario.item.search</field>
        <field name="model">skeen.inventario.item</field>
        <field name="arch" type="xml">
            <search>
                <field name="name"/>
                <field name="sku"/>
                <field name="category"/>
                <filter name="producto" string="Productos" domain="[('kind','=','producto')]"/>
                <filter name="consumible" string="Consumibles" domain="[('kind','=','consumible')]"/>
                <separator/>
                <filter name="out" string="Sin existencias" domain="[('stock_level','=','out')]"/>
                <filter name="low" string="Bajo mínimo" domain="[('stock_level','in',('critical','low'))]"/>
                <group expand="0" string="Agrupar por">
                    <filter name="group_category" string="Línea / Categoría" context="{'group_by':'category'}"/>
                    <filter name="group_kind" string="Tipo" context="{'group_by':'kind'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- Vista de lista de movimientos -->
    <record id="view_skeen_inventario_move_tree" model="ir.ui.view">
        <field name="name">skeen.inventario.move.tree</field>
        <field name="model">skeen.inventario.move</field>
        <field name="arch" type="xml">
            <tree>
                <field name="date"/>
                <field name="item_id"/>
                <field name="type" widget="badge"/>
                <field name="qty"/>
                <field name="before_qty"/>
                <field name="after_qty"/>
                <field name="reference"/>
                <field name="notes"/>
            </tree>
        </field>
    </record>

    <!-- Acciones -->
    <record id="action_skeen_inventario_item" model="ir.actions.act_window">
        <field name="name">Artículos</field>
        <field name="res_model">skeen.inventario.item</field>
        <field name="view_mode">tree,form</field>
    </record>

    <record id="action_skeen_inventario_move" model="ir.actions.act_window">
        <field name="name">Movimientos</field>
        <field name="res_model">skeen.inventario.move</field>
        <field name="view_mode">tree,form</field>
    </record>

    <!-- Menús (bajo el menú raíz SKEEN) -->
    <menuitem id="menu_skeen_inventario" name="Inventario" parent="skeen_citas.menu_skeen_root" sequence="40"/>
    <menuitem id="menu_skeen_inventario_items" name="Artículos" parent="menu_skeen_inventario"
              action="action_skeen_inventario_item" sequence="10"/>
    <menuitem id="menu_skeen_inventario_moves" name="Movimientos" parent="menu_skeen_inventario"
              action="action_skeen_inventario_move" sequence="20"/>
</odoo>
