<?xml version="1.0" encoding="utf-8"?>

<odoo>
    <!-- project task inherit -->
    <record id="view_helpdesk_ticket_inherit" model="ir.ui.view">
        <field name="name">helpdesk.ticket.stage.change.history</field>
        <field name="model">helpdesk.ticket</field>
        <field name="inherit_id" ref="sh_all_in_one_helpdesk.helpdesk_ticket_form_view" />
        <field name="arch" type="xml">
            <data>
                <xpath expr="//notebook" position="inside">
                    <page name="helpdesk_stage_history_line" string="Stage Change History">
                        <field name="helpdesk_stage_history_line">
                            <tree>
                                <field name="stage_name" />
                                <field name="date_in" />
                                <field name="date_in_by" />
                                <field name="date_out" />
                                <field name="date_out_by" />
                                <field name="day_diff" />
                                <field name="time_diff" widget="float_time" />
                                <field name="total_time_diff" widget="float_time" />
                            </tree>
                        </field>
                    </page>
                </xpath>
            </data>
        </field>
    </record>

    <!-- tree view -->
    <record id="sh_helpdesk_stage_change_analysis_tree" model="ir.ui.view">
        <field name="name">Stage Change Analysis</field>
        <field name="model">sh.helpdesk.ticket.stage.info</field>
        <field name="arch" type="xml">
            <tree>
                    <field name="stage_task_id"/>
                    <field name="stage_name" />
                    <field name="date_in" />
                    <field name="date_in_by" />
                    <field name="date_out" />
                    <field name="date_out_by" />
                    <field name="day_diff" />
                    <field name="time_diff" widget="float_time" />
                    <field name="total_time_diff" widget="float_time" />
            </tree>
        </field>
    </record>

    <!-- for group by -->
    <record id="sh_view_helpdesk_stage_change_records_search" model="ir.ui.view">
        <field name="name">sh.helpdesk.ticket.info.search</field>
        <field name="model">sh.helpdesk.ticket.stage.info</field>
        <field name="arch" type="xml">
            <search string="Stage Change Analysis">
                <group expand="0" string="Group By">
                    <filter string="Stage Task" name="stage_task" context="{'group_by':'stage_task_id'}"/>
                    <filter string="Stage Name" name="stage_name" context="{'group_by':'stage_name'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- pivot view -->
    <record id="sh_view_stage_change_records_pivot" model="ir.ui.view">
        <field name="name">sh.helpdesk.ticket.stage.info.pivot</field>
        <field name="model">sh.helpdesk.ticket.stage.info</field>
        <field name="arch" type="xml">
            <pivot string="Stage Change Analysis">
                <field name="stage_task_id" type="row"/>
                <field name="stage_name" type="row"/>
                <field name="day_diff" type="measure"/>
                <field name="time_diff" type="measure"/>
                <field name="total_time_diff" type="measure"/>
            </pivot>
        </field>
   </record>

    <!-- action -->
    <record id="sh_helpdesk_stage_change_analysis_action" model="ir.actions.act_window">
        <field name="name">Stage Change Analysis</field>
        <field name="res_model">sh.helpdesk.ticket.stage.info</field>
        <field name="context">{'search_default_stage_task': 1,'search_default_stage_name': 1}</field>
        <field name="view_mode">tree,pivot</field>
    </record>

    <!-- stage change analysis -->
    <menuitem id="menu_helpdesk_stage_change_analysis" action="sh_helpdesk_stage_change_analysis_action" parent="helpdesk_main_menu" sequence="4"/>
</odoo>