<?xml version="1.0"?>
<odoo>
    <record id="mail_activity_type_view_form" model="ir.ui.view">
        <field name="name">mail.activity.type.view.form</field>
        <field name="model">mail.activity.type</field>
        <field name="arch" type="xml">
            <form string="Activities">
                <sheet>
                    <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" invisible="active"/>
                    <div class="oe_title">
                        <label for="name" class="oe_edit_only"/>
                        <h1><field name="name" placeholder="e.g. Schedule a meeting"/></h1>
                    </div>
                    <group>
                        <group name="activity_details" string="Activity Settings">
                            <field name="active" invisible="1"/>
                            <field name="category"/>
                            <field name="default_user_id" options="{'no_create': True}" domain="[('share', '=', False)]"/>
                            <field name="res_model" groups="base.group_no_one"/>
                            <field name="res_model" invisible="1"/>
                            <field name="res_model_change" invisible="1"/>
                            <field name="initial_res_model" invisible="1"/>
                            <field name="summary" placeholder="e.g. &quot;Discuss proposal&quot;"/>
                            <field name="icon" groups="base.group_no_one"/>
                            <field name="decoration_type" groups="base.group_no_one"/>
                            <field name="keep_done"/>
                        </group>
                        <group name="activity_planning" string="Next Activity">
                            <field name="chaining_type" invisible="category == 'upload_file'"/>
                            <field name="triggered_next_type_id" options="{'no_open': True}" context="{'default_res_model': res_model}"
                                invisible="chaining_type == 'suggest' and category != 'upload_file'"
                                required="chaining_type == 'trigger' and category != 'upload_file'"/>
                            <field name="suggested_next_type_ids" widget="many2many_tags" context="{'default_res_model': res_model}"
                                invisible="chaining_type == 'trigger' or category == 'upload_file'"/>
                            <field name="mail_template_ids" widget="many2many_tags"
                                domain="[('model_id.model', '=', res_model)]"
                                invisible="not res_model"
                                context="{'default_model': res_model}"/>
                            <label for="delay_count"/>
                            <div>
                                <field class="oe_inline pe-1 o_input_3ch" name="delay_count"/>
                                <field class="oe_inline ps-1 pe-2" name="delay_unit"/>
                                <field class="oe_inline" name="delay_from"/>
                            </div>
                        </group>
                    </group>
                    <label for="default_note" class="fw-bold"/>
                    <field nolabel="1" name="default_note" placeholder="e.g. &quot;Go over the offer and discuss details&quot;" class="oe-bordered-editor"/>
                    <p class="alert alert-info" role="alert" invisible="not res_model_change">Modifying the model can have an impact on existing activities using this activity type, be careful.</p>
                </sheet>
            </form>
        </field>
    </record>

    <record id="mail_activity_type_form_inherit" model="ir.ui.view">
        <field name="name">mail.activity.type.form.inherit</field>
        <field name="model">mail.activity.type</field>
        <field name="inherit_id" ref="mail.mail_activity_type_view_form"/>
        <field name="mode">primary</field>
        <field name="priority">50</field>
        <field name="arch" type="xml">
            <xpath expr="//label[@for='delay_count']" position="attributes">
                <attribute name="invisible">chaining_type == 'suggest' and not suggested_next_type_ids or chaining_type == 'trigger' and not triggered_next_type_id</attribute>
            </xpath>
            <field name="delay_count" position="attributes">
                <attribute name="invisible">chaining_type == 'suggest' and not suggested_next_type_ids or chaining_type == 'trigger' and not triggered_next_type_id</attribute>
            </field>
            <field name="delay_from" position="attributes">
                <attribute name="invisible">chaining_type == 'suggest' and not suggested_next_type_ids or chaining_type == 'trigger' and not triggered_next_type_id</attribute>
            </field>
            <field name="delay_unit" position="attributes">
                <attribute name="invisible">chaining_type == 'suggest' and not suggested_next_type_ids or chaining_type == 'trigger' and not triggered_next_type_id</attribute>
            </field>
        </field>
    </record>

    <record id="mail_activity_type_view_search" model="ir.ui.view">
        <field name="name">mail.activity.type.search</field>
        <field name="model">mail.activity.type</field>
        <field name="arch" type="xml">
            <search string="Activities">
                <field name="name"/>
                <filter string="Archived" domain="[('active', '=', False)]" name="archived"/>
            </search>
        </field>
    </record>

    <record id="mail_activity_type_view_tree" model="ir.ui.view">
        <field name="name">mail.activity.type.view.tree</field>
        <field name="model">mail.activity.type</field>
        <field name="arch" type="xml">
            <tree string="Activities" sample="1">
                <field name="sequence" widget="handle"/>
                <field name="name"/>
                <field name="summary"/>
                <field name="delay_label" string="Planned in" class="text-end"/>
                <field name="delay_from" string="Type"/>
                <field name="res_model" groups="base.group_no_one"/>
                <field name="icon" groups="base.group_no_one"/>
            </tree>
        </field>
    </record>

    <record id="mail_activity_type_action" model="ir.actions.act_window">
        <field name="name">Activity Types</field>
        <field name="res_model">mail.activity.type</field>
        <field name="view_mode">tree,form</field>
    </record>


    <record id="mail_activity_action" model="ir.actions.act_window">
        <field name="name">Activities</field>
        <field name="res_model">mail.activity</field>
        <field name="view_mode">tree,form</field>
    </record>

    <record id="mail_activity_view_form_popup" model="ir.ui.view">
        <field name="name">mail.activity.view.form.popup</field>
        <field name="model">mail.activity</field>
        <field name="priority">20</field>
        <field name="arch" type="xml">
            <form string="Log an Activity" create="false">
                <sheet string="Activity">
                    <div class="oe_button_box" name="button_box" invisible="1">
                        <button name="action_open_document"
                                type="object" class="oe_link" icon="fa-file-text-o"
                                invisible="not res_model or res_id == 0">
                                <div class="o_field_widget o_stat_info">
                                    <span class="o_stat_text">Open Document</span>
                                </div>
                        </button>
                    </div>
                    <group invisible="1">
                        <field name="activity_category" invisible="1" />
                        <field name="res_model" invisible="1"/>
                        <field name="res_model_id" invisible="1"/>
                        <field name="res_id" invisible="1"/>
                        <field name="chaining_type" invisible="1"/>
                        <field name="previous_activity_type_id"/>
                        <field name="has_recommended_activities"/>
                    </group>
                    <group invisible="not has_recommended_activities">
                        <field name="recommended_activity_type_id" widget="selection_badge"
                            domain="[('previous_type_ids', '=', previous_activity_type_id)]"
                            string="Recommended Activities"/>
                    </group>
                    <group>
                        <group>
                            <field name="activity_type_id" required="1" options="{'no_create': True, 'no_open': True}"/>
                            <field name="summary" placeholder="e.g. Discuss proposal"/>
                        </group>
                        <group>
                            <field name="date_deadline"/>
                            <field name="user_id" widget="many2one_avatar_user"/>
                        </group>
                    </group>
                    <field name="note" class="oe-bordered-editor" placeholder="Log a note..."/>
                    <footer>
                        <field name="id" invisible="1"/>
                        <button id="mail_activity_schedule" string="Schedule" close="1" name="action_close_dialog" type="object" class="btn-primary"
                            invisible="id" data-hotkey="q"/>
                        <button id="mail_activity_save" string="Save" name="action_close_dialog" type="object" class="btn-primary"
                            invisible="not id" data-hotkey="q"/>
                        <button invisible="chaining_type == 'trigger'" string="Mark as Done" name="action_done"
                            type="object" class="btn-secondary" data-hotkey="w"
                            context="{'mail_activity_quick_update': True}"/>
                        <button invisible="chaining_type == 'trigger'" string="Done &amp; Schedule Next" name="action_done_schedule_next"
                            type="object" class="btn-secondary" data-hotkey="z"
                            context="{'mail_activity_quick_update': True}"/>
                        <button invisible="chaining_type == 'suggest'" string="Done &amp; Launch Next" name="action_done_schedule_next"
                            type="object" class="btn-secondary" data-hotkey="z"
                            context="{'mail_activity_quick_update': True}"/>
                        <button string="Discard" class="btn-secondary" special="cancel" data-hotkey="x" />
                    </footer>
                </sheet>
            </form>
        </field>
    </record>

    <record id="mail_activity_view_form" model="ir.ui.view">
        <field name="name">mail.activity.view.form</field>
        <field name="model">mail.activity</field>
        <field name="priority">21</field>
        <field name="mode">primary</field>
        <field name="inherit_id" ref="mail.mail_activity_view_form_popup"/>
        <field name="arch" type="xml">
            <field name="activity_type_id" position="before">
                <field name="res_name" readonly="1" string="Document"/>
            </field>
            <footer position="replace"/>
            <xpath expr="//div[hasclass('oe_button_box')]" position="attributes">
                <attribute name="invisible">0</attribute>
            </xpath>
        </field>
    </record>

    <record id="mail_activity_view_form_without_record_access" model="ir.ui.view">
        <field name="name">mail.activity.view.form.without.record.access</field>
        <field name="model">mail.activity</field>
        <field name="priority">32</field>
        <field name="arch" type="xml">
            <form string="Log an Activity" create="false" delete="false">
                <sheet string="Activity">
                    <field name="res_model" invisible="1"/>
                    <field name="display_name" invisible="1"/>
                    <group>
                        <group>
                            <field name="activity_type_id" required="1" options="{'no_create': True, 'no_open': True}"/>
                            <field name="summary" placeholder="e.g. Discuss proposal"/>
                        </group>
                        <group>
                            <field name="date_deadline"/>
                        </group>
                    </group>
                    <field name="note" class="oe-bordered-editor" placeholder="Log a note..."/>
                </sheet>
            </form>
        </field>
    </record>

    <record id="mail_activity_view_search" model="ir.ui.view">
        <field name="name">mail.activity.view.search</field>
        <field name="model">mail.activity</field>
        <field name="arch" type="xml">
            <search string="Activity">
                <field name="res_model"/>
                <field name="summary"/>
                <field name="activity_type_id"/>
                <filter invisible="1" string="Late Activities" name="activities_overdue"
                        domain="[('date_deadline', '&lt;', context_today().strftime('%Y-%m-%d'))]"
                        help="Show all records which has next action date is before today"/>
                <filter invisible="1" string="Today Activities" name="activities_today"
                        domain="[('date_deadline', '=', context_today().strftime('%Y-%m-%d'))]"/>
                <filter invisible="1" string="Future Activities" name="activities_upcoming_all"
                        domain="[('date_deadline', '&gt;', context_today().strftime('%Y-%m-%d'))
                        ]"/>
                <group expand="0" string="Group By">
                    <filter string="Deadline" name="date_deadline" context="{'group_by': 'date_deadline'}"/>
                    <filter string="Created By" name="createdby" context="{'group_by': 'create_uid'}"/>
                    <filter string="Activity Type" name="activittype" context="{'group_by': 'activity_type_id'}"/>
                </group>
            </search>
        </field>
    </record>

    <record id="mail_activity_view_tree" model="ir.ui.view">
        <field name="name">mail.activity.view.tree</field>
        <field name="model">mail.activity</field>
        <field name="arch" type="xml">
            <tree string="Next Activities"
                    decoration-danger="date_deadline &lt; current_date"
                    decoration-success="date_deadline == current_date"
                    default_order="date_deadline" create="false">
                <field name="res_name"/>
                <field name="activity_type_id"/>
                <field name="summary"/>
                <field name="date_deadline"/>
            </tree>
        </field>
    </record>

    <record id="mail_activity_view_tree_without_record_access" model="ir.ui.view">
        <field name="name">mail.activity.view.tree.without.record.access</field>
        <field name="model">mail.activity</field>
        <field name="inherit_id" ref="mail_activity_view_tree"/>
        <field name="mode">primary</field>
        <field name="priority">32</field>
        <field name="arch" type="xml">
            <xpath expr="//tree" position="attributes">
                <attribute name="delete">0</attribute>
                <attribute name="edit">0</attribute>
                <attribute name="duplicate">0</attribute>
                <attribute name="js_class">archive_disabled_activity_list</attribute>
            </xpath>
            <xpath expr="//tree" position="inside">
                <button name="action_done" type="object" string="Mark as Done"/>
            </xpath>
        </field>
    </record>

    <record id="mail_activity_action_view_tree" model="ir.actions.act_window.view">
        <field name="sequence" eval="1"/>
        <field name="view_mode">tree</field>
        <field name="act_window_id" ref="mail.mail_activity_action"/>
    </record>
    <record id="mail_activity_action_view_form" model="ir.actions.act_window.view">
        <field name="sequence" eval="2"/>
        <field name="view_mode">form</field>
        <field name="view_id" ref="mail.mail_activity_view_form"/>
        <field name="act_window_id" ref="mail.mail_activity_action"/>
    </record>

    <record id="mail_activity_without_access_action" model="ir.actions.act_window">
        <field name="name">Other activities</field>
        <field name="res_model">mail.activity</field>
        <field name="view_mode">tree,form</field>
        <field name="search_view_id" ref="mail.mail_activity_view_search"/>
        <field name="domain">[('id', 'in', active_ids)]</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No activities.
            </p>
        </field>
    </record>

    <record id="mail_activity_action_without_access_view_tree" 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_view_tree_without_record_access"/>
        <field name="act_window_id" ref="mail.mail_activity_without_access_action"/>
    </record>

    <record id="mail_activity_action_without_access_view_form" 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_view_form_without_record_access"/>
        <field name="act_window_id" ref="mail.mail_activity_without_access_action"/>
    </record>

    <record id="mail_activity_view_calendar" model="ir.ui.view">
        <field name="name">mail.activity.view.calendar</field>
        <field name="model">mail.activity</field>
        <field name="priority" eval="2"/>
        <field name="arch" type="xml">
            <calendar string="Activity" date_start="date_deadline" color="activity_type_id">
                <field name="user_id" avatar_field="avatar_128"/>
                <field name="res_name"/>
                <field name="date_deadline"/>
                <field name="summary"/>
                <field name="activity_type_id" filters="1" invisible="1"/>
            </calendar>
        </field>
    </record>

</odoo>
