<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="mail_activity_plan_view_search" model="ir.ui.view">
            <field name="name">mail.activity.plan.view.search</field>
            <field name="model">mail.activity.plan</field>
            <field name="arch" type="xml">
                <search string="Plan">
                    <field name="name"/>
                    <separator/>
                    <filter string="Archived" name="filter_inactive" domain="[('active', '=', False)]"/>
                </search>
            </field>
        </record>

        <record id="mail_activity_plan_view_tree" model="ir.ui.view">
            <field name="name">mail.activity.plan.view.tree</field>
            <field name="model">mail.activity.plan</field>
            <field name="arch" type="xml">
                <tree string="Planning">
                    <field name="name"/>
                    <field name="steps_count"/>
                    <field name="company_id" groups="base.group_multi_company" optional="hide"/>
                </tree>
            </field>
        </record>

        <record id="mail_activity_plan_view_form" model="ir.ui.view">
            <field name="name">mail.activity.plan.view.form</field>
            <field name="model">mail.activity.plan</field>
            <field name="priority">20</field>
            <field name="arch" type="xml">
                <form string="Planning">
                    <field name="company_id" invisible="1"/>
                    <field name="active" invisible="1"/>
                    <sheet>
                        <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" invisible="active"/>
                        <div class="oe_title">
                            <label for="name" string="Plan Name"/>
                            <h1>
                                <field name="name" placeholder="e.g. Onboarding"/>
                            </h1>
                        </div>
                        <group name="group_plan_fields">
                            <field name="company_id" groups="base.group_multi_company"/>
                        </group>
                        <notebook>
                            <page string="Activities To Generate">
                                <group name="plan_res_model">
                                    <field name="res_model"/>
                                </group>
                                <field name="template_ids" nolabel="1">
                                    <tree default_order="sequence, id">
                                        <field name="sequence" widget="handle"/>
                                        <field name="activity_type_id" context="{'form_view_ref': 'mail.mail_activity_type_form_inherit'}"
                                               options="{'no_quick_create': True}"/>
                                        <field name="summary"/>
                                        <field name="responsible_type"/>
                                        <field name="responsible_id" readonly="responsible_type != 'other'"/>
                                        <field name="note"/>
                                        <field name="company_id" optional="hide"/>
                                    </tree>
                                </field>
                            </page>
                        </notebook>
                    </sheet>
                </form>
            </field>
        </record>

        <record id="mail_activity_plan_view_form_fixed_model" model="ir.ui.view">
            <field name="name">mail.activity.plan.view.form.fixed.model</field>
            <field name="model">mail.activity.plan</field>
            <field name="mode">primary</field>
            <field name="priority">10</field>
            <field name="inherit_id" ref="mail.mail_activity_plan_view_form"/>
            <field name="arch" type="xml">
                <xpath expr="//tree" position="attributes">
                    <attribute name="editable">bottom</attribute>
                </xpath>
                <xpath expr="//group[@name='plan_res_model']" position="attributes">
                    <attribute name="invisible">1</attribute>
                </xpath>
            </field>
        </record>

        <record id="mail_activity_plan_action" model="ir.actions.act_window">
            <field name="name">Activity Plans</field>
            <field name="res_model">mail.activity.plan</field>
            <field name="view_mode">tree,form</field>
            <field name="search_view_id" ref="mail_activity_plan_view_search"/>
            <field name="help" type="html">
                <p class="o_view_nocontent_smiling_face">
                    Add a new plan
                </p>
            </field>
        </record>

        <record id="mail_activity_plan_view_tree_action" model="ir.actions.act_window.view">
            <field name="sequence">1</field>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="mail.mail_activity_plan_view_tree"/>
            <field name="act_window_id" ref="mail.mail_activity_plan_action"/>
        </record>

        <!-- Force the admin view that allows to modify the target models of the plan. -->
        <record id="mail_activity_plan_view_form_action" model="ir.actions.act_window.view">
            <field name="sequence">2</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="mail.mail_activity_plan_view_form"/>
            <field name="act_window_id" ref="mail.mail_activity_plan_action"/>
        </record>

    </data>
</odoo>
