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

    <!-- Action for hotel reservation -->
    <record model="ir.actions.act_window" id="open_hotel_reservation_form_tree_all">
        <field name="name">Hotel Reservation</field>
        <field name="res_model">hotel.reservation</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form,graph,pivot</field>
    </record>

    <menuitem name="Reservation Rooms" id="menu_open_hotel_reservation_form_tree_all"
        action="open_hotel_reservation_form_tree_all" sequence="10" parent="menu_all_folio"/>

     <!--=== Hotel Reservation ==== -->
    <!-- Form view of hotel reservation -->
   <record model="ir.ui.view" id="view_hotel_reservation_form">
        <field name="name">hotel.reservation.form</field>
        <field name="model">hotel.reservation</field>
        <field name="arch" type="xml">
            <form string="Reservation" >
                <header>
                    <field name="splitted" invisible="True" />
                    <field name="parent_reservation" invisible="True" />
                    <field name="has_confirmed_reservations_to_send" invisible="1" />
                    <field name="has_cancelled_reservations_to_send" invisible="1" />
                    <field name="has_checkout_to_send" invisible="1" />
                    <button name="send_reservation_mail" type="object" string="Send Confirmation Email"
                       attrs="{'invisible': [('has_confirmed_reservations_to_send', '=', False)]}" class="oe_highlight"/>
                    <button name="send_cancel_mail" type="object" string="Send Cancel Email"
                       attrs="{'invisible': [('has_cancelled_reservations_to_send', '=', False)]}" class="oe_highlight"/>
                    <button name="send_exit_mail" type="object" string="Send Exit Email"
                       attrs="{'invisible': [('has_checkout_to_send', '=', False)]}" class="oe_highlight"/>

                    <button name="send_reservation_mail" type="object" string="Send Reservation Email" states="confirm" class="oe_highlight"/>
                    <button name="confirm" string="Confirm" class="oe_highlight"
                        type="object"
                        attrs="{'invisible':[('state','not in',('draft','cancelled'))]}"
                    />
                    <button name="action_cancel" string="Cancel Reservation"
                        class="oe_highlight" type="object"
                        attrs="{'invisible':['|',('folio_id', '=', False),('state','not in',('confirm','booking'))]}"
                    />
                    <button name="action_reservation_checkout" string="Done"
                        states="booking" class="oe_highlight"
                        type="object"
                    />
                    <button name="draft" string="Set to Draft"
                        states="cancelled" class="oe_highlight"
                        type="object"
                    />
                    <button name="%(action_hotel_split_reservation)d" string="Split"
                        type="action" class="oe_highlight"
                        icon="fa-cut"
                        attrs="{'invisible':['|',('folio_id', '=', False),('state','not in',('draft','confirm','booking'))]}"
                    />
                    <button name="unify" string="Unify"
                        type="object" class="oe_highlight"
                        icon="fa-compress"
                        attrs="{'invisible':[('splitted', '=', False)]}"
                    />
                    <label for="preconfirm"
                        string="Autoconfirm"
                        attrs="{'invisible':[('folio_id', '!=', False)]}"
                    />
                    <span name="preconfirm" attrs="{'invisible':[('folio_id', '!=', False)]}">
                        <field name="preconfirm" />
                    </span>
                    <button name="open_master" string="Open Master" type="object" class="oe_highlight" icon="fa-file" attrs="{'invisible':['|',['parent_reservation', '=', False]]}" />
                    <field name="state" widget="statusbar"/>

                </header>
                <div class="alert alert-info" role="alert" style="margin-bottom:0px;"
                     attrs="{'invisible': ['|',('shared_folio','=',False),('splitted', '=', True)]}">
                         This reservation has other reservantions and/or services in the folio, you can check it in the
                         <bold><button class="alert-link" type="object" name="open_folio" string="Folio Form"/></bold>
                </div>
                <div class="alert alert-warning" role="alert" style="margin-bottom:0px;"
                     attrs="{'invisible': [('splitted','=',False)]}">
                         This reservation is part of splitted reservation!, you can check it in the
                         <bold><button class="alert-link" type="object" name="open_folio" string="Folio Form"/></bold>
                </div>
                <field name="shared_folio" invisible="1"/>
                <sheet>
                    <div class="oe_button_box" attrs="{'invisible': [('folio_id','=',False)]}">
                        <button type="object" class="oe_stat_button"
                            id="folio_smart_button"
                            icon="fa-file"
                            name="open_folio">
                            <div class="o_form_field o_stat_info">
                                <span class="o_stat_text"><field name="folio_id" readonly="1" nolabel="1"/></span>
                            </div>
                        </button>
                        <button type="action" class="oe_stat_button"
                            id="books"
                            icon="fa-list-ul"
                            attrs="{'invisible': [('partner_id','=',False)]}"
                            name="%(open_hotel_reservation_form_tree_all)d"
                            context="{'search_default_partner_id': partner_id}">
                            <div class="o_form_field o_stat_info">
                                <span class="o_stat_text">Books</span>
                            </div>
                        </button>
                        <!-- <button type="object" class="oe_stat_button"
                            id="payment_smart_button"
                            icon="fa-money"
                            name="action_recalcule_payment"
                            attrs="{'invisible': [('fix_folio_pending','=',False)]}"
                            help="Calcule the total Price">
                            <div class="o_form_field o_stat_info">
                                <span class="o_stat_text">Calcule Price</span>
                            </div>
                        </button> -->
                        <button type="object" class="oe_stat_button"
                            id="open_master"
                            icon="fa-chain-broken"
                            name="open_master"
                            attrs="{'invisible':[('splitted','=',False)]}">
                            <div class="o_form_field o_stat_info">
                                <span><field name="parent_reservation"
                                nolabel="1" readonly="1"/></span>
                                <span class="o_stat_text">Splitted!</span>
                            </div>
                        </button>
                        <button type="action" class="oe_stat_button"
                            id="pending_checkins_smart_button"
                            icon="fa-user-plus"
                            name="%(launch_checkin_wizard_add)d"
                            context="{'partner_id': partner_id,'enter_date': checkin,
                                'exit_date': checkout,'reservation_id': id, 'hidden_cardex': True, 'edit_cardex': True }"
                            attrs="{'invisible':['|', '|', ('state','not in',('confirm','booking')),
                                ('cardex_pending','=', False),('parent_reservation','!=',False)]}">
                            <div class="o_form_field o_stat_info">
                                <span class="o_stat_value"><field name="cardex_pending_num"
                                widget="statinfo" nolabel="1"/></span>
                                <span class="o_stat_text">Pending Checks</span>
                            </div>
                        </button>
                        <button type="object" class="oe_stat_button"
                            id="checkin_smart_button"
                            icon="fa-users"
                            name="action_checks"
                            attrs="{'invisible': ['|', ('cardex_count','&lt;=',0),
                                ('parent_reservation','!=',False)]}">
                            <div class="o_form_field o_stat_info">
                              <span class="o_stat_value"><field name="cardex_count"
                               widget="statinfo" nolabel="1"/></span>
                              <span class="o_stat_text">Checks</span>
                            </div>
                        </button>
                    </div>
                    <span class="label label-danger" attrs="{'invisible': [('state', 'not in', ('cancelled'))]}">Cancelled Reservation!</span>
                    <span class="label label-warning" attrs="{'invisible': [('overbooking', '=', False)]}">OverBooking!</span>
                    <h1>
                        <!-- <field name="edit_room" nolabel="1" class="fa fa-bed" /> -->
                        <!-- <field name="room_id" select="1" domain="[('isroom','=',True)]"
                            nolabel="1" options="{'no_create': True,'no_open': True}" placeholder="Room"
                            style="margin-right: 30px;"/> -->
                        <field name="room_id" select="1"
                          nolabel="1" options="{'no_create': True,'no_open': True}" placeholder="Room"
                          style="margin-right: 30px;" required='1'/>
                        <field name="partner_id" default_focus="1"
                            placeholder="Lastname, Firstname"
                            attrs="{'readonly':[('folio_id','!=',False)]}"
                            required="1"/>
                         <span class="fa fa-user" style="margin-left:20px;"/>
                    </h1>
                    <h3>
                        From <span class="fa fa-sign-in" style="margin: 5px;"/>
                            <field name="checkin" style="margin-right: 10px;"/>
                        to
                        <span class="fa fa-sign-out" style="margin-right: 5px;"/>
                        <field name="checkout" />
                    </h3>
                    <group col="12">
                        <group colspan="5" string="General Info" name="contact_details" >
                            <field name="email" placeholder="email" widget="email" />
                            <field name="mobile" placeholder="mobile" widget="phone" />
                            <field name="phone" placeholder="phone" widget="phone" />
                            <field name="partner_internal_comment" string="Partner Note"/>
                            <field name="cancelled_reason" attrs="{'invisible':[('state','not in',('cancelled'))]}"/>
                        </group>
                        <group colspan="4" string="Reservation Details" name="reservation_details">
                            <field name="name"/>
                            <field name="adults"/>
                            <field name="children"/>
                            <!-- <field name="virtual_room_id" on_change="1" options="{'no_create': True,'no_open': True}"
                                   attrs="{'readonly':[('state','not in',('draft'))]}"/> -->
                            <field name="room_type_id" on_change="1" options="{'no_create': True,'no_open': True}"
                                attrs="{'readonly':[('state','not in',('draft'))]}"/>
                            <field name="channel_type" attrs="{'required':[('reservation_type','not in',('staff','out'))]}"/>
                        </group>
                        <group class="oe_subtotal_footer" style="margin-right: 20px; !important" colspan="2" name="reservation_total" string="Amounts"  attrs="{'invisible':[('folio_id','=', False)]}">
                            <!-- <field name="amount_room" widget="monetary" options="{'currency_field': 'currency_id'}"/> -->
                            <!-- <field name="discount" string="Room Discount" attrs="{'invisible': [('discount_type','=','fixed')]}" /> -->
                            <field name="discount_fixed" string="Room Discount" attrs="{'invisible': [('discount_type','=','percent')]}" />
                            <field name="discount_type" widget="radio" options="{'horizontal': true}" nolabel="1" colspan="2"/>
                            <div class="oe_subtotal_footer_separator oe_inline o_td_label">
                                <label for="amount_discount" />
                                <button name="%(action_hotel_massive_price_change_reservation_days)d" string="Massive Day Prices"
                                    type="action" class="oe_edit_only oe_link" icon="fa-bolt"/>
                            </div>
                            <!-- <field name="amount_discount" nolabel="1" widget='monetary'  class="oe_subtotal_footer_separator" options="{'currency_field': 'currency_id'}"/> -->
                            <div class="oe_subtotal_footer_separator oe_inline o_td_label">
                                <label for="amount_reservation_services" />
                            </div>
                            <!-- <field name="amount_reservation_services" nolabel="1" widget='monetary'  class="oe_subtotal_footer_separator" options="{'currency_field': 'currency_id'}"/> -->
                            <field name="price_total" invisible="1"/>
                            <!-- <field name="qty_delivered_updateable" invisible="1"/> -->
                            <field name="state" invisible="1"/>
                            <!-- <field name="invoice_status" invisible="1"/> -->
                            <!-- <field name="customer_lead" invisible="1"/> -->
                            <!-- <field name="currency_id" invisible="1"/> -->
                            <field name="price_subtotal" widget="monetary" invisible="1"/>
                            <!-- <field name="price_unit" invisible="1"/> -->
                            <!-- <field name="fix_total" invisible="1" /> -->
                            <!-- <field name="fix_folio_pending" invisible="1" /> -->
                        </group>
                    </group>
                    <field name="folio_internal_comment" nolabel="1" placeholder="Reservation Notes"/>
                    <group invisible="1">
                        <field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
                        <!-- <field name="check_rooms" invisible="1"/> -->
                        <field name="cardex_pending" invisible="1"/>
                        <!-- <field name="pricelist_id" invisible="1"/> -->
                        <field name="nights" invisible="1"/>
                        <!-- <field name="product_uom" string="Rent(UOM)" invisible="1" /> -->
                    </group>
                    <notebook>
                        <page name="days" string="Service and Days">
                            <group col="9">
                                <group colspan="6" string="Reservation Services" name="reservation_services" attrs="{'invisible': [('folio_id','=',False)]}">
                                    <field name="service_line_ids"
                                        context="{'default_ser_room_line': active_id, 'default_folio_id': folio_id}"
                                        nolabel="1" style="padding-right:10px !important;">
                                        <!-- <field name="service_line_ids"> -->
                                        <tree string="Services"  editable="bottom">
                                            <!-- <field name="sequence" widget="handle"/> -->
                                            <field name="folio_id" invisible="1"/>
                                            <field name="product_id"
                                                domain="[('sale_ok', '=', True),('is_room_type', '=', False)]"
                                                options="{'create': False, 'create_edit': False}" />
                                            <!-- <field name="layout_category_id" groups="sale.group_sale_layout"/> -->
                                            <field name="name"/>
                                            <field name="list_price"/>
                                            <!-- <field name="ser_room_line" invisible="1" /> -->
                                            <!-- <field name="qty_delivered" invisible="1"
                                                attrs="{'readonly': [('qty_delivered_updateable', '=', False)]}"/> -->
                                            <!-- <field name="product_uom"
                                                attrs="{'readonly': [('state', 'in', ('sale','done', 'cancel'))]}"
                                                context="{'company_id': parent.company_id}"
                                                groups="product.group_uom" options='{"no_open": True}'/> -->
                                            <!-- <field name="analytic_tag_ids" groups="analytic.group_analytic_accounting" widget="many2many_tags"/> -->
                                            <!-- <field name="tax_id" widget="many2many_tags" invisible="1"/> -->
                                            <!-- <field name="qty_delivered_updateable" invisible="1"/> -->
                                            <!-- <field name="state" invisible="1"/> -->
                                            <!-- <field name="invoice_status" invisible="1"/> -->
                                            <!-- <field name="customer_lead" invisible="1"/> -->
                                            <!-- <field name="currency_id" invisible="1"/> -->
                                        </tree>
                                    </field>
                                </group>
                                <group colspan="4" string="Days" name="days">
                                    <field name="reservation_line_ids" nolabel="1">
                                        <tree create="false" delete="false" editable="bottom">
                                            <field name="date" readonly="True" />
                                            <field name="price" />
                                            <field name="discount" />
                                        </tree>
                                    </field>
                                </group>
                             </group>
                        </page>
                        <page name="others" string="Others">
                            <group>
                                <field name="segmentation_ids" widget="many2many_tags" placeholder="Segmentation..."
                                    options="{'no_create': True,'no_open': True}" />
                                <field name="overbooking" />
                            </group>
                            <group>
                                <field name="reservation_type" />
                                <field name="out_service_description"
                                       attrs="{'invisible':[('reservation_type','not in',('out'))]}"/>
                            </group>
                        </page>
                    </notebook>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers"/>
                    <field name="message_ids" widget="mail_thread"/>
                </div>
            </form>
        </field>
    </record>

    <!-- Tree view of hotel reservation -->
    <record model="ir.ui.view" id="view_hotel_reservation_tree">
        <field name="name">hotel.reservation.tree</field>
        <field name="model">hotel.reservation</field>
        <field name="arch" type="xml">
            <tree string="Hotel Reservation"
               decoration-danger="folio_pending_amount &gt; 0 and checkin &lt;= current_date and not overbooking"
               decoration-muted="state == 'cancelled' and folio_pending_amount &gt; 0 and not overbooking"
               decoration-success="folio_pending_amount == 0 and checkout &lt;= current_date and not overbooking"
               decoration-warning="overbooking">
                <field name="splitted" invisible="1" />
                <button icon="fa fa-1x fa-chain-broken"
                    type="object"
                    class="oe_stat_button"
                    name="open_master"
                    attrs="{'invisible':[('splitted','=', False)]}" />
                <button icon="fa fa-2x fa-angellist"
                    attrs="{'invisible':['|',('folio_pending_amount','&gt;',0),('state' ,'!=', 'done')]}"
                    type="object"
                    name="open_folio" />
                <field name="state" />
                <button type="object" class="oe_stat_button"
                    icon="fa fa-2x fa-file"
                    name="open_folio"
                />
                <field name="folio_id"/>
                <button type="action" class="oe_stat_button"
                    icon="fa fa-1x fa-user-plus"
                    name="%(launch_checkin_wizard_add)d"
                    context="{'partner_id': partner_id,'enter_date': checkin,
                        'exit_date': checkout,'reservation_id': id, 'hidden_cardex': True, 'edit_cardex': True }"
                    attrs="{'invisible':['|','|', ('state','not in',('confirm','booking')),('cardex_pending','=', False),('parent_reservation','!=',False)]}"
                />
                <button type="action" class="oe_stat_button"
                    icon="fa fa-2x fa-list-ul"
                    name="%(open_hotel_reservation_form_tree_all)d"
                    context="{'search_default_partner_id': partner_id}"
                />
                <field name="partner_id"/>
                <field name="parent_reservation" invisible="1" />
                <!-- <field name="virtual_room_id" string="Reserved Room Type"/> -->
                <field name="room_type_id" string="Reserved Unit Type" />
                <field name="nights" />
                <field name="adults" string="Persons"/>
                <field name="checkin" widget="date"/>
                <field name="checkout"  widget="date"/>
                <field name="create_date"/>
                <field name="overbooking" invisible="1" />
                <field name="last_updated_res" string="Updated on"/>
                <field name="cardex_ids" invisible ="1"/>
                <field name="to_assign" invisible="1"/>
                <!-- cardex_smart_button attrs depends on cardex_pending to be showed -->
                <field name="cardex_pending" invisible="1"/>
                <field name="folio_pending_amount" string="Folio Pending Amount"/>
                <button type="object" class="oe_stat_button"
                    icon="fa fa-3x fa-money"
                    name="action_pay_folio"
                    attrs="{'invisible':[('folio_pending_amount','=',0)]}"
                />
                <field name="create_uid"/>
            </tree>
        </field>
    </record>

     <!-- Search view of hotel reservation -->
    <record model="ir.ui.view" id="view_hotel_reservation_search">
        <field name="name">hotel.reservation.search</field>
        <field name="model">hotel.reservation</field>
        <field name="arch" type="xml">
            <search string="Reservation Detail">
                <field name="partner_id" />
                <field name="folio_id" />
                <filter string="My Reservations"
                            domain="[('create_uid', '=', uid)]"
                             />
                <filter string="Cancelled"
                            domain="[('state', '=', 'cancelled')]"
                             />
                <filter string="On Board"
                            domain="[('state','in',['booking'])]"
                            help="Current Booking" />
                <filter string="To enter"
                            domain="[('state', '=', 'confirm')]"
                             />
                <filter string="Overbookings"
                            domain="[('overbooking', '=', 'True')]"
                             />
                <filter string="Reservations to 7 days" name="next_res_week"
                        domain="[('checkin', '&lt;', (context_today()+datetime.timedelta(days=7)).strftime('%Y-%m-%d')),
                        ('state', '=', 'confirm')]"
                        help="Show all reservations for which date enter is before than 7 days"/>
                <filter string="Reservations to 14 days" name="next_res_2week"
                        domain="[('checkin', '&lt;', (context_today()+datetime.timedelta(days=14)).strftime('%Y-%m-%d')),
                        ('state', '=', 'confirm')]"
                        help="Show all reservations for which date enter is before than 14 days"/>
                <filter string="Reservations to 1 month" name="next_res_week"
                        domain="[('checkin', '&lt;', (context_today()+datetime.timedelta(days=30)).strftime('%Y-%m-%d')),
                        ('state', '=', 'confirm')]"
                        help="Show all reservations for which date enter is before than aprox. 1 month"/>
                <filter string="To Assign"
                            domain="[('to_assign','=',True)]"
                            />
                <separator/>
                <filter string="Call Center"
                            domain="[('channel_type', '=', 'call')]"
                             />
                <filter string="Web"
                            domain="[('channel_type', '=', 'web')]"
                             />
                <filter string="Door"
                            domain="[('channel_type', '=', 'door')]"
                             />
                <filter string="Mail"
                            domain="[('channel_type', '=', 'mail')]"
                             />
                <filter string="Phone"
                            domain="[('channel_type', '=', 'phone')]"
                             />
                <separator/>
                <filter string="Still to be paid"
                            domain="[('folio_id.invoices_amount','&gt;',0)]"
                             />
                <filter string="Late Payment"
                            domain="[('folio_id.invoices_amount','&gt;',0),('state','in',['done'])]"
                            />
                <filter string="Lates and NoShows"
                            domain="[('cancelled_reason','in',['late','noshow'])]"
                            />
                <separator/>
                <filter string="Staff"
                            domain="[('reservation_type','in',['staff'])]"
                            />
                <filter string="Out of Service"
                            domain="[('reservation_type','in',['dontsell'])]"
                            />
                <group expand="0" string="Group By">
                    <!-- <filter string="Room Type" domain="[]"
                        context="{'group_by':'virtual_room_id'}"/> -->
                    <filter string="Room Type" domain="[]"
                        context="{'group_by':'room_type_id'}"/>
                    <filter string="Creation Date" domain="[]"
                        context="{'group_by':'create_date'}" />
                    <filter string="Checkin Date" domain="[]"
                        context="{'group_by':'checkin'}" />
                    <filter string="Created By" domain="[]"
                        context="{'group_by':'create_uid'}" />
                </group>
            </search>
        </field>
    </record>

</odoo>
