<?xml version="1.0" encoding="utf-8"?>
<odoo>
        <record id="task_type_search" model="ir.ui.view">
            <field name="name">project.task.type.search</field>
            <field name="model">project.task.type</field>
            <field name="arch" type="xml">
                <search string="Tasks Stages">
                   <field name="name" string="Name"/>
                   <field name="project_ids" string="Project"/>
                   <field name="mail_template_id"/>
                   <field name="rating_template_id"/>
                    <filter string="Archived" name="inactive" domain="[('active', '=', False)]"/>
                    <group>
                        <filter string="Projects" name="project_ids" context="{'group_by': 'project_ids'}"/>
                    </group>
                </search>
            </field>
        </record>

        <record id="task_type_edit" model="ir.ui.view">
            <field name="name">project.task.type.form</field>
            <field name="model">project.task.type</field>
            <field name="arch" type="xml">
                <form string="Task Stage" delete="0">
                    <field name="active" invisible="1"/>
                    <field name="user_id" invisible="1"/>
                    <sheet>
                        <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" invisible="active"/>
                        <div class="oe_title">
                            <label for="name"/>
                            <h1><field name="name" placeholder="e.g. Qualification"/></h1>
                        </div>
                        <group>
                            <group>
                                <field name="mail_template_id" placeholder="No email"
                                    context="{'default_model': 'project.task'}" invisible="user_id"/>
                                <label for="rotting_threshold_days" string="Rotting in"/>
                                <div>
                                    <field name="rotting_threshold_days" class="oe_inline o_input_3ch px-1"/>
                                    <span>days</span>
                                </div>
                                <label for="rating_active" string="Ask for Ratings"/>
                                <div class="o_customer_rating o_row">
                                    <field name="rating_active"/>
                                    <field name="rating_status" invisible="not rating_active"/>
                                </div>
                                <field name="rating_status_period" string="Rating Periodicity"
                                    invisible="not rating_active or rating_status != 'periodic'"
                                    required="rating_active and rating_status == 'periodic'"/>
                                <field name="rating_template_id" string="Rating Email" placeholder="Default"
                                    invisible="not rating_active" required="rating_active" context="{'default_model': 'project.task'}"/>
                                <field name="auto_validation_state" string="Update Stage" invisible="not rating_active or not rating_template_id"/>
                            </group>
                            <group>
                                <field name="project_ids" invisible="user_id" required="not user_id"
                                    widget="many2many_tags" options="{'color_field': 'color', 'on_tag_click': 'open_form'}"/>
                                <field name="fold" string="Fold by Default"/>
                                <field name="color" widget="color_picker"/>
                                <field name="sequence" groups="base.group_no_one"/>
                            </group>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>

        <record id="task_type_tree" model="ir.ui.view">
            <field name="name">project.task.type.list</field>
            <field name="model">project.task.type</field>
            <field name="arch" type="xml">
                <list string="Task Stage" delete="0" sample="1" multi_edit="1" editable="bottom" open_form_view="True">
                    <field name="sequence" widget="handle" optional="show"/>
                    <field name="name" placeholder="e.g. To Do"/>
                    <field name="rotting_threshold_days" optional="hide"/>
                    <field name="mail_template_id" optional="hide"/>
                    <field name="project_ids" required="1" optional="show" widget="many2many_tags" options="{'color_field': 'color', 'on_tag_click': 'edit_color'}"/>
                    <field name="color" optional="hide" widget="color_picker"/>
                    <field name="fold" optional="show"/>
                </list>
            </field>
        </record>

        <record id="task_type_tree_inherited" model="ir.ui.view">
            <field name="name">project.task.type.list.inherited</field>
            <field name="model">project.task.type</field>
            <field name="mode">primary</field>
            <field name="inherit_id" ref="task_type_tree"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='name']" position="after">
                    <field name="rating_template_id" optional="hide"/>
                </xpath>
            </field>
        </record>

        <record id="view_project_task_type_kanban" model="ir.ui.view">
            <field name="name">project.task.type.kanban</field>
            <field name="model">project.task.type</field>
            <field name="arch" type="xml">
                <kanban highlight_color="color" class="o_kanban_mobile" sample="1" default_group_by="project_ids">
                    <templates>
                        <t t-name="menu" t-if="!selection_mode" groups="base.group_user">
                            <field name="color" widget="kanban_color_picker"/>
                        </t>
                        <t t-name="card">
                            <field name="name" class="fw-bolder text-truncate"/>
                            <field name="project_ids" widget="many2many_tags" options="{'color_field': 'color', 'on_tag_click': 'edit_color'}"/>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>

        <record id="open_task_type_form" model="ir.actions.act_window">
            <field name="name">Task Stages</field>
            <field name="res_model">project.task.type</field>
            <field name="path">task-stages</field>
            <field name="view_mode">list,kanban,form</field>
            <field name="view_id" ref="task_type_tree_inherited"/>
            <field name="domain">[('user_id', '=', False)]</field>
            <field name="context">{'default_user_id': False}</field>
            <field name="help" type="html">
              <p class="o_view_nocontent_smiling_face">
                No stages found. Let's create one!
              </p><p>
                Define the steps your tasks move through from creation to completion.
              </p>
            </field>
        </record>

        <record id="open_task_type_form_domain" model="ir.actions.act_window">
            <field name="name">Task Stages</field>
            <field name="res_model">project.task.type</field>
            <field name="view_mode">list,kanban,form</field>
            <field name="domain">[('project_ids','=', project_id)]</field>
            <field name="view_id" ref="task_type_tree_inherited"/>
            <field name="help" type="html">
                <p class="o_view_nocontent_smiling_face">
                Create a new stage in the task pipeline
                </p><p>
                Define the steps that will be used in the project from the
                creation of the task, up to the closing of the task or issue.
                You will use these stages in order to track the progress in
                solving a task or an issue.
                </p>
            </field>
        </record>

        <record id="unlink_task_type_action" model="ir.actions.server">
            <field name="name">Delete</field>
            <field name="model_id" ref="project.model_project_task_type"/>
            <field name="binding_model_id" ref="project.model_project_task_type"/>
            <field name="binding_view_types">form,list,kanban</field>
            <field name="state">code</field>
            <field name="code">action = records.unlink_wizard(stage_view=True)</field>
        </record>
</odoo>
