<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2019 Tecnativa - David Vidal
     License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
    <record id="view_move_form" model="ir.ui.view">
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_move_form" />
        <field name="arch" type="xml">
            <xpath expr="//field[@name='invoice_payment_term_id']/.." position="after">
                <field
                    name="global_discount_ids"
                    widget="many2many_tags"
                    placeholder="Discounts..."
                    readonly="state != 'draft'"
                    groups="base_global_discount.group_global_discount"
                />
                <field
                    string="Invoice Global Discounts"
                    name="global_discount_ids_readonly"
                    widget="many2many_tags"
                    readonly="1"
                    groups="!base_global_discount.group_global_discount"
                />
            </xpath>
            <field name="tax_totals" position="before">
                <field
                    name="amount_untaxed_before_global_discounts"
                    string="Untaxed Amount Before Disc."
                    invisible="not global_discount_ids or not invoice_global_discount_ids"
                    groups="base_global_discount.group_global_discount"
                />
                <field
                    name="amount_untaxed_before_global_discounts"
                    string="Untaxed Amount Before Disc."
                    invisible="not global_discount_ids_readonly or not invoice_global_discount_ids"
                    groups="!base_global_discount.group_global_discount"
                />
                <field
                    name="amount_global_discount"
                    string="Global Discounts"
                    invisible="not global_discount_ids or not invoice_global_discount_ids"
                    groups="base_global_discount.group_global_discount"
                />
                <field
                    name="amount_global_discount"
                    string="Global Discounts"
                    invisible="not global_discount_ids_readonly or not invoice_global_discount_ids"
                    groups="!base_global_discount.group_global_discount"
                />
            </field>
            <field name="tax_totals" position="attributes">
                <attribute
                    name="class"
                    add="oe_subtotal_footer_separator"
                    separator=" "
                />
            </field>
            <page id="other_tab" position="inside">
                <separator string="Global Discounts" />
                <field
                    name="invoice_global_discount_ids"
                    nolabel="1"
                    readonly="1"
                    invisible="not global_discount_ids"
                    force_save="1"
                    groups="base_global_discount.group_global_discount"
                >
                    <list create="0" delete="0">
                        <field name="name" />
                        <field
                            name="base"
                            widget="monetary"
                            options="{'currency_field': 'currency_id'}"
                        />
                        <field name="discount_display" />
                        <field name="discount_amount" />
                        <field
                            name="base_discounted"
                            widget="monetary"
                            options="{'currency_field': 'currency_id'}"
                        />
                        <field name="account_id" />
                        <field name="tax_ids" widget="many2many_tags" />
                        <field
                            domain="[('company_id', '=', company_id)]"
                            name="account_analytic_id"
                            groups="analytic.group_analytic_accounting"
                        />
                    </list>
                </field>
                <field
                    name="invoice_global_discount_ids"
                    nolabel="1"
                    readonly="1"
                    invisible="not global_discount_ids_readonly"
                    force_save="1"
                    groups="!base_global_discount.group_global_discount"
                >
                    <list create="0" delete="0">
                        <field name="name" />
                        <field
                            name="base"
                            widget="monetary"
                            options="{'currency_field': 'currency_id'}"
                        />
                        <field name="discount_display" />
                        <field name="discount_amount" />
                        <field
                            name="base_discounted"
                            widget="monetary"
                            options="{'currency_field': 'currency_id'}"
                        />
                        <field name="account_id" />
                        <field name="tax_ids" widget="many2many_tags" />
                        <field
                            domain="[('company_id', '=', company_id)]"
                            name="account_analytic_id"
                            groups="analytic.group_analytic_accounting"
                        />
                    </list>
                </field>
            </page>
        </field>
    </record>
</odoo>
