<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <!-- Form view of hotel folio -->
    <record id="view_hotel_folio_form" model="ir.ui.view">
        <field name="name">hotel.folio.form</field>
        <field name="model">hotel.folio</field>
        <field name="arch" type="xml">
            <form string="Hotel Folio">
                <header>
                    <button
                        name="action_confirm"
                        states="draft"
                        string="Confirm Sale"
                        class="btn-primary"
                        type="object"
                    />
                    <button
                        name="%(sale.action_view_sale_advance_payment_inv)d"
                        string="Create Invoice"
                        type="action"
                        class="btn-primary"
                        attrs="{'invisible': ['|',('state', 'in', ('draft','cancel','done')), ('invoice_status', 'in', 'invoiced')]}"
                    />
                    <button
                        name="action_cancel_draft"
                        states="cancel"
                        string="Set to Draft"
                        type="object"
                        icon="fa-check-square-o"
                        class="oe_highlight"
                    />
                    <button
                        name="action_cancel"
                        string="Cancel Folio"
                        states="sale"
                        type="object"
                        icon="fa-close"
                        class="oe_highlight"
                    />
                    <button
                        name="action_cancel"
                        string="Cancel Folio"
                        states="draft"
                        icon="fa-close"
                        type="object"
                        class="oe_highlight"
                    />
                    <button
                        name="action_done"
                        type="object"
                        string="Set to Done"
                        states="sale"
                        class="oe_highlight"
                        help="If a Hotel Folio is done, you cannot modify it manually anymore. However, you will still be able to invoice or deliver. This is used to freeze the Hotel Folio."
                    />
                    <field
                        name="state"
                        select="2"
                        widget="statusbar"
                        statusbar_visible="draft,sent,sale,done"
                    />
                </header>
                <sheet>
                    <label for="name" string="Folio Number" />
                    <h1>
                        <field name="name" colspan="4" />
                    </h1>
                    <group colspan="4" col="4">
                        <field name="date_order" readonly="1" />
                        <field name="warehouse_id" string="Branch" />
                        <field name="invoice_status" />
                        <field
                            name="hotel_invoice_id"
                            states='sale,done,cancel'
                            readonly="1"
                        />
                    </group>
                    <notebook>
                        <page name="folio" string="Folio">
                            <group colspan="4" col="4">
                                <field
                                    name="partner_id"
                                    string="Guest Name"
                                    required="1"
                                />
                                <field
                                    name="partner_invoice_id"
                                    domain="[('parent_id','=',partner_id)]"
                                />
                                <field name="pricelist_id" />
                                <field
                                    name="partner_shipping_id"
                                    domain="[('parent_id','=',partner_id)]"
                                />
                                <field name="company_id" invisible="1" />
                            </group>
                            <newline />
                            <group colspan="4" col="4" invisible="1">
                                <field name="checkin_date" />
                                <field name="checkout_date" />
                                <field name="duration" readonly="1" />
                                <field name="duration_dummy" invisible="1" />
                            </group>
                            <separator string="Room Lines" colspan="4" />
                            <field
                                name="room_line_ids"
                                colspan="4"
                                string="Room Line"
                                nolabel="1"
                                context="{'checkin':checkin_date,'checkout':checkout_date,'folio':context.get('folio')}"
                            >
                                <tree editable="bottom" string="Room Line">
                                    <field
                                        name="company_id"
                                        options="{'no_create': True}"
                                        groups="base.group_multi_company"
                                        invisible="1"
                                    />
                                    <field name="checkin_date" widget="date" />
                                    <field name="checkout_date" widget="date" />
                                    <field
                                        name="product_id"
                                        string="Room No"
                                        required="1"
                                        context="{'partner_id':parent.partner_id,'quantity':product_uom_qty,'pricelist':parent.pricelist_id,'uom':product_uom}"
                                        domain="[('isroom','=',True)]"
                                        options="{'no_open': True}"
                                    />
                                    <field name="name" />
                                    <field name="product_uom_qty" string="Duration" />
                                    <field
                                        name="product_uom_category_id"
                                        invisible="1"
                                    />
                                    <field
                                        name="product_uom"
                                        string="Rent(UOM)"
                                        attrs="{'readonly': [('state', 'in', ('sale','done', 'cancel'))]}"
                                        context="{'company_id': parent.company_id}"
                                        groups="uom.group_uom"
                                        options="{'no_open': True}"
                                    />
                                    <field name="price_unit" />
                                    <field
                                        domain="[('type_tax_use','=','sale'),('company_id','=',parent.company_id)]"
                                        name="tax_id"
                                        options="{'no_create': True}"
                                        widget="many2many_tags"
                                    />
                                    <field
                                        groups="product.group_discount_per_so_line"
                                        name="discount"
                                    />
                                    <field
                                        groups="account.group_show_line_subtotals_tax_excluded"
                                        name="price_subtotal"
                                        widget="monetary"
                                    />
                                    <field
                                        groups="account.group_show_line_subtotals_tax_included"
                                        name="price_total"
                                        widget="monetary"
                                    />
                                    <field invisible="1" name="currency_id" />
                                    <field invisible="1" name="state" />
                                </tree>
                            </field>
                            <separator string="Service Lines" colspan="4" />
                            <field
                                name="service_line_ids"
                                colspan="4"
                                string="Service Line"
                                nolabel="1"
                                context="{'checkin':checkin_date,'checkout':checkout_date}"
                            >
                                <tree editable="bottom" string="Service Line">
                                    <field
                                        name="product_id"
                                        required="1"
                                        domain="[('isservice','=',True)]"
                                        context="{'partner_id':parent.partner_id,'quantity':product_uom_qty,'pricelist':parent.pricelist_id,'hotel':parent.warehouse_id,'uom':product_uom}"
                                        options="{'no_open': True}"
                                    />
                                    <field name="name" />
                                    <field
                                        name="company_id"
                                        options="{'no_create': True}"
                                        groups="base.group_multi_company"
                                        invisible="1"
                                    />
                                    <field name="product_uom_qty" string="Duration" />
                                    <field
                                        name="product_uom_category_id"
                                        invisible="1"
                                    />
                                    <field
                                        name="product_uom"
                                        string="Rent(UOM)"
                                        attrs="{'readonly': [('state', 'in', ('sale','done', 'cancel'))]}"
                                        context="{'company_id': parent.company_id}"
                                        groups="uom.group_uom"
                                        options="{'no_open': True}"
                                    />
                                    <field name="price_unit" />
                                    <field
                                        domain="[('type_tax_use','=','sale'),('company_id','=',parent.company_id)]"
                                        name="tax_id"
                                        options="{'no_create': True}"
                                        widget="many2many_tags"
                                    />
                                    <field
                                        groups="product.group_discount_per_so_line"
                                        name="discount"
                                    />
                                    <field
                                        groups="account.group_show_line_subtotals_tax_excluded"
                                        name="price_subtotal"
                                        widget="monetary"
                                    />
                                    <field
                                        groups="account.group_show_line_subtotals_tax_included"
                                        name="price_total"
                                        widget="monetary"
                                    />
                                    <field invisible="1" name="currency_id" />
                                    <field name="state" invisible="1" />
                                </tree>
                            </field>
                            <group colspan="2" class="oe_subtotal_footer oe_right">
                                <field
                                    name="amount_untaxed"
                                    sum="Untaxed amount"
                                    widget='monetary'
                                />
                                <field name="amount_tax" widget='monetary' />
                                <div class="oe_subtotal_footer_separator oe_inline">
                                    <label for="amount_total" />
                                </div>
                                <field
                                    name="amount_total"
                                    nolabel="1"
                                    sum="Total amount"
                                    widget='monetary'
                                />
                            </group>
                            <div class="oe_clear" />
                        </page>
                        <page name='other_data' string="Other data">
                            <group>
                                <field name="user_id" />
                                <field
                                    name="hotel_policy"
                                    attrs="{'readonly':[('state','not in',('draft'))]}"
                                />
                                <field name="client_order_ref" />
                            </group>
                        </page>
                        <page name="invoice_history" string="History">
                            <separator string="Related invoices" colspan="4" />
                            <field name="invoice_ids" colspan="4" nolabel="1" />
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>
    <!-- Tree view of hotel folio -->
    <record id="view_hotel_folio_tree" model="ir.ui.view">
        <field name="name">hotel.folio.tree</field>
        <field name="model">hotel.folio</field>
        <field name="arch" type="xml">
            <tree string="Hotel Folio">
                <field name="checkin_date" />
                <field name="checkout_date" />
                <field name="name" />
                <field name="partner_id" />
                <field name="date_order" />
                <field name="state" />
                <field name="amount_total" sum="Total amount" />
            </tree>
        </field>
    </record>
    <!-- Calendar view of hotel folio -->
    <record id="hotel_folio_calendar_view" model="ir.ui.view">
        <field name="name">Hotel- Folios Calendar</field>
        <field name="model">hotel.folio</field>
        <field name="arch" type="xml">
            <calendar
                string="Folios"
                date_start="checkin_date"
                color="user_id"
                date_stop="checkout_date"
            >
                <field name="name" />
                <field name="partner_id" />
                <field name="duration" />
            </calendar>
        </field>
    </record>
    <!-- Search view of hotel folio -->
    <record id="view_hotel_folio_search" model="ir.ui.view">
        <field name="name">hotel.folio.search</field>
        <field name="model">hotel.folio</field>
        <field name="arch" type="xml">
            <search string="Tables Detail">
                <field name="partner_id" />
                <field name="name" filter_domain="[('name', 'ilike', self)]" />
                <filter
                    name="checkout_date"
                    string="Current Booking"
                    domain="[('checkout_date','&gt;=',datetime.datetime.now().replace(hour=0, minute=0, second=0)),('checkin_date','&lt;=',datetime.datetime.now().replace(hour=23, minute=59, second=59))]"
                />
                <group expand="0" string="Group By">
                    <filter
                        name="date_order"
                        string="Order By Month"
                        context="{'group_by':'date_order'}"
                    />
                    <filter
                        name="partner_id"
                        string="Customer"
                        context="{'group_by':'partner_id'}"
                    />
                </group>
            </search>
        </field>
    </record>
    <!--graph view of hotel folio -->
    <record id="view_hotel_folio_graph" model="ir.ui.view">
        <field name="name">view.hotel.folio.graph</field>
        <field name="model">hotel.folio</field>
        <field name="arch" type="xml">
            <graph type="bar">
                <field name="date_order" type="row" />
                <field name="amount_total" type="measure" />
            </graph>
        </field>
    </record>
</odoo>
