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

    <!-- ============================================================ -->
    <!-- FUSION PAYROLL DASHBOARD ACTION                               -->
    <!-- ============================================================ -->
    <record id="action_fusion_payroll_dashboard" model="ir.actions.client">
        <field name="name">Fusion Payroll Dashboard</field>
        <field name="tag">fusion_payroll_dashboard</field>
    </record>

    <!-- Dashboard Action - Direct window action -->
    <record id="action_fusion_dashboard_employees" model="ir.actions.act_window">
        <field name="name">Fusion Payroll</field>
        <field name="res_model">fusion.payroll.dashboard</field>
        <field name="view_mode">form</field>
        <field name="target">current</field>
        <field name="context">{'create': False, 'edit': False, 'delete': False}</field>
        <field name="view_id" ref="fusion_payroll_dashboard_form"/>
    </record>

    <!-- ============================================================ -->
    <!-- RUN PAYROLL ACTIONS                                           -->
    <!-- ============================================================ -->
    <record id="action_fusion_run_payroll" model="ir.actions.act_window">
        <field name="name">Run Payroll</field>
        <field name="res_model">hr.payslip.run</field>
        <field name="view_mode">list,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create a new payroll batch
            </p>
            <p>Process payroll for your employees with automatic CPP, CPP2, EI, and tax calculations.</p>
        </field>
    </record>

    <record id="action_fusion_payslips" model="ir.actions.act_window">
        <field name="name">Payslips</field>
        <field name="res_model">hr.payslip</field>
        <field name="view_mode">list,form</field>
    </record>

    <!-- ============================================================ -->
    <!-- EMPLOYEES ACTIONS                                             -->
    <!-- ============================================================ -->
    <record id="action_fusion_employees" model="ir.actions.act_window">
        <field name="name">Employees</field>
        <field name="res_model">hr.employee</field>
        <field name="view_mode">kanban,list,form</field>
        <field name="context">{'search_default_active_employees': 1}</field>
    </record>

    <record id="action_fusion_employees_active" model="ir.actions.act_window">
        <field name="name">Active Employees</field>
        <field name="res_model">hr.employee</field>
        <field name="view_mode">kanban,list,form</field>
        <field name="domain">[('employment_status', '=', 'active')]</field>
    </record>

    <record id="action_fusion_employees_on_leave" model="ir.actions.act_window">
        <field name="name">On Leave</field>
        <field name="res_model">hr.employee</field>
        <field name="view_mode">kanban,list,form</field>
        <field name="domain">[('employment_status', '=', 'on_leave')]</field>
    </record>

    <record id="action_fusion_employees_terminated" model="ir.actions.act_window">
        <field name="name">Terminated Employees</field>
        <field name="res_model">hr.employee</field>
        <field name="view_mode">list,form</field>
        <field name="domain">[('employment_status', '=', 'terminated')]</field>
    </record>

    <!-- ============================================================ -->
    <!-- PAYROLL TAX ACTIONS                                           -->
    <!-- ============================================================ -->
    <record id="action_fusion_tax_remittances" model="ir.actions.act_window">
        <field name="name">Tax Remittances</field>
        <field name="res_model">hr.tax.remittance</field>
        <field name="view_mode">list,kanban,form</field>
    </record>

    <!-- ============================================================ -->
    <!-- ROE ACTIONS                                                   -->
    <!-- ============================================================ -->
    <record id="action_fusion_roe" model="ir.actions.act_window">
        <field name="name">Records of Employment</field>
        <field name="res_model">hr.roe</field>
        <field name="view_mode">list,form</field>
    </record>

    <record id="action_fusion_roe_pending" model="ir.actions.act_window">
        <field name="name">Pending ROE</field>
        <field name="res_model">hr.employee</field>
        <field name="view_mode">list,form</field>
        <field name="domain">[('employment_status', '=', 'terminated'), ('roe_issued', '=', False)]</field>
    </record>

    <!-- ============================================================ -->
    <!-- COMPLIANCE ACTIONS                                            -->
    <!-- ============================================================ -->
    <record id="action_fusion_t4_summary" model="ir.actions.act_window">
        <field name="name">T4 Summary</field>
        <field name="res_model">hr.t4.summary</field>
        <field name="view_mode">list,form</field>
    </record>

    <record id="action_fusion_t4_slips" model="ir.actions.act_window">
        <field name="name">T4 Slips</field>
        <field name="res_model">hr.t4.slip</field>
        <field name="view_mode">list,form</field>
    </record>

    <!-- ============================================================ -->
    <!-- CONFIGURATION ACTIONS                                         -->
    <!-- ============================================================ -->
    <record id="action_fusion_salary_rules" model="ir.actions.act_window">
        <field name="name">Salary Rules</field>
        <field name="res_model">hr.salary.rule</field>
        <field name="view_mode">list,form</field>
        <field name="domain">[('struct_id.name', 'ilike', 'canada')]</field>
    </record>

    <record id="action_fusion_rule_parameters" model="ir.actions.act_window">
        <field name="name">Tax Rate Parameters</field>
        <field name="res_model">hr.rule.parameter</field>
        <field name="view_mode">list,form</field>
        <field name="domain">[('code', 'like', 'ca_%')]</field>
    </record>

    <record id="action_fusion_payroll_structure" model="ir.actions.act_window">
        <field name="name">Payroll Structure</field>
        <field name="res_model">hr.payroll.structure</field>
        <field name="view_mode">list,form</field>
        <field name="domain">[('name', 'ilike', 'canada')]</field>
    </record>

    <record id="action_fusion_input_types" model="ir.actions.act_window">
        <field name="name">Input Types</field>
        <field name="res_model">hr.payslip.input.type</field>
        <field name="view_mode">list,form</field>
        <field name="domain">[('country_id.code', '=', 'CA')]</field>
    </record>

    <record id="action_fusion_yearly_rates" model="ir.actions.act_window">
        <field name="name">Yearly Rates (Legacy)</field>
        <field name="res_model">tax.yearly.rates</field>
        <field name="view_mode">list,form</field>
    </record>

    <!-- ============================================================ -->
    <!-- MAIN MENU: FUSION PAYROLL                                     -->
    <!-- ============================================================ -->
    
    <!-- Root Menu under Payroll App -->
    <menuitem id="menu_fusion_payroll_root"
              name="Fusion Payroll"
              parent="hr_work_entry_enterprise.menu_hr_payroll_root"
              sequence="5"/>

    <!-- ============================================================ -->
    <!-- SUBMENU: DASHBOARD                                            -->
    <!-- ============================================================ -->
    <menuitem id="menu_fusion_dashboard"
              name="Dashboard"
              parent="menu_fusion_payroll_root"
              action="action_fusion_dashboard_employees"
              sequence="1"/>

    <!-- ============================================================ -->
    <!-- SUBMENU: RUN PAYROLL                                          -->
    <!-- ============================================================ -->
    <menuitem id="menu_fusion_run_payroll"
              name="Run Payroll"
              parent="menu_fusion_payroll_root"
              sequence="10"/>

    <menuitem id="menu_fusion_run_payroll_wizard"
              name="Run Payroll"
              parent="menu_fusion_run_payroll"
              action="action_open_run_payroll"
              sequence="5"/>

    <menuitem id="menu_fusion_payroll_batches"
              name="Payroll Batches"
              parent="menu_fusion_run_payroll"
              action="action_fusion_run_payroll"
              sequence="10"/>

    <menuitem id="menu_fusion_payslips"
              name="All Payslips"
              parent="menu_fusion_run_payroll"
              action="action_fusion_payslips"
              sequence="20"/>

    <menuitem id="menu_fusion_pay_periods"
              name="Pay Periods"
              parent="menu_fusion_run_payroll"
              action="action_payroll_pay_period"
              sequence="25"/>

    <!-- ============================================================ -->
    <!-- SUBMENU: EMPLOYEES                                            -->
    <!-- ============================================================ -->
    <menuitem id="menu_fusion_employees"
              name="Employees"
              parent="menu_fusion_payroll_root"
              sequence="20"/>

    <menuitem id="menu_fusion_employees_all"
              name="All Employees"
              parent="menu_fusion_employees"
              action="action_fusion_employees"
              sequence="10"/>

    <menuitem id="menu_fusion_employees_active"
              name="Active"
              parent="menu_fusion_employees"
              action="action_fusion_employees_active"
              sequence="20"/>

    <menuitem id="menu_fusion_employees_on_leave"
              name="On Leave"
              parent="menu_fusion_employees"
              action="action_fusion_employees_on_leave"
              sequence="30"/>

    <menuitem id="menu_fusion_employees_terminated"
              name="Terminated"
              parent="menu_fusion_employees"
              action="action_fusion_employees_terminated"
              sequence="40"/>

    <!-- ============================================================ -->
    <!-- SUBMENU: TAX COMPLIANCE (Combined)                            -->
    <!-- ============================================================ -->
    <menuitem id="menu_fusion_payroll_tax"
              name="Tax &amp; Compliance"
              parent="menu_fusion_payroll_root"
              sequence="30"/>

    <menuitem id="menu_fusion_tax_remittances"
              name="CRA Remittances"
              parent="menu_fusion_payroll_tax"
              action="action_fusion_tax_remittances"
              sequence="10"/>

    <menuitem id="menu_fusion_t4_summary"
              name="T4 Summary"
              parent="menu_fusion_payroll_tax"
              action="action_fusion_t4_summary"
              sequence="20"/>

    <menuitem id="menu_fusion_t4_slips"
              name="T4 Slips"
              parent="menu_fusion_payroll_tax"
              action="action_fusion_t4_slips"
              sequence="30"/>

    <record id="action_fusion_t4a_summary" model="ir.actions.act_window">
        <field name="name">T4A Summary</field>
        <field name="res_model">hr.t4a.summary</field>
        <field name="view_mode">list,form</field>
    </record>

    <record id="action_fusion_t4a_slips" model="ir.actions.act_window">
        <field name="name">T4A Slips</field>
        <field name="res_model">hr.t4a.slip</field>
        <field name="view_mode">list,form</field>
    </record>

    <menuitem id="menu_fusion_t4a_summary"
              name="T4A Summary"
              parent="menu_fusion_payroll_tax"
              action="action_fusion_t4a_summary"
              sequence="40"/>

    <menuitem id="menu_fusion_t4a_slips"
              name="T4A Slips"
              parent="menu_fusion_payroll_tax"
              action="action_fusion_t4a_slips"
              sequence="50"/>

    <!-- ============================================================ -->
    <!-- SUBMENU: ROE (RECORD OF EMPLOYMENT)                           -->
    <!-- ============================================================ -->
    <menuitem id="menu_fusion_roe"
              name="Record of Employment"
              parent="menu_fusion_payroll_root"
              sequence="40"/>

    <menuitem id="menu_fusion_roe_all"
              name="All ROEs"
              parent="menu_fusion_roe"
              action="action_fusion_roe"
              sequence="10"/>

    <menuitem id="menu_fusion_roe_pending"
              name="Pending ROE"
              parent="menu_fusion_roe"
              action="action_fusion_roe_pending"
              sequence="20"/>

    <!-- ============================================================ -->
    <!-- REPORTS ACTIONS                                               -->
    <!-- ============================================================ -->
    
    <!-- Report Hub Action - Shows all reports in a grid -->
    <record id="action_fusion_report_hub_page" model="ir.actions.client">
        <field name="name">Payroll Reports</field>
        <field name="tag">fusion_payroll.report_hub</field>
    </record>

    <!-- Paycheque/Payslip Reports -->
    <record id="action_report_paycheque_history" model="ir.actions.act_window">
        <field name="name">Paycheque History</field>
        <field name="res_model">hr.payslip</field>
        <field name="view_mode">list,form</field>
        <field name="domain">[('state', '=', 'done')]</field>
        <field name="context">{'search_default_group_employee': 1}</field>
    </record>

    <record id="action_report_payroll_deductions" model="ir.actions.act_window">
        <field name="name">Payroll Deductions/Contributions</field>
        <field name="res_model">hr.payslip.line</field>
        <field name="view_mode">list,pivot,graph</field>
        <field name="domain">[('category_id.code', 'in', ['DED', 'COMP'])]</field>
        <field name="context">{'search_default_group_category': 1}</field>
    </record>

    <record id="action_report_payroll_summary_employee" model="ir.actions.act_window">
        <field name="name">Payroll Summary by Employee</field>
        <field name="res_model">hr.payslip</field>
        <field name="view_mode">pivot,list,graph</field>
        <field name="context">{'search_default_group_employee': 1}</field>
    </record>

    <!-- Employee Reports -->
    <record id="action_report_employee_directory" model="ir.actions.act_window">
        <field name="name">Employee Directory</field>
        <field name="res_model">hr.employee</field>
        <field name="view_mode">list,kanban,form</field>
        <field name="domain">[('employment_status', '=', 'active')]</field>
    </record>

    <record id="action_report_employee_details" model="ir.actions.act_window">
        <field name="name">Employee Details</field>
        <field name="res_model">hr.employee</field>
        <field name="view_mode">list,form</field>
    </record>

    <record id="action_report_multiple_worksites" model="ir.actions.act_window">
        <field name="name">Multiple Worksites</field>
        <field name="res_model">hr.employee</field>
        <field name="view_mode">list,form</field>
        <field name="context">{'search_default_group_department': 1}</field>
    </record>

    <!-- Payroll Details Reports -->
    <record id="action_report_payroll_details" model="ir.actions.act_window">
        <field name="name">Payroll Details</field>
        <field name="res_model">hr.payslip.line</field>
        <field name="view_mode">list,pivot,graph</field>
    </record>

    <record id="action_report_payroll_item_list" model="ir.actions.act_window">
        <field name="name">Payroll Item List</field>
        <field name="res_model">hr.salary.rule</field>
        <field name="view_mode">list,form</field>
    </record>

    <record id="action_report_payroll_summary" model="ir.actions.act_window">
        <field name="name">Payroll Summary</field>
        <field name="res_model">hr.payslip.run</field>
        <field name="view_mode">list,pivot,form</field>
    </record>

    <record id="action_report_vacation_sick" model="ir.actions.act_window">
        <field name="name">Vacation and Sick Leave</field>
        <field name="res_model">hr.leave</field>
        <field name="view_mode">list,calendar,pivot</field>
    </record>

    <!-- Tax Reports -->
    <record id="action_report_retirement_plans" model="ir.actions.act_window">
        <field name="name">Retirement Plans</field>
        <field name="res_model">hr.payslip.line</field>
        <field name="view_mode">list,pivot</field>
        <field name="domain">[('salary_rule_id.code', 'ilike', 'rrsp')]</field>
    </record>

    <record id="action_report_tax_liability" model="ir.actions.act_window">
        <field name="name">Payroll Tax Liability</field>
        <field name="res_model">hr.tax.remittance</field>
        <field name="view_mode">list,pivot,graph</field>
    </record>

    <record id="action_report_tax_payments" model="ir.actions.act_window">
        <field name="name">Payroll Tax Payments</field>
        <field name="res_model">hr.tax.remittance</field>
        <field name="view_mode">list,form</field>
        <field name="domain">[('state', '=', 'paid')]</field>
    </record>

    <record id="action_report_total_payroll_cost" model="ir.actions.act_window">
        <field name="name">Total Payroll Cost</field>
        <field name="res_model">hr.payslip.run</field>
        <field name="view_mode">pivot,graph,list</field>
    </record>

    <record id="action_report_total_pay" model="ir.actions.act_window">
        <field name="name">Total Pay</field>
        <field name="res_model">hr.payslip</field>
        <field name="view_mode">pivot,graph,list</field>
        <field name="domain">[('state', '=', 'done')]</field>
    </record>

    <record id="action_report_tax_wage_summary" model="ir.actions.act_window">
        <field name="name">Payroll Tax and Wage Summary</field>
        <field name="res_model">hr.payslip</field>
        <field name="view_mode">pivot,graph,list</field>
    </record>

    <record id="action_report_workers_comp" model="ir.actions.act_window">
        <field name="name">Workers' Compensation</field>
        <field name="res_model">hr.payslip.line</field>
        <field name="view_mode">list,pivot</field>
        <field name="domain">[('salary_rule_id.code', 'ilike', 'wsib')]</field>
    </record>

    <!-- Time Activities -->
    <record id="action_report_time_activities" model="ir.actions.act_window">
        <field name="name">Recent/Edited Time Activities</field>
        <field name="res_model">hr.work.entry</field>
        <field name="view_mode">list,calendar</field>
        <field name="context">{'search_default_filter_today': 1}</field>
    </record>

    <record id="action_report_time_by_employee" model="ir.actions.act_window">
        <field name="name">Time Activities by Employee Detail</field>
        <field name="res_model">hr.work.entry</field>
        <field name="view_mode">list,pivot,calendar</field>
        <field name="context">{'search_default_group_employee': 1}</field>
    </record>

    <!-- ============================================================ -->
    <!-- SUBMENU: REPORTS (single menu linking to reports page)        -->
    <!-- ============================================================ -->
    <menuitem id="menu_fusion_reports"
              name="Reports"
              parent="menu_fusion_payroll_root"
              action="action_fusion_report_hub_page"
              sequence="90"/>

    <!-- ============================================================ -->
    <!-- SUBMENU: SETTINGS (Company-level payroll settings)           -->
    <!-- ============================================================ -->
    <menuitem id="menu_fusion_payroll_settings"
              name="Settings"
              parent="menu_fusion_payroll_root"
              action="action_payroll_config_settings"
              sequence="95"/>

    <!-- ============================================================ -->
    <!-- SUBMENU: CONFIGURATION (Technical config for admins)          -->
    <!-- ============================================================ -->
    <menuitem id="menu_fusion_config"
              name="Configuration"
              parent="menu_fusion_payroll_root"
              sequence="100"
              groups="base.group_system"/>

    <menuitem id="menu_fusion_config_rules"
              name="Salary Rules"
              parent="menu_fusion_config"
              action="action_fusion_salary_rules"
              sequence="10"/>

    <menuitem id="menu_fusion_config_params"
              name="Tax Rate Parameters"
              parent="menu_fusion_config"
              action="action_fusion_rule_parameters"
              sequence="20"/>

    <menuitem id="menu_fusion_config_structure"
              name="Payroll Structure"
              parent="menu_fusion_config"
              action="action_fusion_payroll_structure"
              sequence="30"/>

    <menuitem id="menu_fusion_config_inputs"
              name="Input Types"
              parent="menu_fusion_config"
              action="action_fusion_input_types"
              sequence="40"/>

    <menuitem id="menu_fusion_config_yearly"
              name="Yearly Rates (Legacy)"
              parent="menu_fusion_config"
              action="action_fusion_yearly_rates"
              sequence="50"/>

    <menuitem id="menu_fusion_work_locations"
              name="Work Locations"
              parent="menu_fusion_config"
              action="action_payroll_work_location"
              sequence="60"/>

    <record id="action_pdf_field_position" model="ir.actions.act_window">
        <field name="name">PDF Field Positions</field>
        <field name="res_model">pdf.field.position</field>
        <field name="view_mode">list,form</field>
        <field name="context">{'search_default_active': 1}</field>
    </record>

    <menuitem id="menu_fusion_pdf_field_positions"
              name="PDF Field Positions"
              parent="menu_fusion_config"
              action="action_pdf_field_position"
              sequence="70"/>

    <menuitem id="menu_cheque_layout_settings"
              name="Cheque Layout"
              parent="menu_fusion_config"
              action="action_cheque_layout_settings"
              sequence="75"/>

</odoo>
