<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright 2015-2020 Akretion France (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">account_usability.account.move.form</field>
    <field name="model">account.move</field>
    <field name="inherit_id" ref="account.view_move_form"/>
    <field name="arch" type="xml">
        <field name="fiscal_position_id" position="attributes">
            <attribute name="widget">selection</attribute>
        </field>
        <field name="invoice_incoterm_id" position="attributes">
            <attribute name="widget">selection</attribute>
        </field>
        <button name="action_register_payment" position="attributes">
            <attribute name="class">btn-default</attribute>
        </button>
        <button name="action_register_payment" position="before">
            <button name="%(account.account_invoices)d" type="action" string="Print" attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'out_refund'))]}"/>
        </button>
        <button name="preview_invoice" position="attributes">
            <attribute name="attrs">{'invisible': 1}</attribute>
        </button>
        <!-- move sent field and make it visible -->
        <field name="is_move_sent" position="replace"/>
        <field name="invoice_origin" position="attributes">
            <attribute name="invisible">0</attribute>
        </field>
        <field name="invoice_origin" position="after">
            <field name="is_move_sent" attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'out_refund'))]}"/>
        </field>
        <xpath expr="//field[@name='line_ids']/tree/field[@name='analytic_account_id']" position="attributes">
            <attribute name="optional">show</attribute>
        </xpath>
        <xpath expr="//field[@name='line_ids']/tree/field[@name='currency_id']" position="attributes">
            <attribute name="optional">show</attribute>
        </xpath>
        <xpath expr="//field[@name='line_ids']/tree/field[@name='tax_tag_ids']" position="after">
            <field name="matching_number" optional="show"/>
        </xpath>
        <xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='product_id']" position="after">
            <field name="product_barcode" optional="hide"/>
        </xpath>
        <field name="auto_post" position="before">
            <field name="blocked"/>
        </field>
        <div role="alert" position="after">
            <div id="warn_blocked" groups="account.group_account_invoice,account.group_account_readonly"
                    class="alert alert-warning" role="alert" style="margin-bottom:0px;"
                    attrs="{'invisible': ['|', ('move_type', 'not in', ('in_invoice', 'in_refund', 'out_invoice', 'out_refund')), ('blocked', '=', False)]}">
                    This <field name="move_type"/> is marked as <b>disputed</b>.
            </div>
        </div>
    </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="attributes">
            <attribute name="optional">show</attribute>
        </field>
        <field name="amount_untaxed_signed" position="before">
            <!-- No sum="1" on the invoice currency fields, because it doesn't make sense
                to add amounts in different currencies -->
            <field name="amount_untaxed_invoice_currency_signed" string="Tax Excluded Inv. Cur." optional="hide"/>
            <field name="amount_tax_invoice_currency_signed" string="Tax Inv. Cur." optional="hide"/>
            <field name="amount_total_invoice_currency_signed" string="Total Inv. Cur." optional="hide"/>
            <field name="amount_residual_invoice_currency_signed" string="Amount Due Inv. Cur." optional="hide"/>
        </field>
    </field>
</record>

<record id="view_account_invoice_filter" model="ir.ui.view">
    <field name="name">account_usability.account.move.search</field>
    <field name="model">account.move</field>
    <field name="inherit_id" ref="account.view_account_invoice_filter"/>
    <field name="arch" type="xml">
        <filter name="due_date" position="after">
            <separator/>
             <filter name="to_send" string="To Send" domain="[('is_move_sent', '=', False), ('state', '=', 'posted'), ('move_type', 'in', ('out_invoice', 'out_refund'))]"/>
             <filter name="sent" string="Sent" domain="[('is_move_sent', '=', True), ('move_type', 'in', ('out_invoice', 'out_refund'))]"/>
            <separator/>
            <filter name="no_attachment" string="Missing Attachment" domain="[('has_attachment', '=', False)]"/>
            <separator/>
            <filter name="dispute" string="Dispute" domain="[('blocked', '=', True)]"/>
        </filter>
        <filter name="salesperson" position="before">
            <filter name="commercial_partner_groupby" string="Commercial Partner" context="{'group_by': 'commercial_partner_id'}"/>
        </filter>
        <filter name="status" position="after">
            <filter name="payment_state_groupby" string="Payment Status" context="{'group_by': 'payment_state'}"/>
        </filter>
    </field>
</record>

<record id="view_account_move_filter" model="ir.ui.view">
    <field name="model">account.move</field>
    <field name="inherit_id" ref="account.view_account_move_filter"/>
    <field name="arch" type="xml">
        <field name="journal_id" position="after">
            <field name="search_account_id"/>
        </field>
    </field>
</record>

<record id="view_move_line_form" model="ir.ui.view">
    <field name="model">account.move.line</field>
    <field name="inherit_id" ref="account.view_move_line_form"/>
    <field name="arch" type="xml">
        <!-- The field 'blocked' is alone in it's block
        We don't want to display an empty block, so we put the attrs on the group
        The drawback of this is that, if someone added a field in that group,
        he won't see the field when internal_type is not payable/receivable -->
        <xpath expr="//field[@name='blocked']/.." position="attributes">
            <attribute name="attrs">{'invisible': [('account_internal_type', 'not in', ('payable', 'receivable'))]}</attribute>
        </xpath>
        <field name="company_id" position="after">
            <field name="account_internal_type" invisible="1"/>
        </field>
    </field>
</record>

<record id="view_move_line_tree" model="ir.ui.view">
    <field name="model">account.move.line</field>
    <field name="inherit_id" ref="account.view_move_line_tree"/>
    <field name="arch" type="xml">
        <field name="matching_number" position="after">
            <button title="View Journal Entry Form" type="object" name="show_account_move_form" icon="fa-arrow-right"/>
        </field>
        <field name="credit" position="after">
            <field name="balance" sum="Balance" optional="show"/>
        </field>
    </field>
</record>

<record id="view_account_move_line_filter" model="ir.ui.view">
    <field name="name">account_usability.account_move_line_search</field>
    <field name="model">account.move.line</field>
    <field name="inherit_id" ref="account.view_account_move_line_filter"/>
    <field name="arch" type="xml">
        <filter name="unposted" position="before">
            <filter name="current_year" string="Current Year" domain="[('date', '&gt;=', (context_today().strftime('%Y-01-01'))), ('date', '&lt;=', (context_today().strftime('%Y-12-31')))]"/>
            <filter name="previous_year" string="Previous Year" domain="[('date', '&gt;=', (context_today() + relativedelta(day=1, month=1, years=-1)).strftime('%Y-%m-%d')), ('date', '&lt;=', (context_today() + relativedelta(day=31, month=12, years=-1)).strftime('%Y-%m-%d'))]"/>
            <separator/>
        </filter>
        <field name="partner_id" position="after">
            <field name="matching_number" />
            <field name="debit" filter_domain="['|', ('debit', '=', self), ('credit', '=', self)]" string="Debit or Credit"/>
        </field>
        <filter name="unreconciled" position="before">
            <filter name="reconciled" string="Fully Reconciled" domain="[('account_id.reconcile', '=', True), ('full_reconcile_id', '!=', False)]"/>
        </filter>
        <filter name="unreconciled" position="attributes">
            <attribute name="string">Unreconciled or Partially Reconciled</attribute>
        </filter>
        <field name="name" position="attributes">
            <attribute name="string">Label, Reference, Account or Partner</attribute>
        </field>
        <field name="name" position="before">
            <field name="move_id" position="move"/>
        </field>
        <field name="partner_id" position="attributes">
            <attribute name="domain">['|', ('parent_id', '=', False), ('is_company', '=', True)]</attribute>
        </field>
    </field>
</record>

<record id="view_move_line_pivot" model="ir.ui.view">
    <field name="model">account.move.line</field>
    <field name="inherit_id" ref="account.view_move_line_pivot"/>
    <field name="arch" type="xml">
        <!-- By default, date is split by month... but if you've been using Odoo for several years,
            the pivot table becomes very big by default: so we split by year -->
        <field name="date" position="attributes">
            <attribute name="interval">year</attribute>
        </field>
    </field>
</record>

<record id="account.action_move_journal_line" model="ir.actions.act_window">
    <field name="context">{'default_move_type': 'entry', 'view_no_maturity': True}</field>
    <!-- Remove 'search_default_misc_filter': 1 -->
</record>

</odoo>
