<?xml version="1.0" ?>
<odoo>
    <record id="massive_changes_wizard" model="ir.ui.view">
        <field name="name">Availability Wizard</field>
        <field name="model">pms.massive.changes.wizard</field>
        <field name="arch" type="xml">
            <form class="pt-1">
                <group>
                    <field name="massive_changes_on" invisible="1" />
                    <field name="avail_readonly" invisible="1" />
                    <field name="pricelist_readonly" invisible="1" />
                    <field name="allowed_board_services" invisible="1" />
                </group>
                <div class="row">
                    <div class="col-5">
                        <group>
                            <field
                                name="start_date"
                                widget="daterange"
                                options="{'related_end_date': 'end_date'}"
                            />
                            <field
                                name="end_date"
                                widget="daterange"
                                options="{'related_start_date': 'start_date'}"
                            />
                            <field
                                name="massive_changes_on"
                                attrs="{'invisible':['|', ('avail_readonly','=',True), ('pricelist_readonly', '=', True)]}"
                            />
                            <field
                                name="apply_pricelists_on"
                                widget="radio"
                                attrs="{'invisible':[('massive_changes_on','!=','pricelist')]}"
                            />
                        </group>
                    </div>
                    <div class="col-7">
                        <group class="">
                            <field name="pms_property_ids" widget="many2many_tags" />
                            <field
                                name="availability_plan_ids"
                                class="mr-5"
                                string="Availability Plan"
                                widget="many2many_tags"
                                options="{'no_create': True,'no_open': True}"
                                attrs="{'invisible':['|','|',('massive_changes_on','=','pricelist'), ('avail_readonly','=',True),
                                                             ('pricelist_readonly', '=', True)],
                                'required': [('massive_changes_on','=','availability_plan')]}"
                                domain="['|', ('pms_property_ids', '=', False), ('pms_property_ids', 'in', pms_property_ids)]"
                            />

                            <field
                                name="pricelist_ids"
                                string="Pricelist"
                                widget="many2many_tags"
                                options="{'no_create': True,'no_open': True}"
                                attrs="{'invisible':['|','|',('massive_changes_on','=','availability_plan'),
                                ('pricelist_readonly','=',True), ('pricelist_readonly', '=', True)],
                                 'required': [('massive_changes_on','=','pricelist')]}"
                                domain="[('id', 'in', allowed_pricelist_ids), '|', ('pms_property_ids', '=', False), ('pms_property_ids', 'in', pms_property_ids)]"
                            />
                            <field
                                name="room_type_ids"
                                default_focus="1"
                                widget="many2many_tags"
                                options="{'no_create': True,'no_open': True}"
                                attrs="{'invisible':[('apply_pricelists_on','!=','room_types'),('massive_changes_on', '=','pricelist')],'required': []}"
                            />
                            <field
                                name="board_service_room_type_ids"
                                widget="many2many_tags"
                                options="{'no_create': True,'no_open': True}"
                                attrs="{'invisible':['|', ('apply_pricelists_on','!=','board_services'),('massive_changes_on', '=','availability_plan')],
                                'required': [('apply_pricelists_on','=','board_services')]}"
                            />
                            <field
                                name="board_service"
                                options="{'no_create': True,'no_open': True}"
                                attrs="{'invisible':['|', ('apply_pricelists_on','!=','board_services'),('massive_changes_on', '=','availability_plan')],
                                'required': [('apply_pricelists_on','=','board_services')]}"
                            />
                            <field
                                name="service"
                                options="{'no_create': True,'no_open': True}"
                                attrs="{'invisible':['|', ('apply_pricelists_on','!=','service'),('massive_changes_on', '=','availability_plan')]}"
                            />
                            <field
                                name="date_types"
                                widget="radio"
                                options="{'no_create': True,'no_open': True}"
                                attrs="{'invisible':[('massive_changes_on', '=','availability_plan')]}"
                            />
                        </group>

                    </div>
                </div>
                <field name="allowed_pricelist_ids" invisible="1" />
                <b>Days:</b>
                <div class="row">
                    <div class="col-12">
                        <table class="table table-bordered text-center">
                            <thead>
                                <tr>
                                    <th>All days</th>
                                    <th>Sunday</th>
                                    <th>Monday</th>
                                    <th>Tuesday</th>
                                    <th>Wednesday</th>
                                    <th>Thursday</th>
                                    <th>Friday</th>
                                    <th>Saturday</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>
                                       <field
                                            name="apply_on_all_week"
                                            widget="boolean_toggle"
                                        />
                                    </td>
                                    <td>
                                        <field
                                            name="apply_on_sunday"
                                            widget="boolean_toggle"
                                            attrs="{'invisible':[('apply_on_all_week','=',True)]}"
                                        />
                                    </td>
                                    <td>
                                        <field
                                            name="apply_on_monday"
                                            widget="boolean_toggle"
                                            attrs="{'invisible':[('apply_on_all_week','=',True)]}"
                                        />
                                    </td>
                                    <td>
                                        <field
                                            name="apply_on_tuesday"
                                            widget="boolean_toggle"
                                            attrs="{'invisible':[('apply_on_all_week','=',True)]}"
                                        />
                                    </td>
                                    <td>
                                        <field
                                            name="apply_on_wednesday"
                                            widget="boolean_toggle"
                                            attrs="{'invisible':[('apply_on_all_week','=',True)]}"
                                        />
                                    </td>
                                    <td>
                                        <field
                                            name="apply_on_thursday"
                                            widget="boolean_toggle"
                                            attrs="{'invisible':[('apply_on_all_week','=',True)]}"
                                        />
                                    </td>
                                    <td>
                                        <field
                                            name="apply_on_friday"
                                            widget="boolean_toggle"
                                            attrs="{'invisible':[('apply_on_all_week','=',True)]}"
                                        />
                                    </td>
                                    <td>
                                        <field
                                            name="apply_on_saturday"
                                            widget="boolean_toggle"
                                            attrs="{'invisible':[('apply_on_all_week','=',True)]}"
                                        />
                                    </td>

                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <span attrs="{'invisible':[('massive_changes_on','=','pricelist')]}">
                <b>Rules to apply:</b>
                <div class="row">
                    <div class="col-4 pr-0">
                        <div class="border h-100 pt-2 px-2">
                            <div class="row">
                                <div class="col-2">
                                    <field
                                            name="apply_min_stay"
                                            widget="boolean_toggle"
                                        />
                                </div>
                                <div class="col-6">
                                    <label for="min_stay" />
                                </div>
                                <div class="col-4">
                                    <field
                                            name="min_stay"
                                            nolabel="1"
                                            attrs="{'invisible':[('apply_min_stay','=',False)], 'required':[('apply_min_stay','=',True)]}"
                                        />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-5 pr-0">
                        <div class="border h-100  pt-2 px-2 ">
                            <div class="row">
                                <div class="col-2">
                                    <field
                                            name="apply_min_stay_arrival"
                                            widget="boolean_toggle"
                                        />
                                </div>
                                <div class="col-6">
                                    <label for="min_stay_arrival" />
                                </div>
                                <div class="col-4">
                                    <field
                                            name="min_stay_arrival"
                                            nolabel="1"
                                            attrs="{'invisible':[('apply_min_stay_arrival','=',False)],'required':[('apply_min_stay_arrival','=',True)]}"
                                        />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-3">
                        <div class="border h-100 pt-2 px-2">
                            <div class="row">
                                <div class="col-3">
                                    <field
                                            name="apply_closed"
                                            widget="boolean_toggle"
                                        />
                                </div>
                                <div class="col-9">
                                    <field
                                            name="closed"
                                            attrs="{'readonly':[('apply_closed','=',False)]}"
                                        />
                                    <label for="closed" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row pt-3">
                    <div class="col-4 pr-0">
                        <div class="border h-100  pt-2 px-2 ">
                            <div class="row">
                                <div class="col-2">
                                    <field
                                            name="apply_max_stay"
                                            widget="boolean_toggle"
                                        />
                                </div>
                                <div class="col-6">
                                    <label for="max_stay" />
                                </div>
                                <div class="col-4">
                                    <field
                                            name="max_stay"
                                            nolabel="1"
                                            attrs="{'invisible':[('apply_max_stay','=',False)], 'required':[('apply_max_stay','=',True)]}"
                                        />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-5 pr-0">
                        <div class="border h-100  pt-2 px-2 ">
                            <div class="row">
                                <div class="col-2">
                                    <field
                                            name="apply_max_stay_arrival"
                                            widget="boolean_toggle"
                                        />
                                </div>
                                <div class="col-6">
                                    <label for="max_stay_arrival" />
                                </div>
                                <div class="col-4">
                                    <field
                                            name="max_stay_arrival"
                                            nolabel="1"
                                            attrs="{'invisible':[('apply_max_stay_arrival','=',False)], 'required':[('apply_max_stay_arrival','=',True)]}"
                                        />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-3">
                        <div class="border h-100 pt-2 px-2">
                            <div class="row">
                                <div class="col-3">
                                    <field
                                            name="apply_closed_arrival"
                                            widget="boolean_toggle"
                                        />
                                </div>
                                <div class="col-9">
                                    <field
                                            name="closed_arrival"
                                            attrs="{'readonly':[('apply_closed_arrival','=',False)]}"
                                        />
                                    <label for="closed_arrival" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row pt-4">
                    <div class="col-4 pr-0">
                        <div class="border h-100  pt-2 px-2 ">
                            <div class="row">
                                <div class="col-2">
                                    <field name="apply_quota" widget="boolean_toggle" />
                                </div>
                                <div class="col-6">
                                    <label for="quota" />
                                </div>
                                <div class="col-4">
                                    <field
                                            name="quota"
                                            nolabel="1"
                                            attrs="{'invisible':[('apply_quota','=',False)], 'required':[('apply_quota','=',True)]}"
                                        />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-5 pr-0">
                        <div class="border h-100  pt-2 px-2">
                            <div class="row">
                                <div class="col-2">
                                    <field
                                            name="apply_max_avail"
                                            widget="boolean_toggle"
                                        />
                                </div>
                                <div class="col-6">
                                    <label for="max_avail" />
                                </div>
                                <div class="col-4">
                                    <field
                                            name="max_avail"
                                            nolabel="1"
                                            attrs="{'invisible':[('apply_max_avail','=',False)],'required':[('apply_max_avail','=',True)]}"
                                        />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-3">
                        <div class="border h-100 pt-2 px-2">
                            <div class="row">
                                <div class="col-3">
                                    <field
                                            name="apply_closed_departure"
                                            widget="boolean_toggle"
                                        />
                                </div>
                                <div class="col-9">
                                    <field
                                            name="closed_departure"
                                            attrs="{'readonly':[('apply_closed_departure','=',False)]}"
                                        />
                                    <label for="closed_departure" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                </span>
                <br />
                <div
                    attrs="{'invisible':[('massive_changes_on','=','availability_plan')]}"
                >
                    <div class="col-4">
                        <group>
                            <field name="price" />
                            <!-- REVIEW 'min_quantity'-->
                            <!--<field name="min_quantity" />-->
                        </group>
                    </div>
                </div>
                <b
                    attrs="{'invisible':[('massive_changes_on','=','pricelist')]}"
                    class="mt-5"
                >
                    <span style="text-decoration:underline;">
                        <field name="num_rules_to_overwrite" />
                    </span>
                    availability rules
                    <u>will be overwritten:</u>
                </b>

                <b
                    attrs="{'invisible':[('massive_changes_on','=','availability_plan')]}"
                >
                    <span style="text-decoration:underline;">
                        <field name="num_pricelist_items_to_overwrite" />

                    </span>
                    pricelist items
                    <u>will be overwritten:</u>
                </b>
                <field
                    name="rules_to_overwrite"
                    nolabel="1"
                    attrs="{'invisible':[('massive_changes_on','=','pricelist')]}"
                >
                    <tree>
                        <field name="date" />
                        <field name="room_type_id" />
                        <field
                            name="quota"
                            attrs="{'column_invisible':[('parent.apply_quota', '==', False)]}"
                        />
                        <field
                            name="max_avail"
                            attrs="{'column_invisible':[('parent.apply_max_avail', '==', False)]}"
                        />
                        <field
                            name="min_stay"
                            attrs="{'column_invisible':[('parent.apply_min_stay', '==', False)]}"
                        />

                        <field
                            name="max_stay"
                            attrs="{'column_invisible':[('parent.apply_max_stay', '==', False)]}"
                        />

                        <field
                            name="min_stay_arrival"
                            attrs="{'column_invisible':[('parent.apply_min_stay_arrival', '==', False)]}"
                        />

                        <field
                            name="max_stay_arrival"
                            attrs="{'column_invisible':[('parent.apply_max_stay_arrival', '==', False)]}"
                        />

                         <field
                            name="closed"
                            attrs="{'column_invisible':[('parent.apply_closed', '==', False)]}"
                        />

                        <field
                            name="closed_arrival"
                            attrs="{'column_invisible':[('parent.apply_closed_arrival', '==', False)]}"
                        />
                        <field
                            name="closed_departure"
                            attrs="{'column_invisible':[('parent.apply_closed_departure', '==', False)]}"
                        />
                        <field name="pms_property_id" />
                    </tree>
                </field>
                <field
                    name="pricelist_items_to_overwrite"
                    nolabel="1"
                    attrs="{'invisible':[('massive_changes_on','=','availability_plan')]}"
                >
                     <tree>
                         <field name="pricelist_id" />
                         <field string="Applicable on" name="name" />
                         <field name="board_service_room_type_id" />
                         <field string="Sale Date Start" name="date_start" />
                         <field string="Sale Date End" name="date_end" />
                         <field name="date_start_consumption" />
                         <field name="date_end_consumption" />
                         <field name="price" />
                         <field name="pms_property_ids" widget="many2many_tags" />
                    </tree>
                </field>
                <footer>
                    <button
                        name="save_and_close"
                        string="Apply and close"
                        type="object"
                        class="btn-primary"
                    />
                    <button
                        name="continue_massive_changes"
                        string="Apply and continue"
                        type="object"
                        class="btn-primary"
                    />
                    or
                    <button
                        string="Cancel"
                        class="btn-default border"
                        special="cancel"
                    />
                </footer>
            </form>
        </field>
    </record>
    <record id="action_wizard_massive_changes" model="ir.actions.act_window">
        <field name="name">Massive changes on Pricelist &amp; Availability Plans</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">pms.massive.changes.wizard</field>
        <field name="view_id" ref="massive_changes_wizard" />
        <field name="view_mode">form</field>
        <field name="target">new</field>
    </record>
    <menuitem
        name="Massive Changes"
        id="menu_pms_room_massive_changes_wizard"
        action="action_wizard_massive_changes"
        sequence="75"
        parent="pms.revenue_management_menu"
    />
</odoo>
