<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2021 Sygel - Valentin Vinagre
     License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
    <record id="crm_salesperson_planner_visit_sale_form_view" model="ir.ui.view">
        <field name="name">Crm Salesperson Planner Visit Sale Form View</field>
        <field name="model">crm.salesperson.planner.visit</field>
        <field
            name="inherit_id"
            ref="crm_salesperson_planner.crm_salesperson_planner_visit_form_view"
        />
        <field name="arch" type="xml">
            <header position="inside">
                <button
                    string="New Quotation"
                    name="action_sale_quotation_new"
                    type="object"
                    class="oe_highlight"
                    attrs="{'invisible': [('state', 'not in', ('confirm', 'done'))]}"
                />
            </header>
            <xpath expr="//div[@name='button_box']" position="inside">
                <button
                    class="oe_stat_button"
                    type="object"
                    name="action_view_sale_quotation"
                    icon="fa-pencil-square-o"
                    attrs="{'invisible': [('state', '=', 'draft')]}"
                >
                    <field
                        name="quotation_count"
                        widget="statinfo"
                        string="Quotations"
                    />
                </button>
                <button
                    class="oe_stat_button"
                    type="object"
                    attrs="{'invisible': ['|',('sale_order_count', '=', 0), ('state', '=', 'draft')]}"
                    name="action_view_sale_order"
                    icon="fa-usd"
                >
                    <field name="sale_order_count" widget="statinfo" string="Orders" />
                </button>
            </xpath>
        </field>
    </record>
    <record
        id="crm_salesperson_visit_action_quotation_new"
        model="ir.actions.act_window"
    >
        <field name="name">Quotation</field>
        <field name="res_model">sale.order</field>
        <field name="view_mode">form,tree,graph</field>
        <field name="domain">[('visit_id', '=', active_id)]</field>
        <field
            name="context"
        >{'search_default_visit_id': active_id, 'default_visit_id': active_id}</field>
    </record>
</odoo>
