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

        <record id="view_media_unit_tree" model="ir.ui.view">
            <field name="name">op.media.unit.list</field>
            <field name="model">op.media.unit</field>
            <field name="priority" eval="8"/>
            <field name="arch" type="xml">
                <list string="Media Units">
                    <field name="name"/>
                    <field name="media_id"/>
                    <field name="barcode"/>
                    <field name="state" string="Status"/>
                </list>
            </field>
        </record>

        <record id="view_media_unit_form" model="ir.ui.view">
            <field name="name">op.media.unit.form</field>
            <field name="model">op.media.unit</field>
            <field name="priority" eval="8"/>
            <field name="arch" type="xml">
                <form string="Media Units">
                    <header groups="base.group_user">
                        <button name="%(issue_media_act)d" string="Issue Media"
                                type="action"
                                context="{'default_media_id': media_id, 'default_media_unit_id': id}"
                                invisible= "state != 'available'"
                                class="oe_highlight" groups="openeducat_library.group_op_library"/>
                        <button name="%(return_media_act)d" string="Return Media"
                                type="action"
                                context="{'default_media_id': media_id, 'default_media_unit_id': id}"
                                invisible= "state != 'issue'"
                                class="oe_highlight" groups="openeducat_library.group_op_library"/>
                        <field name="state" widget="statusbar" statusbar_visible="available,issue,reserve,lost"
                               statusbar_colors='{"r":"red"}'/>
                    </header>
                    <sheet>
                        <field name="active" invisible="True"/>
                        <widget name="web_ribbon" title="Archived" bg_color="bg-danger"
                                invisible="active == True"/>
                        <group>
                            <group>
                                <field name="name"/>
                                <field name="barcode" readonly="1"/>
                            </group>
                            <group>
                                <field name="media_id"/>
                                <field name="media_type_id"/>
                            </group>
                        </group>
                        <notebook>
                            <page name="movements" string="Movements" >
                                <field name="movement_lines" nolabel='1'>
                                    <list create='false' editable="top">
                                        <field name="library_card_id"/>
                                        <field name="partner_id"/>
                                        <field name="media_id"/>
                                        <field name="media_unit_id"/>
                                        <field name="issued_date"/>
                                        <field name="return_date"/>
                                        <field name="actual_return_date"/>
                                        <field name="state"/>
                                        <field name="invoice_id"/>
                                    </list>
                                </field>
                            </page>
                        </notebook>
                    </sheet>
                    <chatter/>
                </form>
            </field>
        </record>

        <record id="view_media_unit_search" model="ir.ui.view">
            <field name="name">op.media.unit.search</field>
            <field name="model">op.media.unit</field>
            <field name="priority" eval="8"/>
            <field name="arch" type="xml">
                <search string="media Units">
                    <field name="name"/>
                    <field name="barcode"/>
                    <field name="media_id"/>
                    <newline/>
                    <group >
                        <filter string="Media" name="group_by_lbr_media_unit_media"
                                domain="[]" context="{'group_by':'media_id'}"/>
                        <filter string="State" name="group_by_lbr_media_unit_state"
                                domain="[]" context="{'group_by':'state'}"/>
                        <filter string="Archived" name="inactive"
                                domain="[('active', '=', False)]"/>
                    </group>
                </search>
            </field>
        </record>

        <record id="view_op_media_unit_pivot" model="ir.ui.view">
            <field name="name">op.media.unit.pivot</field>
            <field name="model">op.media.unit</field>
            <field name="arch" type="xml">
                <pivot string="Media Units">
                    <field name="media_id" type="col"/>
                    <field name="name" type="row"/>
                </pivot>
            </field>
        </record>

        <record id="view_op_media_unit_graph" model="ir.ui.view">
            <field name="name">op.media.unit.graph</field>
            <field name="model">op.media.unit</field>
            <field name="arch" type="xml">
                <graph string="Media Units" type="pie">
                    <field name="name"/>
                    <field name="media_id"/>
                </graph>
            </field>
        </record>

        <record model="ir.actions.act_window" id="act_open_media_unit_view">
            <field name="name">Media Units</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">op.media.unit</field>
            <field name="binding_view_types">form</field>
            <field name="view_mode">list,form,pivot,graph</field>
            <field name="domain">[]</field>
            <field name="path">media-unit</field>
            <field name="context">{}</field>
        </record>

        <record model="ir.actions.act_window.view" id="act_open_media_unit_view_form">
            <field name="act_window_id" ref="act_open_media_unit_view"/>
            <field name="sequence" eval="20"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_media_unit_form"/>
        </record>

        <record model="ir.actions.act_window.view" id="act_open_media_unit_view_tree">
            <field name="act_window_id" ref="act_open_media_unit_view"/>
            <field name="sequence" eval="10"/>
            <field name="view_mode">list</field>
            <field name="view_id" ref="view_media_unit_tree"/>
        </record>

</odoo>
