<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright 2015-2024 Akretion (http://www.akretion.com/)
  @author: Alexis de Lattre <alexis.delattre@akretion.com>
  License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->

<odoo>

<record id="view_move_form" model="ir.ui.view">
    <field name="name">margin.account.move.form</field>
    <field name="model">account.move</field>
    <field name="inherit_id" ref="account.view_move_form"/>
    <field name="arch" type="xml">
        <group name="sale_info_group" position="inside">
            <field name="margin_invoice_currency"
                groups="base.group_no_one"
                attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'out_refund'))]}"/>
            <field name="margin_company_currency"
                groups="base.group_no_one"
                attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'out_refund'))]}"/>
        </group>
        <xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='price_total']" position="after">
            <field name="standard_price_invoice_currency" optional="hide" attrs="{'column_invisible': [('parent.move_type', 'not in', ('out_invoice', 'out_refund'))]}"/>
            <field name="margin_invoice_currency" optional="hide" attrs="{'column_invisible': [('parent.move_type', 'not in', ('out_invoice', 'out_refund'))]}"/>
            <field name="margin_rate" optional="hide" string="Margin Rate (%)" attrs="{'column_invisible': [('parent.move_type', 'not in', ('out_invoice', 'out_refund'))]}"/>
        </xpath>
        <xpath expr="//field[@name='invoice_line_ids']/form//field[@name='price_total']/.." position="inside">
            <field name="standard_price_company_currency"
                groups="base.group_no_one" attrs="{'invisible': [('parent.move_type', 'not in', ('out_invoice', 'out_refund'))]}"/>
            <field name="standard_price_invoice_currency"
                groups="base.group_no_one" attrs="{'invisible': [('parent.move_type', 'not in', ('out_invoice', 'out_refund'))]}"/>
            <field name="margin_invoice_currency"
                groups="base.group_no_one" attrs="{'invisible': [('parent.move_type', 'not in', ('out_invoice', 'out_refund'))]}"/>
            <field name="margin_company_currency"
                groups="base.group_no_one" attrs="{'invisible': [('parent.move_type', 'not in', ('out_invoice', 'out_refund'))]}"/>
            <label for="margin_rate" groups="base.group_no_one" attrs="{'invisible': [('parent.move_type', 'not in', ('out_invoice', 'out_refund'))]}"/>
            <div name="margin_rate" groups="base.group_no_one" attrs="{'invisible': [('parent.move_type', 'not in', ('out_invoice', 'out_refund'))]}">
                <field name="margin_rate" class="oe_inline"/> %
            </div>
        </xpath>
    </field>
</record>

<record id="view_invoice_tree" model="ir.ui.view">
    <field name="model">account.move</field>
    <field name="inherit_id" ref="account.view_invoice_tree"/>
    <field name="arch" type="xml">
        <field name="amount_residual_signed" position="after">
            <field name="margin_company_currency" optional="hide" sum="1" invisible="context.get('default_move_type') not in ('out_invoice', 'out_refund')" string="Margin"/>
        </field>
    </field>
</record>

</odoo>
