<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="maintenance_plan_view_form" model="ir.ui.view">
        <field name="name">maintenance.plan.form@maintenance_plan</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"
                        invisible="not id or interval == 0"
                    />
                </header>
                <sheet>
                    <widget
                        name="web_ribbon"
                        title="Archived"
                        bg_color="bg-danger"
                        invisible="active"
                    />
                    <field name="active" invisible="True" />
                    <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"
                                required="not equipment_id"
                            />
                        </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"
                                required="not equipment_id"
                            />
                            <field
                                name="generate_with_domain"
                                invisible="equipment_id"
                            />
                            <field
                                name="generate_domain"
                                widget="domain"
                                options="{'model': 'maintenance.equipment', 'in_dialog': True}"
                                invisible="equipment_id or not generate_with_domain"
                            />
                        </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">
                            <group col="1">
                                <field
                                    name="instruction_type"
                                    widget="radio"
                                    nolabel="1"
                                />
                                <field
                                    name="instruction_pdf"
                                    help="Upload your PDF file."
                                    widget="pdf_viewer"
                                    invisible="instruction_type != 'pdf'"
                                    required="instruction_type == 'pdf'"
                                    nolabel="1"
                                />
                                <field
                                    name="instruction_google_slide"
                                    placeholder="Google Slide Link"
                                    widget="embed_viewer"
                                    invisible="instruction_type != 'google_slide'"
                                    required="instruction_type == 'google_slide'"
                                    nolabel="1"
                                />
                                <field
                                    name="instruction_text"
                                    placeholder="Your instructions"
                                    invisible="instruction_type != 'text'"
                                    nolabel="1"
                                />
                            </group>
                        </page>
                    </notebook>
                </sheet>
                <div class="o_attachment_preview" />
                <chatter />
            </form>
        </field>
    </record>

    <record id="maintenance_plan_view_tree" model="ir.ui.view">
        <field name="name">maintenance.plan.list@maintenance_plan</field>
        <field name="model">maintenance.plan</field>
        <field name="arch" type="xml">
            <list 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" column_invisible="True" />
                <field name="company_id" groups="base.group_multi_company" />
            </list>
        </field>
    </record>

    <record id="maintenance_plan_view_search" model="ir.ui.view">
        <field name="name">maintenance.plan.search@maintenance_plan</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="path">maintenance-plans</field>
        <field name="res_model">maintenance.plan</field>
        <field name="view_mode">list,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="path">maintenance-equipment-plans</field>
        <field name="res_model">maintenance.plan</field>
        <field name="view_mode">list,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>
