<?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" />
                    <sheet>
                        <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" invisible="active" />
                        <group>
                            <group>
                                <field name="name" placeholder="e.g. To Do"/>
                                <field name="fold"/>
                                <field name="user_id" invisible="True"/>
                                <field name="auto_validation_state" invisible="not rating_template_id"/>
                                <field name="project_ids" widget="many2many_tags" options="{'color_field': 'color', 'edit_tags': True}" invisible="user_id" required="not user_id"/>
                                <field name="rotting_threshold_days"/>
                                <field name="color" widget="color_picker"/>
                                <field name="sequence" groups="base.group_no_one"/>
                            </group>
                            <group>
                                <field name="mail_template_id" context="{'default_model': 'project.task'}" invisible="user_id"/>
                            </group>
                            <group name="group_customer_rating" string="Customer Rating" class="row o_settings_container" invisible="user_id">
                                <setting class="col-lg-12">
                                    <field name="rating_active"/>
                                    <div invisible="not rating_active">
                                        <field name="rating_status" widget="radio" class="o_row"/>
                                        <group class="mt-2">
                                            <field
                                                name="rating_status_period"
                                                invisible="rating_status != 'periodic'"
                                                required="rating_status == 'periodic'"
                                            />
                                            <field
                                                name="rating_template_id"
                                                placeholder="Task: Rating Request"
                                                context="{'default_model': 'project.task'}"
                                                required="rating_active"
                                            />
                                        </group>
                                        <span colspan="2" class="text-muted o_row ps-1">
                                            <i class="fa fa-lightbulb-o pe-2"/>
                                            <span name="rating_status_helper">
                                                <span invisible="rating_status == 'periodic'">A rating request will be sent as soon as a task reaches this stage.</span>
                                                <span invisible="rating_status == 'stage'">Rating requests will be sent as long as the task remains in this stage.</span>
                                            </span>
                                        </span>
                                    </div>
                                </setting>
                            </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'}"/>
                    <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'}"/>
                        </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>
