<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="sale_order_template_view_search" model="ir.ui.view">
        <field name="name">sale.order.template.search</field>
        <field name="model">sale.order.template</field>
        <field name="arch" type="xml">
            <search string="Search Quotation Template">
                <field name="name"/>
                <filter string="Archived" name="inactive" domain="[('active','=', False)]"/>
                <group>
                    <filter string="Company" name="company_id" context="{'group_by': 'company_id'}" groups="base.group_multi_company"/>
                </group>
            </search>
        </field>
    </record>

    <record id="sale_order_template_view_form" model="ir.ui.view">
        <field name="name">sale.order.template.form</field>
        <field name="model">sale.order.template</field>
        <field name="arch" type="xml">
            <form string="Quotation Template">
                <sheet>
                    <div name="button_box" class="oe_button_box"/>
                    <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" invisible="active"/>
                    <div class="oe_title" name="sale_order_template_title">
                        <label for="name" id="sale_order_template_title"/>
                        <h1>
                            <field name="name" placeholder="e.g. Standard Consultancy Package" class="d-block"/>
                        </h1>
                    </div>
                    <group>
                        <group name="sale_info">
                            <field name="active" invisible="1"/>
                            <label for="number_of_days" string="Quotation Validity"/>
                            <div id="number_of_days">
                                <field name="number_of_days" style="width: 3rem;"/>
                                <div class="d-inline-block">days</div>
                            </div>
                            <field name="mail_template_id" context="{'default_model': 'sale.order'}"/>
                            <field name="company_id" options="{'no_create': True}" groups="base.group_multi_company" placeholder="Visible to all"/>
                            <field name="journal_id"/>
                        </group>
                        <group name="so_confirmation">
                            <field name="require_signature"/>
                            <label for="require_payment"/>
                            <div id="require_payment" class="o_row">
                                <field name="require_payment" class="oe_inline"/>
                                <span invisible="not require_payment">of</span>
                                <field name="prepayment_percent"
                                       invisible="not require_payment"
                                       widget="percentage"
                                       class="oe_inline"/>
                            </div>
                        </group>
                    </group>
                    <notebook name="main_book">
                        <page string="Lines" name="order_lines">
                        <field
                            name="sale_order_template_line_ids"
                            widget="so_template_line_o2m"
                            options="{ 'subsections': True }"
                        >
                            <form string="Quotation Template Lines">
                                <!--
                                    We need the sequence field to be here for new lines to be added at the correct position.
                                    TODO: at some point we want to fix this in the framework so that an invisible field is not required.
                                -->
                                <field name="sequence" invisible="1"/>
                                <field name="display_type" invisible="1"/>
                                <group invisible="display_type">
                                    <group>
                                        <field name="product_id" required="not display_type"/>
                                        <label for="product_uom_qty"/>
                                        <div>
                                            <field name="product_uom_qty" class="oe_inline"/>
                                        </div>
                                    </group>
                                </group>
                                <notebook colspan="4" name="description">
                                    <page string="Description" name="order_description" invisible="display_type">
                                        <field name="name" />
                                    </page>
                                    <page string="Section" name="order_section" invisible="display_type != 'line_section'">
                                        <field name="name" />
                                    </page>
                                    <page string="Note" name="order_note" invisible="display_type != 'line_note'">
                                        <field name="name" />
                                    </page>
                                </notebook>
                            </form>
                            <list string="Quotation Template Lines" editable="bottom">
                                <control>
                                    <create name="add_product_control" string="Add a product"/>
                                    <create name="add_section_control" string="Add a section" context="{'default_display_type': 'line_section'}"/>
                                    <create name="add_note_control" string="Add a note" context="{'default_display_type': 'line_note'}"/>
                                </control>
                                <field name="display_type" column_invisible="True"/>
                                <field name="is_optional" column_invisible="True"/>
                                <field name="sequence" widget="handle"/>
                                <field name="product_id"/>
                                <field name="name" widget="section_and_note_text"/>
                                <field name="product_uom_qty"/>
                                <field
                                    name="product_uom_id"
                                    groups="uom.group_uom"
                                    required="not display_type"/>
                            </list>
                        </field>
                    </page>
                        <page string="Terms &amp; Conditions" name="terms_and_conditions">
                            <field
                                name="note"
                                nolabel="1"
                                placeholder="The Administrator can set default Terms &amp; Conditions in Sales Settings. Terms set here will show up instead if you select this quotation template."/>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <record id="sale_order_template_view_tree" model="ir.ui.view">
        <field name="name">sale.order.template.list</field>
        <field name="model">sale.order.template</field>
        <field name="arch" type="xml">
            <list string="Quotation Template">
                <field name="sequence" widget="handle"/>
                <field name="name"/>
                <field name="company_id" groups="base.group_multi_company"/>
            </list>
        </field>
    </record>

    <record id="sale_order_template_action" model="ir.actions.act_window">
        <field name="name">Quotation Templates</field>
        <field name="res_model">sale.order.template</field>
        <field name="view_mode">list,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create your quotation template
            </p><p>
                Use templates to create polished, professional quotes in minutes.
                Send these quotes by email and let your customers sign online.
                Use cross-selling and discounts to push and boost your sales.
            </p>
        </field>
    </record>

</odoo>
