<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="l10n_dk_nemhandel_view_move_form" model="ir.ui.view">
        <field name="name">l10n.dk.nemhandel.view.move.form</field>
        <field name="model">account.move</field>
        <field name="priority">30</field>
        <field name="inherit_id" ref="account.view_move_form"/>
        <field name="arch" type="xml">
            <header position="inside">
                <button name="action_cancel_nemhandel_documents"
                        type="object"
                        class="btn btn-secondary"
                        string="Cancel Nemhandel"
                        invisible="nemhandel_move_state != 'to_send' or state == 'draft'"/>
            </header>
            <xpath expr="//div[@name='journal_div']" position="after">
                <label for="nemhandel_move_state"
                       invisible="not nemhandel_move_state or state == 'draft' or move_type in ('in_invoice', 'in_refund')"/>
                <div name="nemhandel_div"
                     class="d-flex"
                     invisible="not nemhandel_move_state or state == 'draft' or move_type in ('in_invoice', 'in_refund')">
                    <field name="nemhandel_move_state" class="oe_inline"/>
                    <span class="mx-1" invisible="'demo_' not in nemhandel_message_uuid"> (Demo)</span>
                    <span class="text-muted mx-3"
                          invisible="nemhandel_move_state != 'to_send'">
                        The invoice will be sent automatically via Nemhandel
                    </span>
                </div>
            </xpath>
        </field>
    </record>

    <record id="nemhandel_view_out_invoice_tree_inherit" model="ir.ui.view">
        <field name="name">account.move.out.invoice.tree.inherit</field>
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_out_invoice_tree"/>
        <field name="arch" type="xml">
            <field name="status_in_payment" position="before">
                <field name="nemhandel_move_state" optional="hide"/>
            </field>
        </field>
    </record>

    <record id="nemhandel_view_out_credit_note_tree_inherit" model="ir.ui.view">
        <field name="name">account.move.credit.note.tree.inherit</field>
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_out_credit_note_tree"/>
        <field name="arch" type="xml">
            <field name="status_in_payment" position="before">
                <field name="nemhandel_move_state" optional="show"/>
            </field>
        </field>
    </record>

    <record id="nemhandel_view_account_invoice_filter" model="ir.ui.view">
        <field name="name">account.invoice.select.inherit</field>
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_account_invoice_filter"/>
        <field name="arch" type="xml">
            <xpath expr="//search/group/filter[@name='status']" position="after">
                <filter string="Nemhandel status" name="nemhandel_move_state" context="{'group_by': 'nemhandel_move_state'}"/>
            </xpath>
            <xpath expr="//filter[@name='to_check']" position='after'>
                <separator/>
                <filter name="nemhandel_ready"
                        string="Nemhandel Ready"
                        domain="[('state', '=', 'posted'), ('nemhandel_move_state', '=', 'ready'), ('move_type', 'in', ('out_invoice', 'out_refund', 'out_receipt'))]"/>
                <separator/>
            </xpath>
        </field>
    </record>
</odoo>
