<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="view_account_spread" model="ir.ui.view">
        <field name="model">account.spread</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <button
                        name="compute_spread_board"
                        type="object"
                        string="Recalculate unposted lines"
                        class="oe_highlight"
                        invisible="not debit_account_id or not display_recompute_buttons"
                    />
                    <button
                        name="action_recalculate_spread"
                        type="object"
                        string="Recalculate entire spread"
                        invisible="not debit_account_id or not display_recompute_buttons"
                        groups="account.group_account_manager"
                    />
                    <button
                        name="action_undo_spread"
                        type="object"
                        string="Undo spread"
                        invisible="not line_ids"
                        groups="account.group_account_manager"
                    />
                    <button
                        name="action_unlink_invoice_line"
                        type="object"
                        string="Unlink Invoice Line"
                        invisible="not invoice_line_id"
                        groups="account.group_account_manager"
                    />
                </header>
                <sheet>
                    <div name="button_box" class="oe_button_box">
                        <button
                            name="open_posted_view"
                            class="oe_stat_button"
                            icon="fa-bars"
                            type="object"
                            string="Posted entries"
                        >
                        </button>
                    </div>
                    <widget
                        name="web_ribbon"
                        title="Archived"
                        bg_color="bg-danger"
                        invisible="active"
                    />
                    <div class="oe_title">
                        <label for="name" string="Spread Board Name" />
                        <h1>
                            <field
                                name="name"
                                placeholder="e.g. One year offices cleaning contract"
                            />
                        </h1>
                    </div>
                    <group name="header_info">
                        <group name="spread_definitions">
                            <field name="template_id" />
                            <field name="invoice_type" readonly="invoice_line_id" />
                            <field name="display_recompute_buttons" invisible="1" />
                            <field name="display_move_line_auto_post" invisible="1" />
                            <field name="all_posted" invisible="1" />
                            <field name="active" invisible="1" />
                            <field name="use_invoice_line_account" invisible="1" />
                        </group>
                    </group>
                    <group name="accounts">
                        <group name="debits">
                            <field name="is_debit_account_deprecated" invisible="1" />
                            <label
                                for="debit_account_id"
                                colspan="3"
                                string="Balance sheet account / Spread account"
                                invisible="invoice_type not in ['out_invoice','in_refund']"
                            />
                            <label
                                for="debit_account_id"
                                colspan="3"
                                string="Expense account"
                                invisible="invoice_type not in ['in_invoice','out_refund']"
                            />
                            <div invisible="use_invoice_line_account" colspan="3">
                                <span
                                    class="help-block"
                                    colspan="2"
                                    invisible="invoice_type not in ['out_invoice','in_refund']"
                                >
                                      The Balance Sheet account used for the spreading.<br
                                    />This account is the counterpart of the account in the invoice line.
                                </span>
                                <span
                                    class="help-block"
                                    colspan="2"
                                    invisible="invoice_type not in ['in_invoice','out_refund']"
                                >
                                      The Expense account in the vendor bill line.<br
                                    />Usually the same account of the vendor bill line.
                                </span>
                            </div>
                            <div invisible="not use_invoice_line_account" colspan="3">
                                <span
                                    class="help-block"
                                    colspan="2"
                                    invisible="invoice_type not in ['out_invoice','in_refund']"
                                >
                                      The Balance Sheet account.<br
                                    />This is the account in the invoice line.
                                </span>
                                <span
                                    class="help-block"
                                    colspan="2"
                                    invisible="invoice_type not in ['in_invoice','out_refund']"
                                >
                                      The Expense account used for the spreading.<br
                                    />This account is the counterpart of the account of the vendor bill line.
                                </span>
                            </div>
                            <field
                                name="debit_account_id"
                                required="1"
                                domain="[('deprecated', '=', False), ('account_type', 'not in', ('asset_cash','liability_credit_card')), ('internal_group', '!=', 'off_balance')]"
                                readonly="invoice_line_id"
                            />
                            <span
                                class="help-block text-danger"
                                colspan="2"
                                invisible="not is_debit_account_deprecated"
                            >
                                  This account in deprecated! The reconciliation will be NOT possible.
                            </span>
                        </group>
                        <group name="credits">
                            <field name="is_credit_account_deprecated" invisible="1" />
                            <label
                                for="credit_account_id"
                                colspan="3"
                                string="Revenue account"
                                invisible="invoice_type not in ['out_invoice','in_refund']"
                            />
                            <label
                                for="credit_account_id"
                                colspan="3"
                                string="Balance sheet account / Spread account"
                                invisible="invoice_type not in ['in_invoice','out_refund']"
                            />
                            <div invisible="use_invoice_line_account" colspan="3">
                                <span
                                    class="help-block"
                                    colspan="2"
                                    invisible="invoice_type not in ['out_invoice','in_refund']"
                                >
                                      The Revenue account in the invoice line.<br
                                    />Usually the same account of the invoice line.
                                </span>
                                <span
                                    class="help-block"
                                    colspan="2"
                                    invisible="invoice_type not in ['in_invoice','out_refund']"
                                >
                                      The Balance Sheet account used for the spreading.<br
                                    />This account is the counterpart of the account in the vendor bill line.
                                </span>
                            </div>
                            <div invisible="not use_invoice_line_account" colspan="3">
                                <span
                                    class="help-block"
                                    colspan="2"
                                    invisible="invoice_type not in ['out_invoice','in_refund']"
                                >
                                      The Revenue account used for the spreading.<br
                                    />This account is the counterpart of the account of the invoice line.
                                </span>
                                <span
                                    class="help-block"
                                    colspan="2"
                                    invisible="invoice_type not in ['in_invoice','out_refund']"
                                >
                                      The Balance Sheet account.<br
                                    />This is the account in the vendor bill line.
                                </span>
                            </div>
                            <field
                                name="credit_account_id"
                                required="1"
                                domain="[('deprecated', '=', False), ('account_type', 'not in', ('asset_cash','liability_credit_card')), ('internal_group', '!=', 'off_balance')]"
                                readonly="invoice_line_id"
                            />
                            <span
                                class="help-block text-danger"
                                colspan="2"
                                invisible="not is_credit_account_deprecated"
                            >
                                  This account in deprecated! The reconciliation will be NOT possible.
                            </span>
                        </group>
                    </group>
                    <group name="main_info">
                        <group>
                            <field
                                name="invoice_id"
                                invisible="not invoice_id"
                                readonly="1"
                            />
                            <field
                                name="invoice_line_id"
                                readonly="1"
                                invisible="not invoice_line_id"
                            />
                            <field
                                name="estimated_amount"
                                readonly="invoice_line_id"
                                invisible="estimated_amount == 0.0 and invoice_line_id"
                            />
                            <field
                                name="total_amount"
                                invisible="not invoice_line_id"
                            />
                            <field
                                name="move_line_auto_post"
                                invisible="not display_move_line_auto_post"
                            />
                        </group>
                        <group>
                            <field name="period_number" />
                            <field name="period_type" />
                            <field name="spread_date" />
                            <field name="days_calc" />
                            <field name="suitable_journal_ids" invisible="1" />
                            <field
                                name="journal_id"
                                widget="selection"
                                groups="base.group_multi_company"
                            />
                        </group>
                    </group>
                    <notebook name="notebook">
                        <page name="spread_lines" string="Spread lines">
                            <field name="line_ids" readonly="1">
                                <list>
                                    <field name="name" readonly="1" />
                                    <field
                                        name="amount"
                                        readonly="move_id"
                                        sum="Total"
                                    />
                                    <field name="date" readonly="1" />
                                    <field name="move_id" readonly="1" />
                                    <button
                                        name="create_move"
                                        icon="fa-play"
                                        string="Create Move"
                                        type="object"
                                        groups="account.group_account_manager"
                                        invisible="move_id"
                                    />
                                    <button
                                        name="open_move"
                                        icon="fa-plus-square-o"
                                        string="View Move"
                                        type="object"
                                        invisible="not move_id"
                                    />
                                    <button
                                        name="unlink_move"
                                        icon="fa-times"
                                        string="Delete Move"
                                        type="object"
                                        confirm="This will delete the move. Are you sure ?"
                                        groups="account.group_account_manager"
                                        invisible="not move_id"
                                    />
                                </list>
                            </field>
                            <group name="extension">
                                <group name="extension_left">
                                </group>
                                <group name="extension_right">
                                    <field
                                        name="display_create_all_moves"
                                        invisible="1"
                                    />
                                    <button
                                        name="create_all_moves"
                                        string="Create All Moves"
                                        type="object"
                                        icon="fa-play"
                                        colspan="2"
                                        invisible="not display_create_all_moves"
                                    />
                                    <field
                                        name="unspread_amount"
                                        invisible="unspread_amount == 0"
                                    />
                                    <field
                                        name="unposted_amount"
                                        invisible="unposted_amount == 0"
                                    />
                                    <field
                                        name="posted_amount"
                                        invisible="posted_amount == 0"
                                    />
                                </group>
                            </group>
                        </page>
                        <page name="details" string="Details">
                            <group name="extra_details">
                                <group>
                                    <field
                                        name="company_id"
                                        groups="base.group_multi_company"
                                        options="{'no_create': True}"
                                    />
                                    <field
                                        name="currency_id"
                                        groups="base.group_multi_currency"
                                    />
                                </group>
                                <group>
                                    <field
                                        name="analytic_distribution"
                                        groups="analytic.group_analytic_accounting"
                                        widget="analytic_distribution"
                                    />
                                </group>
                            </group>
                        </page>
                    </notebook>
                </sheet>
                <chatter/>
            </form>
        </field>
    </record>

    <record id="view_account_spread_tree" model="ir.ui.view">
        <field name="model">account.spread</field>
        <field name="arch" type="xml">
            <list>
                <field name="name" />
                <field name="company_id" groups="base.group_multi_company" />
            </list>
        </field>
    </record>

    <record id="view_account_spread_search" model="ir.ui.view">
        <field name="model">account.spread</field>
        <field name="arch" type="xml">
            <search>
                <field name="name" string="Spread" />
                <filter
                    string="Archived"
                    name="inactive"
                    domain="[('active','=',False)]"
                />
            </search>
        </field>
    </record>

    <record id="action_account_spread_form" model="ir.actions.act_window">
        <field name="name">Spread Costs/Revenues</field>
        <field name="res_model">account.spread</field>
        <field name="view_mode">list,form</field>
        <field name="view_id" ref="view_account_spread_tree" />
    </record>
    <menuitem
        id="menu_action_account_spread_form"
        parent="account.menu_finance_entries"
        action="action_account_spread_form"
        groups="account.group_account_user,account.group_account_manager"
    />
</odoo>
