<?xml version="1.0" ?>
<odoo>
    <record id="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_date']" position="after">
                <field
                    name="folio_ids"
                    widget="many2many_tags"
                    readonly="1"
                    attrs="{'invisible':[('move_type','not in',('out_invoice','out_refund','out_receipt'))]}"
                />
                <field
                    name="pms_property_id"
                    domain="[('company_id','=',company_id)]"
                />
            </xpath>
            <xpath expr="//field[@name='invoice_user_id']" position="before">
                <field name="origin_agency_id" />
            </xpath>
            <xpath
                expr="//field[@name='invoice_line_ids']/tree/field[@name='quantity']"
                position="before"
            >
                <field name="name_changed_by_user" invisible="0" />
                <field
                    name="pms_property_id"
                    attrs="{'column_invisible':[('parent.pms_property_id','!=',False)]}"
                />
            </xpath>
            <xpath
                expr="//notebook//field[@name='line_ids']/tree/field[@name='date_maturity']"
                position="after"
            >
                <field name="name_changed_by_user" invisible="1" />
                <field
                    name="pms_property_id"
                    attrs="{'column_invisible':[('parent.pms_property_id','!=',False)]}"
                    optional="hide"
                />
            </xpath>
        </field>
    </record>

    <record id="view_move_tree" model="ir.ui.view">
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_move_tree" />
        <field name="arch" type="xml">
            <xpath expr="//field[@name='company_id']" position="after">
                <field name="pms_property_id" optional="show" />
                <field name="origin_agency_id" optional="show" />
            </xpath>
        </field>
    </record>

    <record id="view_account_invoice_filter" model="ir.ui.view">
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_account_invoice_filter" />
        <field name="arch" type="xml">
            <xpath expr="//field[@name='invoice_user_id']" position="after">
                <field name="pms_property_id" />
            </xpath>
            <xpath expr="//filter[@name='status']" position="after">
                <filter
                    name="pms_property_id"
                    string="Property"
                    context="{'group_by':'pms_property_id'}"
                />
                <filter
                    name="origin_agency_id"
                    string="Originating agency"
                    context="{'group_by':'origin_agency_id'}"
                />
            </xpath>
        </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">
            <xpath expr="//field[@name='journal_id']" position="after">
                <field name="pms_property_id" />
            </xpath>
            <xpath expr="//filter[@name='by_company']" position="after">
                <filter
                    name="by_property"
                    string="Property"
                    context="{'group_by':'pms_property_id'}"
                />
                <filter
                    name="by_origin_agency"
                    string="Originating agency"
                    context="{'group_by':'origin_agency_id'}"
                />
            </xpath>
        </field>
    </record>

    <record id="action_pms_move_out_invoice_type" model="ir.actions.act_window">
        <field name="name">PMS Invoices</field>
        <field name="res_model">account.move</field>
        <field name="view_mode">tree,kanban,form</field>
        <field name="view_id" ref="account.view_out_invoice_tree" />
        <field name="search_view_id" ref="view_account_invoice_filter" />
        <field name="domain">[('move_type', 'in', ('out_invoice','out_refund'))]</field>
        <field name="context">{'default_move_type': 'out_invoice'}</field>
        <field name="help" type="html">
          <p class="o_view_nocontent_smiling_face">
            Create a customer invoice
          </p><p>
            Create invoices, register payments and keep track of the discussions with your customers.
          </p>
        </field>
    </record>

    <menuitem
        name="Invoices"
        id="pms_invoice_menu"
        action="pms.action_pms_move_out_invoice_type"
        sequence="15"
        parent="pms.pms_sales_menu"
    />
</odoo>
