<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <!-- Form  -->
    <record id="view_hr_fiscalyear_form" model="ir.ui.view">
        <field name="name">hr.fiscalyear.form</field>
        <field name="model">hr.fiscalyear</field>
        <field name="arch" type="xml">
            <form string="Fiscal Year">
                <header>
                    <button
                        name="create_periods"
                        string="Create Periods"
                        type="object"
                        class="btn-primary"
                        states="draft"
                    />
                    <button
                        name="button_set_to_draft"
                        string="Set To Draft"
                        type="object"
                        states="open"
                    />
                    <button
                        name="button_confirm"
                        string="Confirm"
                        type="object"
                        class="btn-primary"
                        states="draft"
                    />
                    <field name="state" widget="statusbar" nolabel="1" />
                </header>
                <sheet>
                    <div class="oe_title">
                        <label for="name" class="oe_edit_only" />
                        <h1>
                            <field name="name" placeholder="Fiscal year..." />
                        </h1>
                    </div>
                    <group>
                        <group>
                            <field name="schedule_pay" />
                            <label for="date_start" string="Period" />
                            <div>
                                <field
                                    name="date_start"
                                    widget="daterange"
                                    class="oe_inline"
                                    options="{'related_end_date': 'date_end'}"
                                />
                                -
                                <field
                                    name="date_end"
                                    widget="daterange"
                                    class="oe_inline"
                                    options="{'related_start_date': 'date_start'}"
                                />
                            </div>
                        </group>
                        <group>
                            <field
                                name="company_id"
                                groups="base.group_multi_company"
                            />
                        <field name="type_id" domain="[('hr_fiscal_year','=',True)]" />
                        </group>
                        <group>
                            <field
                                name="payment_day"
                                attrs="{
                                'invisible': [('schedule_pay', 'in', ['weekly', 'bi-weekly'])],
                                'required': [('schedule_pay', 'not in', ['weekly', 'bi-weekly'])],
                            }"
                            />
                            <newline />
                            <field
                                name="payment_weekday"
                                attrs="{
                                'invisible': [('schedule_pay', 'not in', ['weekly', 'bi-weekly'])],
                                'required': [('schedule_pay', 'in', ['weekly', 'bi-weekly'])],
                            }"
                            />
                            <field
                                name="payment_week"
                                attrs="{
                                'invisible': [('schedule_pay', 'not in', ['weekly', 'bi-weekly'])],
                                'required': [('schedule_pay', 'in', ['weekly', 'bi-weekly'])],
                            }"
                            />
                        </group>
                    </group>
                    <field colspan="4" name="period_ids" nolabel="1" />
                </sheet>
            </form>
        </field>
    </record>
    <!-- Tree -->
    <record id="view_hr_fiscalyear_tree" model="ir.ui.view">
        <field name="name">hr.fiscalyear.tree</field>
        <field name="model">hr.fiscalyear</field>
        <field name="arch" type="xml">
            <tree
                decoration-info="state == 'draft'"
                decoration-muted="state == 'done'"
                name="Fiscalyear"
            >
                <field name="name" />
                <field name="company_id" groups="base.group_multi_company" />
                <field name="state" />
            </tree>
        </field>
    </record>
    <!-- Search -->
    <record id="view_hr_fiscalyear_search" model="ir.ui.view">
        <field name="name">hr.fiscalyear.search</field>
        <field name="model">hr.fiscalyear</field>
        <field name="arch" type="xml">
            <search string="Search Fiscalyear">
                <field
                    name="name"
                    filter_domain="[('name', 'ilike', self)]"
                    string="Fiscal Year"
                />
                <field name="schedule_pay" />
                <field name="payment_weekday" />
                <field name="payment_day" />
                <filter
                    name="open"
                    string="Open"
                    domain="[('state', '=', 'open')]"
                    icon="terp-camera_test"
                />
                <filter
                    name="closed"
                    string="Closed"
                    domain="[('state', '=', 'done')]"
                    icon="terp-dialog-close"
                />
                <field name="state" />
                <group expand="0" string="Group By...">
                    <filter
                        name="Status"
                        context="{'group_by': 'state'}"
                        icon="terp-stock_effects-object-colorize"
                    />
                </group>
            </search>
        </field>
    </record>
    <!-- Action -->
    <record id="action_hr_fiscalyear" model="ir.actions.act_window">
        <field name="name">Payroll Fiscal Years</field>
        <field name="res_model">hr.fiscalyear</field>
        <field name="view_mode">tree,form</field>
        <field name="domain">[('type_id.hr_fiscal_year','=',True)]</field>
    </record>
    <!-- Menu -->
    <menuitem
        id="menu_action_hr_fiscalyear"
        action="action_hr_fiscalyear"
        parent="hr_payroll_period.hr_period_configure"
        sequence="25"
    />
</odoo>
