<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record model="ir.ui.view" id="pms_service_line_view_form">
        <field name="name">pms.service.line.form</field>
        <field name="model">pms.service.line</field>
        <field name="arch" type="xml">
            <form string="Service Line">
                <group>
                    <field name="product_id" />
                    <field name="day_qty" />
                    <field name="date" />
                    <field name="price_unit" />
                    <field
                        name="discount"
                        attrs="{'readonly':[('is_board_service','=', True)]}"
                    />
                    <field name="price_day_total" />
                    <field name="pms_property_id" invisible="1" />
                    <field name="is_board_service" invisible="1" />
                </group>
            </form>
        </field>
    </record>
    <record model="ir.ui.view" id="pms_service_line_view_tree">
        <field name="name">pms.service.line.tree</field>
        <field name="model">pms.service.line</field>
        <field name="arch" type="xml">
            <tree name="Service By Day">
                <field name="product_id" />
                <field name="day_qty" />
                <field name="date" />
                <field name="price_unit" />
                <field
                    name="discount"
                    attrs="{'readonly':[('is_board_service','=', True)]}"
                />
                <field name="price_day_total" />
                <field name="pms_property_id" invisible="1" />
                <field name="is_board_service" invisible="1" />
            </tree>
        </field>
    </record>
    <record model="ir.ui.view" id="pms_service_line_report_view_tree">
        <field name="name">pms.service.line.report.tree</field>
        <field name="model">pms.service.line</field>
        <field name="arch" type="xml">
            <tree name="Service By Day">
                <button
                    class="oe_stat_button"
                    icon="fa-1x fa-bed"
                    name="open_service_ids"
                    attrs="{'invisible':[('is_board_service','=', False)]}"
                    title="Board Service"
                />
                <field name="is_board_service" invisible="1" />
                <field name="product_id" />
                <field name="date" />
                <field name="day_qty" />
                <field
                    name="price_unit"
                    attrs="{'invisible':[('is_board_service','=', True)]}"
                />
                <field name="service_id" optional="show" />
                <field name="reservation_id" />
                <field name="tax_ids" optional="show" />
                <field name="discount" optional="show" />
                <field name="price_day_total" optional="show" />
            </tree>
        </field>
    </record>
    <!-- Search Views -->
    <record model="ir.ui.view" id="pms_service_line_view_search">
        <field name="name">pms.service.line.search</field>
        <field name="model">pms.service.line</field>
        <field name="arch" type="xml">
            <search string="Services By Day">
                <field name="product_id" />
                <separator />
                <field name="pms_property_id" />
                <separator />
                <filter
                    string="Board Services"
                    name="board_services"
                    domain="[('is_board_service', '=', True)]"
                    help="Services included in the room reservation price"
                />
                <filter
                    string="Extra Services"
                    name="no_board_services"
                    domain="[('is_board_service', '=', False)]"
                    help="Services NOT included in the room reservation price"
                />
                <separator />
                <filter
                    string="Today"
                    name="today"
                    domain="[('date', '=', context_today().strftime('%Y-%m-%d'))]"
                    help="Current Booking"
                />
                <filter
                    string="Tomorrow"
                    name="tomorrow"
                    domain="[('date', '=', (context_today()+datetime.timedelta(days=1)).strftime('%Y-%m-%d'))]"
                />
                <filter
                    string="Next 7 days"
                    name="next_7_days"
                    domain="[('date', '&gt;', context_today().strftime('%Y-%m-%d')),
                            ('date', '&lt;', (context_today()+datetime.timedelta(days=7)).strftime('%Y-%m-%d'))]"
                />
                <group expand="0" string="Group By">
                    <filter
                        string="By Month"
                        name="date_by_month"
                        context="{'group_by':'date', 'default_order': 'date asc'}"
                    />
                    <filter
                        string="By Week"
                        name="date_by_week"
                        context="{'group_by':'date:week', 'default_order': 'date'}"
                    />
                    <filter
                        string="By Day"
                        name="date_by_day"
                        context="{'group_by':'date:day', 'default_order': 'date'}"
                    />
                    <filter
                        string="Property"
                        name="group_property_id"
                        context="{'group_by':'pms_property_id', 'default_order': 'product_id'}"
                    />
                    <filter
                        string="Product"
                        name="group_product_id"
                        context="{'group_by':'product_id', 'default_order': 'product_id'}"
                    />
                </group>
                <searchpanel>
                    <field
                        name="pms_property_id"
                        string="Property"
                        enable_counters="1"
                        icon="fa-h-square"
                    />
                    <field
                        name="product_id"
                        string="Product"
                        enable_counters="1"
                        select="multi"
                    />
                </searchpanel>
            </search>
        </field>
    </record>

    <record id="pms_service_line_view_calendar" model="ir.ui.view">
        <field name="name">pms.service.line.view.calendar</field>
        <field name="model">pms.service.line</field>
        <field name="arch" type="xml">
            <calendar
                date_start="date"
                date_stop="date"
                string="Services"
                quick_add="False"
                mode="month"
                color="product_id"
                scales="week,month,year"
            >
                <field name="service_id" />
                <field name="product_id" filters="1" />
                <field name="reservation_id" filters="1" />
            </calendar>
        </field>
    </record>

    <record id="pms_service_line_pivot" model="ir.ui.view">
        <field name="name">pms.service.line.pivot</field>
        <field name="model">pms.service.line</field>
        <field name="arch" type="xml">
            <pivot string="Services">
                <field name="date" type="row" interval="day" />
                <field name="product_id" type="col" />
                <field name="day_qty" type="measure" />
            </pivot>
        </field>
    </record>

    <record id="pms_service_line_graph" model="ir.ui.view">
        <field name="name">pms.service.line.graph</field>
        <field name="model">pms.service.line</field>
        <field name="arch" type="xml">
            <graph string="Services">
                <field name="date" type="row" interval="day" />
                <field name="product_id" type="col" />
                <field name="day_qty" type="measure" />
            </graph>
        </field>
    </record>

    <!-- Action for service line from Form Folio/Reservation-->
    <record model="ir.actions.act_window" id="action_pms_service_line_form">
        <field name="name">Services</field>
        <field name="res_model">pms.service.line</field>
        <field name="view_mode">tree,form</field>
    </record>
    <!--
    <menuitem name="Services as Products" id="menu_open_pms_service_line_form"
        action="action_pms_service_line_form" sequence="8"
        parent="pms.menu_pms_service" />
-->
    <record model="ir.actions.act_window" id="action_service_line">
        <field name="name">Services By Day</field>
        <field name="res_model">pms.service.line</field>
        <field name="view_mode">tree,form,calendar,pivot,graph</field>
        <field name="view_id" ref="pms.pms_service_line_report_view_tree" />
        <field name="context">{
            'search_default_next_7_days': 1,
            'search_default_date_by_day': 1,
            'search_default_group_product_id': 1,
        }</field>
        <field name="domain">[('cancel_discount', '=', 0)]</field>
    </record>

    <menuitem
        id="menu_pms_service_line"
        name="Services by Day"
        sequence="35"
        action="action_service_line"
        parent="pms.menu_reservations"
    />
</odoo>
