<?xml version="1.0"?>
<odoo>

    <record id="hotel_reservation_view_form" model="ir.ui.view">
        <field name="model">hotel.reservation</field>
        <field name="inherit_id" ref="hotel.hotel_reservation_view_form" />
        <field name="arch" type="xml">
            <xpath expr="//field[@name='channel_type']" position="after">
                <field name="ota_reservation_id" attrs='{"readonly": [("able_to_modify_channel","=",False)], "invisible":[("channel_type","!=", "web")]}' string="OTA code"/>
                <field name="ota_id" readonly="True" attrs='{"invisible":[("channel_type","!=", "web")]}' string="OTA"/>
            </xpath>
            <xpath expr="//field[@name='shared_folio']" position="before">
                <group colspan="6" col="6">
                    <field name="is_from_ota" readonly="True" invisible="True"/>
                </group>
            </xpath>
            <xpath expr="//field[@name='partner_internal_comment']" position="after">
                <field name="able_to_modify_channel" invisible="True"/>
            </xpath>
            <xpath expr="//page[@name='days']" position="after">
                <page name="connector" string="Channel Connector" groups="connector.group_connector_manager">
                    <group string="Hotel Channel Bindings">
                        <field name="channel_bind_ids" nolabel="1">
                            <tree>
                                <field name="backend_id"/>
                            </tree>
                        </field>
                    </group>
                </page>
            </xpath>
            <!-- ALLOW ONLY-READ -->
            <xpath expr="//field[@name='adults']" position="attributes">
                <attribute name="attrs">{'readonly': [('is_from_ota','=',True),('able_to_modify_channel','=',False)]}</attribute>
            </xpath>
            <xpath expr="//field[@name='room_type_id']" position="attributes">
                <attribute name="attrs">{'readonly': [('is_from_ota','=',True),('able_to_modify_channel','=',False)]}</attribute>
            </xpath>
            <xpath expr="//field[@name='children']" position="attributes">
                <attribute name="attrs">{'readonly': [('is_from_ota','=',True),('able_to_modify_channel','=',False)]}</attribute>
            </xpath>
            <xpath expr="//field[@name='checkin']" position="attributes">
                <attribute name="attrs">{'readonly': [('is_from_ota','=',True),('able_to_modify_channel','=',False)]}</attribute>
            </xpath>
            <xpath expr="//field[@name='checkout']" position="attributes">
                <attribute name="attrs">{'readonly': [('is_from_ota','=',True),('able_to_modify_channel','=',False)]}</attribute>
            </xpath>
            <xpath expr="//notebook/page[@name='days']/field[@name='reservation_line_ids']/tree/field[@name='price']" position="attributes">
                <attribute name="attrs">{'readonly': [('parent.is_from_ota','=',True),('parent.able_to_modify_channel','=',False)]}</attribute>
                <attribute name="force_save">True</attribute>
            </xpath>
        </field>
    </record>


    <!-- Tree view of hotel reservation -->
    <record model="ir.ui.view" id="view_hotel_reservation_tree">
        <field name="model">hotel.reservation</field>
        <field name="inherit_id" ref="hotel.hotel_reservation_view_tree" />
        <field name="arch" type="xml">
            <xpath expr="//field[@name='checkout']" position="after">
                <field name="ota_id"/>
                <field name="ota_reservation_id"/>
            </xpath>
            <xpath expr="//field[@name='checkout']" position="after">
                <field name="is_from_ota" invisible="1"/>
            </xpath>
            <xpath expr="//field[@name='checkout']" position="attributes">
                <attribute name="attrs">{'readonly': [('is_from_ota', '!=', False)]}</attribute>
            </xpath>
            <xpath expr="//field[@name='checkin']" position="attributes">
                <attribute name="attrs">{'readonly': [('is_from_ota', '!=', False)]}</attribute>
            </xpath>
        </field>
    </record>

    <!-- Search view of hotel reservation -->
    <record model="ir.ui.view" id="hotel_reservation_view_search">
        <field name="model">hotel.reservation</field>
        <field name="inherit_id" ref="hotel.hotel_reservation_view_search" />
        <field name="arch" type="xml">
            <xpath expr="//field[@name='folio_id']" position="after">
                <field name="ota_reservation_id" string="Id on OTA"/>
                <field name="ota_id" string="OTA"/>
                <field name="external_id" />
            </xpath>
            <xpath expr="//group" position="inside">
                <!-- filter name="origin" string="Origin" domain="[]"
                        context="{'group_by':'origin_sale'}"/-->
            </xpath>
        </field>
    </record>

     <!--graph view of hotel reservation -->
    <record id="hotel_reservation_view_graph" model="ir.ui.view">
        <field name="name">view.hotel.reservation.graph</field>
        <field name="model">hotel.reservation</field>
        <field name="arch" type="xml">
            <graph type="bar">
                <!-- field name="origin_sale" string="Origin"/-->
                <field name="price_total" type="measure" />
            </graph>
        </field>
    </record>

    <!--pivot view of hotel reservation -->
    <record id="hotel_reservation_view_pivot_graph" model="ir.ui.view">
        <field name="name">view.hotel.pivot.graph</field>
        <field name="model">hotel.reservation</field>
        <field name="arch" type="xml">
            <pivot string="Reservations">
                <field name="checkin" type="row" />
                <!-- field name="origin_sale" string="Origin" type="col" /-->
                <field name="price_total" string="Price" type="measure" />
            </pivot>
        </field>
    </record>

</odoo>
