<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="hr_equipment_request_action_from_plan" model="ir.actions.act_window">
        <field name="name">Maintenance Requests</field>
        <field name="res_model">maintenance.request</field>
        <field name="binding_model_id" ref="model_maintenance_plan" />
        <field name="view_mode">kanban,tree,form,pivot,graph,calendar</field>
        <field name="context">{
            'default_maintenance_plan_id': active_id,
        }</field>
        <field name="domain">[('maintenance_plan_id', '=', active_id)]</field>
    </record>
    <record id="maintenance_plan_view_form" model="ir.ui.view">
        <field name="name">maintenance.plan.form</field>
        <field name="model">maintenance.plan</field>
        <field name="arch" type="xml">
            <form string="Maintenance Plan">
                <header>
                    <button
                        name="button_manual_request_generation"
                        string="Generate requests for current threshold"
                        help="If not clicked, the scheduled action will do it for you."
                        type="object"
                        attrs="{'invisible' : ['|', ('id', '=', False),('interval', '=', 0)]}"
                    />
                </header>
                <sheet>
                    <widget
                        name="web_ribbon"
                        title="Archived"
                        bg_color="bg-danger"
                        attrs="{'invisible': [('active', '=', True)]}"
                    />
                    <field name="active" attrs="{'invisible': 1}" />
                    <div class="oe_button_box" name="button_box">
                        <button
                            name="%(hr_equipment_request_action_from_plan)d"
                            type="action"
                            class="oe_stat_button"
                            icon="fa-ticket"
                        >
                            <field
                                string="Maintenance"
                                name="maintenance_count"
                                widget="statinfo"
                            />
                        </button>
                    </div>
                    <div class="oe_title">
                        <label for="name" class="oe_edit_only" />
                        <h1>
                            <field
                                name="name"
                                placeholder="e.g. Calibration"
                                attrs="{'required': [('equipment_id', '=', False)]}"
                            />
                        </h1>
                    </div>
                    <group>
                        <group>
                            <field
                                name="equipment_id"
                                invisible="context.get('hide_equipment_id', 0)"
                            />
                            <field name="maintenance_kind_id" />
                            <field
                                name="maintenance_team_id"
                                attrs="{'required': [('equipment_id', '=', False)]}"
                            />
                            <field
                                name="generate_with_domain"
                                attrs="{'invisible': [('equipment_id', '!=', False)]}"
                            />
                            <field
                                name="generate_domain"
                                widget="domain"
                                options="{'model': 'maintenance.equipment', 'in_dialog': True}"
                                attrs="{'invisible': ['|', ('equipment_id', '!=', False), ('generate_with_domain', '=', False)]}"
                            />
                        </group>
                        <group>
                            <field name="skip_notify_follower_on_requests" />
                            <field
                                name="company_id"
                                groups="base.group_multi_company"
                            />
                        </group>
                    </group>
                    <group>
                        <group>
                            <field name="start_maintenance_date" />
                            <field name="next_maintenance_date" />
                        </group>
                        <group>
                            <field name="duration" />
                            <label for="interval" />
                            <div class="o_row">
                                <field name="interval" />
                                <field name="interval_step" />
                            </div>
                            <label
                                for="maintenance_plan_horizon"
                                string="Planning Horizon"
                            />
                            <div class="o_row">
                                <field name="maintenance_plan_horizon" />
                                <field name="planning_step" />
                            </div>
                        </group>
                    </group>
                    <notebook>
                        <page string="Instructions">
                            <field
                                name="note"
                                placeholder="Describe the maintenance to do..."
                            />
                        </page>
                    </notebook>
                </sheet>
                <div class="o_attachment_preview" />
                <!-- Chatter -->
                <div class="oe_chatter">
                    <field name="message_follower_ids" groups="base.group_user" />
                    <field name="activity_ids" />
                    <field name="message_ids" />
                </div>
            </form>
        </field>
    </record>
    <record id="maintenance_plan_view_tree" model="ir.ui.view">
        <field name="name">maintenance.plan.tree</field>
        <field name="model">maintenance.plan</field>
        <field name="arch" type="xml">
            <tree decoration-muted="active == False">
                <field name="equipment_id" />
                <field name="maintenance_kind_id" />
                <field name="maintenance_team_id" />
                <field name="name" />
                <field name="start_maintenance_date" />
                <field name="interval" />
                <field name="interval_step" />
                <field name="duration" />
                <field name="next_maintenance_date" />
                <field name="maintenance_plan_horizon" />
                <field name="planning_step" />
                <field name="active" invisible="1" />
                <field name="company_id" groups="base.group_multi_company" />
            </tree>
        </field>
    </record>
    <record id="maintenance_plan_view_search" model="ir.ui.view">
        <field name="name">maintenance.plan.search</field>
        <field name="model">maintenance.plan</field>
        <field name="arch" type="xml">
            <search string="Maintenance Plans">
                <field name="equipment_id" />
                <field name="maintenance_kind_id" />
                <field name="maintenance_team_id" />
                <field name="name" />
                <field name="company_id" groups="base.group_multi_company" />
                <field name="start_maintenance_date" />
                <filter string="Active" name="active" domain="[('active', '=',True)]" />
                <filter
                    string="Inactive"
                    name="archived"
                    domain="[('active', '=',False)]"
                />
                <filter
                    string="Under Maintenance"
                    name="under_maintenance"
                    domain="[('maintenance_open_count', '&gt;', 0)]"
                />
            </search>
        </field>
    </record>
    <record id="maintenance_plan_action" model="ir.actions.act_window">
        <field name="name">Maintenance plans</field>
        <field name="res_model">maintenance.plan</field>
        <field name="view_mode">tree,form</field>
        <field name="view_id" ref="maintenance_plan_view_tree" />
        <field name="domain">['|', ('active', '=', True), ('active', '=',
            False)]
        </field>
    </record>
    <record id="maintenance_plan_equipment_action" model="ir.actions.act_window">
        <field name="name">Maintenance plans</field>
        <field name="res_model">maintenance.plan</field>
        <field name="view_mode">tree,form</field>
        <field name="view_id" ref="maintenance_plan_view_tree" />
        <field name="context">{
            'default_equipment_id': active_id, 'hide_equipment_id': 0
        }</field>
        <field name="domain">['|', ('active', '=', True), ('active', '=',
            False), ('search_equipment_id', '=', active_id)]
        </field>
    </record>
    <menuitem
        id="menu_m_plan_form"
        name="Maintenance Plans"
        parent="maintenance.menu_m_request"
        action="maintenance_plan_action"
        groups="maintenance.group_equipment_manager,base.group_user"
    />
</odoo>
