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

    <record id="view_account_invoice_filter" model="ir.ui.view">
        <field name="name">account.move.select</field>
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_account_invoice_filter"/>
        <field name="arch" type="xml">
            <field name="partner_id" position="after">
                <field name="l10n_latam_document_type_id"/>
            </field>
            <group>
                <filter string="Document Type" name="l10n_latam_document_type" domain="" context="{'group_by':'l10n_latam_document_type_id'}"/>
            </group>
        </field>
    </record>

    <record id="view_account_move_filter" model="ir.ui.view">
        <field name="name">account.move.filter</field>
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_account_move_filter"/>
        <field name="arch" type="xml">
            <field name="partner_id" position="after">
                <field name="l10n_latam_document_type_id"/>
            </field>
            <group>
                <filter string="Document Type" name="l10n_latam_document_type" domain="" context="{'group_by':'l10n_latam_document_type_id'}"/>
            </group>
        </field>
    </record>

    <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">
            <form>
                <field name="l10n_latam_available_document_type_ids" invisible="1"/>
                <field name="l10n_latam_use_documents" invisible="1"/>
                <field name="l10n_latam_manual_document_number" invisible="1"/>
            </form>

            <xpath expr="//div[@name='journal_div']" position="after">
                <field name="l10n_latam_document_type_id"
                    invisible="not l10n_latam_use_documents"
                    readonly="posted_before"
                    required="partner_id and l10n_latam_use_documents"
                    domain="[('id', 'in', l10n_latam_available_document_type_ids)]" options="{'no_open': True, 'no_create': True}"/>
                <field name="l10n_latam_document_number"
                    invisible="(not l10n_latam_use_documents or not l10n_latam_manual_document_number) and (not l10n_latam_use_documents or highest_name or state != 'draft')"
                    readonly="posted_before and state != 'draft'"
                    required="partner_id and l10n_latam_use_documents and l10n_latam_manual_document_number"/>
            </xpath>

            <!-- on latam_documents we use document_number to set name -->
            <field name="name" position="attributes">
                <attribute name="readonly">state != 'draft' or l10n_latam_use_documents</attribute>
                <attribute name="force_save">1</attribute>
            </field>

        </field>
    </record>

</odoo>
