<?xml version="1.0" encoding="UTF-8"?>
<odoo>

    <record id="quotation_document_form" model="ir.ui.view">
        <field name="name">quotation.document.form</field>
        <field name="model">quotation.document</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <h1>
                        <field name="name" readonly="not datas"/>
                    </h1>
                    <group>
                        <group>
                            <field name="document_type"/>
                            <label for="datas"/>
                            <div class="o_row">
                                <field
                                    name="datas"
                                    filename="name"
                                    options="{'accepted_file_extensions': '.pdf', 'allowed_mime_type' : 'application/pdf'}"
                                    class="oe_inline"
                                />
                                <button
                                    name="action_open_pdf_form_fields"
                                    type="object"
                                    string="Configure dynamic fields"
                                    help="Mark fields as safe to fill in the quote."
                                    class="btn btn-link"
                                    icon="fa-pencil"
                                    colspan="2"
                                    groups="base.group_system,base.group_no_one"
                                    invisible="not (datas and form_field_ids)"
                                />
                            </div>
                            <field
                                name="quotation_template_ids"
                                options="{'no_create': True}"
                                widget="many2many_tags"
                            />
                            <field name="add_by_default"/>
                        </group>
                    </group>
                    <group string="Attached To" groups="base.group_multi_company,base.group_no_one">
                        <field
                            name="company_id"
                            placeholder="Visible to all"
                            groups="base.group_multi_company"
                            options="{'no_create': True}"
                            class="oe_inline"
                        />
                        <field
                            name="form_field_ids"
                            groups="base.group_no_one"
                            widget="many2many_tags"
                        />
                    </group>
                    <group string="History" groups="base.group_no_one" invisible="not create_date">
                        <label for="create_uid" string="Creation"/>
                        <div name="creation_div">
                            <field name="create_uid" readonly="1" class="oe_inline"/> on
                            <field name="create_date" readonly="1" class="oe_inline"/>
                        </div>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record id="quotation_document_kanban" model="ir.ui.view">
        <field name="name">quotation.document.kanban</field>
        <field name="model">quotation.document</field>
        <field name="arch" type="xml">
            <kanban js_class="quotation_document_kanban">
                <field name="sequence" widget="handle"/>
                <field name="ir_attachment_id"/>
                <field name="mimetype"/>
                <field name="document_type"/>
                <field name="name"/>
                <field name="active"/>
                <templates>
                    <t t-name="menu">
                        <a t-if="widget.editable" type="open" class="dropdown-item">Edit</a>
                        <a t-if="widget.deletable" type="delete" class="dropdown-item">Delete</a>
                        <a
                            t-attf-href="/web/content/#{record.ir_attachment_id.raw_value}?download=true"
                            download=""
                            class="dropdown-item"
                        >Download</a>
                    </t>
                    <t t-name="card" class="o_kanban_attachment flex-row">
                        <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" invisible="active"/>
                        <aside>
                            <div class="o_image o_kanban_previewer w-100 h-100" t-att-data-mimetype="record.mimetype.value"/>
                        </aside>
                        <main class="ms-2">
                            <field name="name" class="fw-bolder text-truncate"/>
                            <div class="d-flex mt-2">
                                <span>Document type:</span>
                                <field name="document_type" class="ms-2" widget="selection"/>
                            </div>
                            <div
                                t-if="!context.hide_template_ids
                                      and !!record.quotation_template_ids.raw_value.length"
                                class="mt-2"
                            >
                                <span class="pe-2">Templates:</span>
                                <field name="quotation_template_ids" class="d-inline-block" widget="many2many_tags"/>
                            </div>
                        </main>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>

    <record id="quotation_document_list" model="ir.ui.view">
        <field name="name">quotation.document.list</field>
        <field name="model">quotation.document</field>
        <field name="arch" type="xml">
            <list editable="top" multi_edit="true">
                <field name="sequence" widget="handle"/>
                <field name="name"/>
                <field name="document_type"/>
                <field name="quotation_template_ids" widget="many2many_tags"/>
                <field name="add_by_default" widget="boolean_toggle" optional="show"/>
                <field name="company_id" groups="base.group_multi_company" optional="show"/>
            </list>
        </field>
    </record>

    <record id="quotation_document_search_view" model="ir.ui.view">
        <field name="name">quotation.document.search</field>
        <field name="model">quotation.document</field>
        <field name="arch" type="xml">
            <search string="Quotation Document">
                <field name="name"/>
                <separator/>
                <group>
                    <filter
                        string="Document type"
                        name="doc_type"
                        context="{'group_by': 'document_type'}"
                    />
                    <filter
                        string="Quotation Template"
                        name="quotation_template"
                        context="{'group_by': 'quotation_template_ids'}"
                    />
                    <filter name="all" string="All"/>
                    <filter name="archived" string="Archived" domain="[('active', '=', False)]"/>
                    <filter name="add_by_default" string="Add By Default" domain="[('add_by_default', '=', True)]"/>
                </group>
            </search>
        </field>
    </record>

    <record id="quotation_document_action" model="ir.actions.act_window">
        <field name="name">Headers/Footers</field>
        <field name="res_model">quotation.document</field>
        <field name="view_mode">kanban,list,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Upload quotation headers and footers
            </p>
            <p>
                Personalize your quotes with catchy header and footer pages
                <br/>
                to boost your sales.
            </p>
        </field>
    </record>

</odoo>
