<?xml version='1.0' encoding='utf-8'?>
<odoo>
    <record id="view_move_line_tree" model="ir.ui.view">
        <field name="name">account.move.line.list</field>
        <field name="model">account.move.line</field>
        <field name="inherit_id" ref="account.view_move_line_tree"/>
        <field name="mode">extension</field>
        <field name="arch" type="xml">
            <xpath expr="//list" position="attributes">
                <attribute name="js_class">account_move_line_list</attribute>
            </xpath>
            <xpath expr="//list" position="inside">
                <header>
                    <button name="action_reconcile" type="object" string="Reconcile" groups="account.group_account_user"
                            data-hotkey="r"/>
                    <button name="turn_as_asset" type="object" string="Create Asset" groups="account.group_account_user"
                        data-hotkey="c"/>
                </header>
                <field name="is_account_reconcile" column_invisible="True"/>
                <field name="has_deferred_moves" column_invisible="True"/>
            </xpath>
            <xpath expr="//list/field[@name='name']" position="after">
                <field name="deferred_start_date" optional="hide" readonly="has_deferred_moves"/>
                <field name="deferred_end_date" optional="hide" readonly="has_deferred_moves"/>
            </xpath>
            <xpath expr="//list/field[@name='matching_number']" position="attributes">
                <attribute name="widget">matching_link_widget</attribute>
            </xpath>
        </field>
    </record>

    <record id="view_move_line_payment_tree" model="ir.ui.view">
        <field name="name">account.move.line.payment.list</field>
        <field name="model">account.move.line</field>
        <field name="inherit_id" ref="account.view_move_line_payment_tree"/>
        <field name="mode">extension</field>
        <field name="arch" type="xml">
            <xpath expr="//button[@name='action_payment_items_register_payment']" position="after">
                <button name="action_reconcile" type="object" string="Reconcile" groups="account.group_account_user"/>
            </xpath>
        </field>
    </record>

    <record id="view_move_form_inherit" model="ir.ui.view">
        <field name="name">account.move.form.inherit</field>
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_move_form"/>
        <field name="arch" type="xml">
            <xpath expr="//page[@id='other_tab']//field[@name='fiscal_position_id']" position="after">
                <field name="inalterable_hash" groups="base.group_no_one"/>
            </xpath>
            <xpath expr="//page[@id='other_tab_entry']//field[@name='company_id']" position="after">
                <field name="inalterable_hash" groups="base.group_no_one"/>
            </xpath>
            <xpath expr="//list/field[@name='analytic_distribution']" position="after">
                <field name="has_abnormal_deferred_dates" column_invisible="1"/>
                <field name="deferred_start_date" optional="hide" decoration-warning="has_abnormal_deferred_dates"/>
                <field name="deferred_end_date" optional="hide" decoration-warning="has_abnormal_deferred_dates"/>
            </xpath>
            <xpath expr="//div[@name='button_box']" position="inside">
                <button name="action_open_bank_reconciliation_widget_statement"
                        class="oe_stat_button"
                        icon="fa-bars"
                        type="object"
                        invisible="not statement_id or state == 'cancel'">
                    <div class="o_stat_info">
                        <span class="o_stat_text">Bank Statement</span>
                    </div>
                </button>
                <button name="action_open_bank_reconciliation_widget"
                        class="oe_stat_button"
                        icon="fa-bars"
                        type="object"
                        invisible="move_type != 'entry' or not id or not statement_line_id or state == 'cancel'">
                    <div class="o_stat_info">
                        <span class="o_stat_text">1 Bank Transaction</span>
                    </div>
                </button>
                <field name="deferred_move_ids" invisible="1"/>
                <field name="deferred_original_move_ids" invisible="1"/>
                <field name="deferred_entry_type" invisible="1"/>
                <button name="open_deferred_entries"
                        class="oe_stat_button"
                        icon="fa-bars"
                        type="object"
                        invisible="not deferred_move_ids"
                        string="Deferred Entries">
                </button>
                <button name="open_deferred_original_entry"
                        class="oe_stat_button"
                        icon="fa-bars"
                        type="object"
                        invisible="deferred_entry_type == 'revenue' or not deferred_original_move_ids"
                        string="Related Purchase(s)">
                </button>
                <button name="open_deferred_original_entry"
                        class="oe_stat_button"
                        icon="fa-bars"
                        type="object"
                        invisible="deferred_entry_type == 'expense' or not deferred_original_move_ids"
                        string="Related Sale(s)">
                </button>
            </xpath>
        </field>
    </record>

    <record id="view_deferred_entries_tree" model="ir.ui.view">
        <field name="name">account.move.line.deferral.entries.list</field>
        <field name="model">account.move.line</field>
        <field name="inherit_id" ref="account.view_move_line_tree"/>
        <field name="mode">primary</field>
        <field name="arch" type="xml">
            <xpath expr="//list" position="attributes">
                <attribute name="default_order">date</attribute>
            </xpath>
            <xpath expr="//field[@name='tax_ids']" position="attributes">
                <attribute name="optional">hide</attribute>
            </xpath>
            <xpath expr="//field[@name='amount_currency']" position="attributes">
                <attribute name="optional">hide</attribute>
            </xpath>
            <xpath expr="//field[@name='analytic_distribution']" position="attributes">
                <attribute name="optional">hide</attribute>
            </xpath>
            <xpath expr="//field[@name='discount_date']" position="attributes">
                <attribute name="column_invisible">1</attribute>
            </xpath>
            <xpath expr="//field[@name='discount_amount_currency']" position="attributes">
                <attribute name="column_invisible">1</attribute>
            </xpath>
            <xpath expr="//field[@name='date_maturity']" position="attributes">
                <attribute name="column_invisible">1</attribute>
            </xpath>
        </field>
    </record>


    <record id="view_archived_tag_move_tree" model="ir.ui.view">
        <field name="name">account.archived.tax.tag.list</field>
        <field name="model">account.move.line</field>
        <field name="inherit_id" ref="account.view_move_line_tree"/>
        <field name="mode">primary</field>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='tax_ids']" position="attributes">
                <attribute name="optional">show</attribute>
            </xpath>
            <xpath expr="//field[@name='tax_tag_ids']" position="attributes">
                <attribute name="optional">show</attribute>
            </xpath>
            <xpath expr="//field[@name='matching_number']" position="attributes">
                <attribute name="optional">hide</attribute>
            </xpath>
        </field>
    </record>

    <record id="view_journal_report_audit_move_line_tree" model="ir.ui.view">
        <field name="name">account.journal.report.audit.move.line.list</field>
        <field name="model">account.move.line</field>
        <field name="inherit_id" ref="account.view_move_line_tree"/>
        <field name="mode">primary</field>
        <field name="arch" type="xml">
            <list name="move_line_tree" position="attributes">
                <attribute name="js_class">account_move_line_journal_report_list</attribute>
            </list>
            <button name="edit" position="replace">
                <button name="open_partner" type="object" string="View" title="View Partner"/>
            </button>
            <groupby name="partner_id" position="after">
                <groupby name="move_id">
                    <button name="button_set_checked" type="object" string="Set as Checked"
                            invisible="checked or state == 'draft'"/>
                </groupby>
            </groupby>
            <field name="invoice_date" position="attributes">
                <attribute name="optional">show</attribute>
            </field>
            <field name="account_id" position="attributes">
                <attribute name="optional">show</attribute>
            </field>
            <field name="tax_ids" position="attributes">
                <attribute name="optional">show</attribute>
            </field>
            <field name="date" position="attributes">
                <attribute name="optional">hide</attribute>
            </field>
            <field name="matching_number" position="attributes">
                <attribute name="optional">hide</attribute>
            </field>
            <field name="partner_id" position="attributes">
                <attribute name="optional">hide</attribute>
            </field>

        </field>
    </record>

    <record id="view_journal_report_audit_bank_move_line_tree" model="ir.ui.view">
        <field name="name">account.journal.report.audit.bank.move.line.tree</field>
        <field name="model">account.move.line</field>
        <field name="inherit_id" ref="fusion_accounting.view_journal_report_audit_move_line_tree"/>
        <field name="mode">primary</field>
        <field name="arch" type="xml">
            <field name="invoice_date" position="attributes">
                <attribute name="optional">hide</attribute>
            </field>
            <field name="date" position="attributes">
                <attribute name="optional">show</attribute>
            </field>
            <field name="matching_number" position="attributes">
                <attribute name="optional">show</attribute>
            </field>
            <field name="partner_id" position="attributes">
                <attribute name="optional">show</attribute>
            </field>
        </field>
    </record>

    <record id="view_journal_report_audit_move_line_search" model="ir.ui.view">
        <field name="name">account.journal.report.audit.move.line.search</field>
        <field name="model">account.move.line</field>
        <field name="inherit_id" ref="account.view_account_move_line_filter"/>
        <field name="arch" type="xml">
            <field name="journal_id" position="after">
                <field name="exclude_bank_lines"/>
            </field>
            <filter name="group_by_move" position="attributes">
                <attribute name="context">{'group_by': 'move_id'}</attribute>
            </filter>
            <filter name="sales" position="before">
                <filter string="Invoice lines" name="invoices_lines" domain="[('display_type','=','product')]"
                        invisible="1"/>
                <filter string="Exclude Bank lines" name="search_default_exclude_bank_lines"
                        domain="[('exclude_bank_lines','=', True)]" invisible="1"/>
            </filter>
        </field>
    </record>


    <record id="view_move_form_asset_inherit" model="ir.ui.view">
        <field name="name">account.move.form</field>
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_move_form"/>
        <field name="arch" type="xml">
            <xpath expr="//div[hasclass('oe_button_box')]" position="inside">
                <field name="asset_id" invisible="1"/>
                <field name="asset_ids" invisible="1"/>
                <field name="count_asset" invisible="1"/>
                <field name="draft_asset_exists" invisible="1"/>
                <button name="open_asset_view"
                        invisible="not asset_id"
                        class="oe_stat_button"
                        icon="fa-cube"
                        type="object">
                    <field name="asset_id_display_name" nolabel="1"/>
                </button>
                <button name="action_open_asset_ids"
                        type="object"
                        class="oe_stat_button"
                        icon="fa-id-card-o"
                        invisible="count_asset == 0 or draft_asset_exists">
                    <field string="Asset(s)" name="count_asset" widget="statinfo"/>
                </button>
                <button name="action_open_asset_ids"
                        type="object"
                        class="oe_stat_button text-danger"
                        icon="fa-id-card-o"
                        invisible="count_asset == 0 or not draft_asset_exists">
                    <field string="Asset(s)" name="count_asset" widget="statinfo"/>
                </button>
            </xpath>
            <xpath expr="//page[@id='other_tab']//group[@name='accounting_info_group']" position="inside">
                <field name="asset_move_type" invisible="not asset_id and not asset_ids" readonly="0"/>
            </xpath>
            <xpath expr="//page[@id='other_tab_entry']//group[@id='other_tab_entry_group']//group[@name='misc_group']"
                   position="inside">
                <field name="asset_move_type" invisible="not asset_id and not asset_ids" readonly="0"/>
            </xpath>
        </field>
    </record>

    <record id="view_move_line_form_asset_inherit" model="ir.ui.view">
        <field name="name">account.move.line.form</field>
        <field name="model">account.move.line</field>
        <field name="inherit_id" ref="account.view_move_line_form"/>
        <field name="arch" type="xml">
            <field name="move_id" position="after">
                <group string="Related Assets" invisible="not asset_ids">
                    <field name="asset_ids" nolabel="1"/>
                </group>
            </field>
        </field>
    </record>

    <record model="ir.actions.server" id="action_account_aml_to_asset">
        <field name="name">Create Asset</field>
        <field name="group_ids" eval="[(4, ref('account.group_account_user'))]"/>
        <field name="model_id" ref="account.model_account_move_line"/>
        <field name="binding_model_id" ref="account.model_account_move_line"/>
        <field name="state">code</field>
        <field name="code">
            if records:
            action = records.turn_as_asset()
        </field>
    </record>
</odoo>
