<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="view_move_form" 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="//group[@id='header_right_group']" position="inside">
                    <field name="l10n_jo_edi_invoice_type"
                        readonly="state != 'draft'"
                        invisible="country_code != 'JO' or move_type not in ('out_invoice', 'out_refund')"/>
                </xpath>
                <xpath expr="//sheet" position="before">
                    <div class="alert alert-warning" role="alert" invisible="not l10n_jo_edi_error">
                        <div class="p-0 m-0">
                            <span class="mx-1"><b>Warning</b>: this invoice cannot be sent to JoFotara.</span>
                            <a name="download_l10n_jo_edi_computed_xml" type="object" groups="base.group_no_one" class="float-end">Download XML</a>
                        </div>
                        <field name="l10n_jo_edi_error"/>
                    </div>
                </xpath>
                <xpath expr="//group[@name='sale_info_group']" position="inside">
                    <field name="l10n_jo_edi_qr" invisible="1"/>
                    <field name="l10n_jo_edi_state" invisible="country_code != 'JO'" readonly="l10n_jo_edi_qr"/>
                    <field name="l10n_jo_edi_is_needed" invisible="1"/>
                    <field name="reversed_entry_id"
                        invisible="move_type != 'out_refund' or not l10n_jo_edi_is_needed"
                        domain="[('move_type', '=', 'out_invoice')]"
                        readonly="l10n_jo_edi_state == 'sent'"
                        groups="base.group_no_one"/>
                </xpath>
            </field>
        </record>

        <record id="view_out_invoice_tree" model="ir.ui.view">
            <field name="name">account.move.tree</field>
            <field name="model">account.move</field>
            <field name="inherit_id" ref="account.view_out_invoice_tree"/>
            <field name="arch" type="xml">
                <field name="payment_reference" position="before">
                    <field name="l10n_jo_edi_invoice_type" string="JoFotara Invoice Type" optional="hide"/>
                    <field name="l10n_jo_edi_state" optional="hide"/>
                    <field name="l10n_jo_edi_error" optional="hide"/>
                </field>
            </field>
        </record>

        <record id="view_out_credit_note_tree" model="ir.ui.view">
            <field name="name">account.move.tree</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="payment_reference" position="before">
                    <field name="l10n_jo_edi_invoice_type" string="JoFotara Invoice Type" optional="hide"/>
                    <field name="l10n_jo_edi_state" optional="hide"/>
                    <field name="l10n_jo_edi_error" optional="hide"/>
                </field>
            </field>
        </record>

        <record id="view_account_invoice_filter" model="ir.ui.view">
            <field name="name">account.invoice.select</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='groupy_by_journal']" position="after">
                    <filter name="l10n_jo_edi_state" context="{'group_by': 'l10n_jo_edi_state'}"/>
                    <filter name="l10n_jo_edi_invoice_type" string="JoFotara Invoice Type" context="{'group_by': 'l10n_jo_edi_invoice_type'}"/>
                </xpath>
            </field>
        </record>
    </data>
</odoo>
