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

      <!-- Product menu-->"/>

        <record model="ir.ui.view" id="purchase_return_order_pivot">
            <field name="name">purchase.return.order.pivot</field>
            <field name="model">purchase.return.order</field>
            <field name="arch" type="xml">
                <pivot
                string="Purchase Return Order"
                display_quantity="True"
                sample="1"
            >
                    <field name="partner_id" type="row" />
                    <field name="amount_total" type="measure" />
                </pivot>
            </field>
        </record>
        <record model="ir.ui.view" id="purchase_return_order_graph">
            <field name="name">purchase.return.order.graph</field>
            <field name="model">purchase.return.order</field>
            <field name="arch" type="xml">
                <graph string="Purchase Return Order" sample="1">
                    <field name="partner_id" />
                    <field name="amount_total" type="measure" />
                </graph>
            </field>
        </record>

        <record id="purchase_return_order_form" model="ir.ui.view">
            <field name="name">purchase.return.order.form</field>
            <field name="model">purchase.return.order</field>
            <field name="arch" type="xml">
                <form string="Purchase Return Order" class="o_purchase_order">
                <header>
                    <button
                        name="action_draft_send"
                        states="draft"
                        string="Send by Email"
                        type="object"
                        context="{'send_draft':True}"
                        class="oe_highlight"
                    />
                    <button
                        name="print_return"
                        string="Print Return"
                        type="object"
                        states="draft"
                        class="oe_highlight"
                        groups="base.group_user"
                    />
                    <button
                        name="button_confirm"
                        type="object"
                        states="sent"
                        string="Confirm Return Order"
                        class="oe_highlight"
                        id="bid_confirm"
                    />
                    <button
                        name="button_approve"
                        type="object"
                        states='to approve'
                        string="Approve Order"
                        class="oe_highlight"
                        groups="purchase.group_purchase_manager"
                    />
                    <button
                        name="action_create_refund"
                        string="Create Refund"
                        type="object"
                        class="oe_highlight"
                        context="{'create_refund':True}"
                        attrs="{'invisible': ['|', ('state', 'not in', ('purchase', 'done')), ('invoice_status', 'in', ('no', 'invoiced'))]}"
                    />
                    <button
                        name="action_draft_send"
                        states="sent"
                        string="Re-Send by Email"
                        type="object"
                        context="{'send_draft':True}"
                    />
                    <button
                        name="print_return"
                        string="Print Return"
                        type="object"
                        states="sent"
                        groups="base.group_user"
                    />
                    <button
                        name="button_confirm"
                        type="object"
                        states="draft"
                        string="Confirm Return Order"
                        id="draft_confirm"
                    />
                    <button
                        name="action_draft_send"
                        states="purchase"
                        string="Send Return PO by Email"
                        type="object"
                        context="{'send_draft':False}"
                    />
                    <button
                        name="button_draft"
                        states="cancel"
                        string="Set to Draft"
                        type="object"
                    />
                    <button
                        name="button_cancel"
                        states="draft,to approve,sent,purchase"
                        string="Cancel"
                        type="object"
                    />
                    <button
                        name="button_done"
                        type="object"
                        string="Lock"
                        states="purchase"
                    />
                    <button
                        name="button_unlock"
                        type="object"
                        string="Unlock"
                        states="done"
                        groups="purchase.group_purchase_manager"
                    />
                    <field
                        name="state"
                        widget="statusbar"
                        statusbar_visible="draft,sent,purchase"
                        readonly="1"
                    />
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button
                            type="object"
                            name="action_view_invoice"
                            class="oe_stat_button"
                            icon="fa-pencil-square-o"
                            attrs="{'invisible':['|', ('invoice_count', '=', 0), ('state', 'in', ('draft','sent','to approve'))]}"
                        >
                            <field
                                name="invoice_count"
                                widget="statinfo"
                                string="Vendor Refunds"
                            />
                            <field name='invoice_ids' invisible="1" />
                        </button>
                    </div>
                    <div class="oe_title">
                        <span
                            class="o_form_label"
                            attrs="{'invisible': [('state','not in',('draft','sent'))]}"
                        >Draft </span>
                        <span
                            class="o_form_label"
                            attrs="{'invisible': [('state','in',('draft','sent'))]}"
                        >Purchase Return Order </span>
                        <h1>
                            <field name="name" readonly="1" />
                        </h1>
                    </div>
                    <group>
                        <group>
                            <field
                                name="partner_id"
                                widget="res_partner_many2one"
                                context="{'res_partner_search_mode': 'supplier', 'show_vat': True}"
                                placeholder="Name, TIN, Email, or Reference"
                            />
                            <field name="partner_ref" />
                            <field
                                name="currency_id"
                                groups="base.group_multi_currency"
                                force_save="1"
                            />
                            <field name="id" invisible="1" />
                        </group>
                        <group>
                            <field
                                name="date_order"
                                attrs="{'invisible': [('state','=','purchase')]}"
                            />
                            <label
                                for="date_approve"
                                attrs="{'invisible': [('state','!=','purchase')]}"
                            />
                            <div
                                name="date_approve"
                                attrs="{'invisible': [('state','!=','purchase')]}"
                                class="o_row"
                            >
                                <field name="date_approve" />
                            </div>
                            <label for="date_planned" />
                            <div name="date_planned_div" class="o_row">
                                <field
                                    name="date_planned"
                                    attrs="{'readonly': [('state', 'not in', ('draft', 'sent', 'to approve', 'purchase'))]}"
                                />
                            </div>
                            <field
                                name="origin"
                                attrs="{'invisible': [('origin','=',False)]}"
                            />
                        </group>
                    </group>
                    <notebook>
                        <page string="Products" name="products">
                            <field
                                name="order_line"
                                widget="section_and_note_one2many"
                                mode="tree,kanban"
                                context="{'default_state': 'draft'}"
                                attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}"
                            >
                                <tree 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" invisible="1" />
                                    <field name="currency_id" invisible="1" />
                                    <field name="state" invisible="1" readonly="1" />
                                    <field name="product_type" invisible="1" />
                                    <field
                                        name="product_uom_category_id"
                                        invisible="1"
                                    />
                                    <field name="invoice_lines" invisible="1" />
                                    <field name="sequence" widget="handle" />
                                    <field
                                        name="product_uom"
                                        invisible="1"
                                        groups="!uom.group_uom"
                                    />
                                    <field
                                        name="product_id"
                                        attrs="{
                                            'readonly': [('state', 'in', ('purchase', 'to approve','done', 'cancel'))],
                                            'required': [('display_type', '=', False)],
                                        }"
                                        context="{'partner_id':parent.partner_id, 'quantity':product_qty,'uom':product_uom, 'company_id': parent.company_id}"
                                        force_save="1"
                                        domain="[('purchase_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]"
                                    />
                                    <field name="name" widget="section_and_note_text" />
                                    <field
                                        name="date_planned"
                                        optional="hide"
                                        attrs="{'required': [('display_type', '=', False)]}"
                                        force_save="1"
                                    />
                                    <field
                                        name="account_analytic_id"
                                        optional="hide"
                                        context="{'default_partner_id':parent.partner_id}"
                                        groups="analytic.group_analytic_accounting"
                                    />
                                    <field name="product_qty" />
                                    <field name="refund_only" />
                                    <field
                                        name="qty_invoiced"
                                        string="Refunded"
                                        attrs="{'column_invisible': [('parent.state', 'not in', ('purchase', 'done'))]}"
                                        optional="show"
                                    />
                                    <field
                                        name="product_uom"
                                        string="UoM"
                                        groups="uom.group_uom"
                                        attrs="{
                                            'readonly': [('state', 'in', ('purchase', 'done', 'cancel'))],
                                            'required': [('display_type', '=', False)]
                                        }"
                                        force_save="1"
                                        optional="show"
                                    />
                                    <field
                                        name="price_unit"
                                        attrs="{'readonly': [('invoice_lines', '!=', [])]}"
                                    />
                                    <field
                                        name="taxes_id"
                                        widget="many2many_tags"
                                        domain="[('type_tax_use','=','purchase'), ('company_id', '=', parent.company_id)]"
                                        context="{'default_type_tax_use': 'purchase', 'search_view_ref': 'account.account_tax_view_search'}"
                                        options="{'no_create': True}"
                                        optional="show"
                                    />
                                    <field name="price_subtotal" widget="monetary" />
                                </tree>
                                <form string="Purchase Return Order Line">
                                        <field name="state" invisible="1" />
                                        <field name="display_type" invisible="1" />
                                        <group
                                        attrs="{'invisible': [('display_type', '!=', False)]}"
                                    >
                                            <group>
                                                <field
                                                name="product_uom_category_id"
                                                invisible="1"
                                            />
                                                <field
                                                name="product_id"
                                                context="{'partner_id': parent.partner_id}"
                                                widget="many2one_barcode"
                                                domain="[('purchase_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]"
                                            />
                                                <label for="product_qty" />
                                                <div class="o_row">
                                                    <field name="product_qty" />
                                                    <field
                                                    name="product_uom"
                                                    groups="uom.group_uom"
                                                    attrs="{'required': [('display_type', '=', False)]}"
                                                />
                                                </div>
                                                <field
                                                name="qty_invoiced"
                                                string="Refunded Quantity"
                                                attrs="{'invisible': [('parent.state', 'not in', ('purchase', 'done'))]}"
                                            />
                                                <field name="price_unit" />
                                                <field
                                                name="taxes_id"
                                                widget="many2many_tags"
                                                domain="[('type_tax_use', '=', 'purchase'), ('company_id', '=', parent.company_id)]"
                                                options="{'no_create': True}"
                                            />
                                            </group>
                                            <group>
                                                <field
                                                name="date_planned"
                                                widget="date"
                                                attrs="{'required': [('display_type', '=', False)]}"
                                            />
                                                <field
                                                name="account_analytic_id"
                                                colspan="2"
                                                domain="['|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]"
                                                groups="analytic.group_analytic_accounting"
                                            />
                                            </group>
                                            <group colspan="12">
                                            <notebook>
                                                <page string="Notes" name="notes">
                                                    <field name="name" />
                                                </page>
                                                <page
                                                    string="Refunds and Outgoing Shipments"
                                                    name="invoices_outgoing_shiptments"
                                                >
                                                    <field name="invoice_lines" />
                                                </page>
                                            </notebook>
                                            </group>
                                        </group>
                                        <label
                                        for="name"
                                        string="Section Name (eg. Products, Services)"
                                        attrs="{'invisible': [('display_type', '!=', 'line_section')]}"
                                    />
                                        <label
                                        for="name"
                                        string="Note"
                                        attrs="{'invisible': [('display_type', '!=', 'line_note')]}"
                                    />
                                        <field
                                        name="name"
                                        nolabel="1"
                                        attrs="{'invisible': [('display_type', '=', False)]}"
                                    />
                                 </form>
                                 <kanban class="o_kanban_mobile">
                                     <field name="name" />
                                     <field name="product_id" />
                                     <field name="product_qty" />
                                     <field name="product_uom" groups="uom.group_uom" />
                                     <field name="price_subtotal" />
                                     <field name="price_tax" invisible="1" />
                                     <field name="price_total" invisible="1" />
                                     <field name="price_unit" />
                                     <field name="display_type" />
                                     <field name="taxes_id" invisible="1" />
                                     <templates>
                                         <t t-name="kanban-box">
                                             <div
                                                t-attf-class="oe_kanban_card oe_kanban_global_click {{ record.display_type.raw_value ? 'o_is_' + record.display_type.raw_value : '' }}"
                                            >
                                                 <t
                                                    t-if="!record.display_type.raw_value"
                                                >
                                                     <div class="row">
                                                         <div class="col-8">
                                                             <strong>
                                                                 <span
                                                                    t-esc="record.product_id.value"
                                                                />
                                                             </strong>
                                                         </div>
                                                         <div class="col-4">
                                                             <strong>
                                                                 <span
                                                                    t-esc="record.price_subtotal.value"
                                                                    class="float-right text-right"
                                                                />
                                                             </strong>
                                                         </div>
                                                     </div>
                                                     <div class="row">
                                                         <div class="col-12 text-muted">
                                                             <span>
                                                                 Quantity:
                                                                 <t
                                                                    t-esc="record.product_qty.value"
                                                                />
                                                                 <t
                                                                    t-esc="record.product_uom.value"
                                                                />
                                                             </span>
                                                         </div>
                                                     </div>
                                                     <div class="row">
                                                         <div class="col-12 text-muted">
                                                             <span>
                                                                 Unit Price:
                                                                 <t
                                                                    t-esc="record.price_unit.value"
                                                                />
                                                             </span>
                                                         </div>
                                                     </div>
                                                 </t>
                                                 <div
                                                    t-elif="record.display_type.raw_value === 'line_section' || record.display_type.raw_value === 'line_note'"
                                                    class="row"
                                                >
                                                     <div class="col-12">
                                                         <span
                                                            t-esc="record.name.value"
                                                        />
                                                     </div>
                                                 </div>
                                             </div>
                                         </t>
                                     </templates>
                                 </kanban>
                            </field>
                            <group class="oe_subtotal_footer oe_right">
                                <field
                                    name="amount_untaxed"
                                    widget="monetary"
                                    options="{'currency_field': 'currency_id'}"
                                />
                                <field
                                    name="amount_tax"
                                    widget="monetary"
                                    options="{'currency_field': 'currency_id'}"
                                />
                                <div class="oe_subtotal_footer_separator oe_inline">
                                    <label for="amount_total" />
                                </div>
                                <field
                                    name="amount_total"
                                    nolabel="1"
                                    class="oe_subtotal_footer_separator"
                                    widget="monetary"
                                    options="{'currency_field': 'currency_id'}"
                                />
                            </group>
                            <field
                                name="notes"
                                class="oe_inline"
                                placeholder="Define your terms and conditions ..."
                            />
                            <div class="oe_clear" />
                        </page>
                        <page
                            string="Other Information"
                            name="purchase_delivery_invoice"
                        >
                            <group>
                                <group name="other_info">
                                    <field
                                        name="user_id"
                                        domain="[('share', '=', False)]"
                                        widget="many2one_avatar_user"
                                    />
                                    <field
                                        name="company_id"
                                        groups="base.group_multi_company"
                                        options="{'no_create': True}"
                                    />
                                </group>
                                <group name="invoice_info">
                                    <field
                                        name="invoice_status"
                                        attrs="{'invisible': [('state', 'in', ('draft', 'sent', 'to approve', 'cancel'))]}"
                                    />
                                    <field
                                        name="payment_term_id"
                                        attrs="{'readonly': ['|', ('invoice_status','=', 'invoiced'), ('state', '=', 'done')]}"
                                        options="{'no_create': True}"
                                    />
                                    <field
                                        name="company_id"
                                        invisible="1"
                                        groups="!base.group_multi_company"
                                    />
                                    <field
                                        name="fiscal_position_id"
                                        options="{'no_create': True}"
                                        attrs="{'readonly': ['|', ('invoice_status','=', 'invoiced'), ('state', '=', 'done')]}"
                                    />
                                </group>
                            </group>
                        </page>
                    </notebook>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" />
                    <field name="activity_ids" />
                    <field name="message_ids" />
                </div>
                </form>
            </field>
        </record>

       <record id="view_purchase_return_order_filter" model="ir.ui.view">
            <field name="name">purchase.return.draft.select</field>
            <field name="model">purchase.return.order</field>
            <field name="arch" type="xml">
                <search string="Search Purchase Return Order">
                    <field
                    name="name"
                    string="Order"
                    filter_domain="['|', '|', ('name', 'ilike', self), ('partner_ref', 'ilike', self), ('partner_id', 'child_of', self)]"
                />
                    <field name="partner_id" operator="child_of" />
                    <field name="user_id" />
                    <field name="product_id" />
                    <filter
                    name="my_purchases"
                    string="My Purchase Returns"
                    domain="[('user_id', '=', uid)]"
                />
                    <separator />
                    <filter
                    name="draft"
                    string="Drafts"
                    domain="[('state', 'in', ('draft', 'sent', 'to approve'))]"
                />
                    <separator />
                    <filter
                    name="approved"
                    string="Purchase Return Orders"
                    domain="[('state', 'in', ('purchase', 'done'))]"
                />
                    <filter
                    name="to_approve"
                    string="To Approve"
                    domain="[('state', '=', 'to approve')]"
                />
                    <separator />
                    <filter name="order_date" string="Order Date" date="date_order" />
                    <filter
                    name="draft_rfqs"
                    string="Drafts"
                    domain="[('state', '=', 'draft')]"
                />
                    <filter
                    name="waiting_drafts"
                    string="Waiting"
                    domain="[('state', '=', 'sent'), ('date_order', '&gt;=', datetime.datetime.now())]"
                />
                    <filter
                    name="late_drafts"
                    string="Late"
                    domain="[('state', 'in', ['draft', 'sent', 'to approve']),('date_order', '&lt;', datetime.datetime.now())]"
                />
                    <separator />
                    <filter
                    invisible="1"
                    string="Late Activities"
                    name="activities_overdue"
                    domain="[('activity_ids.date_deadline', '&lt;', context_today().strftime('%Y-%m-%d'))]"
                    help="Show all records which has next action date is before today"
                />
                    <filter
                    invisible="1"
                    string="Today Activities"
                    name="activities_today"
                    domain="[('activity_ids.date_deadline', '=', context_today().strftime('%Y-%m-%d'))]"
                />
                    <filter
                    invisible="1"
                    string="Future Activities"
                    name="activities_upcoming_all"
                    domain="[('activity_ids.date_deadline', '&gt;', context_today().strftime('%Y-%m-%d'))]"
                />
                    <separator />
                    <filter
                    string="Warnings"
                    name="activities_exception"
                    domain="[('activity_exception_decoration', '!=', False)]"
                />
                    <group expand="0" string="Group By">
                        <filter
                        string="Vendor"
                        name="vendor"
                        domain="[]"
                        context="{'group_by': 'partner_id'}"
                    />
                        <filter
                        string="Purchase Representative"
                        name="representative"
                        domain="[]"
                        context="{'group_by': 'user_id'}"
                    />
                        <filter
                        string="Order Date"
                        name="order_date"
                        domain="[]"
                        context="{'group_by': 'date_order'}"
                    />
                    </group>
                </search>
            </field>
        </record>

        <record id="purchase_return_order_view_search" model="ir.ui.view">
            <field name="name">purchase.return.order.select</field>
            <field name="model">purchase.return.order</field>
            <field name="arch" type="xml">
                <search string="Search Purchase Order">
                    <field
                    name="name"
                    string="Order"
                    filter_domain="['|', ('name', 'ilike', self), ('partner_id', 'child_of', self)]"
                />
                    <field name="partner_id" operator="child_of" />
                    <field name="user_id" />
                    <field name="product_id" />
                    <filter
                    name="my_Orders"
                    string="My Orders"
                    domain="[('user_id', '=', uid)]"
                />
                    <separator />
                    <filter
                    name="not_invoiced"
                    string="Waiting Bills"
                    domain="[('invoice_status', '=', 'to invoice')]"
                    help="Purchase orders that include lines not invoiced."
                />
                    <filter
                    name="invoiced"
                    string="Bills Received"
                    domain="[('invoice_status', '=', 'invoiced')]"
                    help="Purchase orders that have been invoiced."
                />
                    <separator />
                    <filter name="order_date" string="Order Date" date="date_order" />
                    <separator />
                    <filter
                    invisible="1"
                    string="Late Activities"
                    name="activities_overdue"
                    domain="[('activity_ids.date_deadline', '&lt;', context_today().strftime('%Y-%m-%d'))]"
                    help="Show all records which has next action date is before today"
                />
                    <filter
                    invisible="1"
                    string="Today Activities"
                    name="activities_today"
                    domain="[('activity_ids.date_deadline', '=', context_today().strftime('%Y-%m-%d'))]"
                />
                    <filter
                    invisible="1"
                    string="Future Activities"
                    name="activities_upcoming_all"
                    domain="[('activity_ids.date_deadline', '&gt;', context_today().strftime('%Y-%m-%d'))]"
                />
                    <separator />
                    <filter
                    string="Warnings"
                    name="activities_exception"
                    domain="[('activity_exception_decoration', '!=', False)]"
                />
                    <group expand="0" string="Group By">
                        <filter
                        string="Vendor"
                        name="vendor"
                        domain="[]"
                        context="{'group_by': 'partner_id'}"
                    />
                        <filter
                        string="Purchase Representative"
                        name="representative"
                        domain="[]"
                        context="{'group_by': 'user_id'}"
                    />
                        <filter
                        string="Order Date"
                        name="order_date"
                        domain="[]"
                        context="{'group_by': 'date_order'}"
                    />
                    </group>
                </search>
            </field>
        </record>


        <!-- Purchase Orders Kanban View  -->
        <record model="ir.ui.view" id="view_purchase_return_order_kanban">
            <field name="name">purchase.return.order.kanban</field>
            <field name="model">purchase.return.order</field>
            <field name="arch" type="xml">
                <kanban
                class="o_kanban_mobile"
                js_class="purchase_kanban_dashboard"
                sample="1"
            >
                    <field name="name" />
                    <field name="partner_id" readonly="1" />
                    <field name="amount_total" />
                    <field name="state" />
                    <field name="date_order" />
                    <field name="currency_id" readonly="1" />
                    <field name="activity_state" />
                    <progressbar
                    field="activity_state"
                    colors='{"planned": "success", "today": "warning", "overdue": "danger"}'
                />
                    <templates>
                        <t t-name="kanban-box">
                            <div t-attf-class="oe_kanban_card oe_kanban_global_click">
                                <div class="o_kanban_record_top mb16">
                                    <div class="o_kanban_record_headings ml-1">
                                        <strong class="o_kanban_record_title"><span><t
                                                t-esc="record.partner_id.value"
                                            /></span></strong>
                                    </div>
                                    <strong><field
                                        name="amount_total"
                                        widget="monetary"
                                    /></strong>
                                </div>
                                <div class="o_kanban_record_bottom">
                                    <div class="oe_kanban_bottom_left">
                                        <span><t t-esc="record.name.value" /> <t
                                            t-esc="record.date_order.value and record.date_order.value.split(' ')[0] or False"
                                        /></span>
                                        <field
                                        name="activity_ids"
                                        widget="kanban_activity"
                                    />
                                    </div>
                                    <div class="oe_kanban_bottom_right">
                                        <field
                                        name="state"
                                        widget="label_selection"
                                        options="{'classes': {'draft': 'default', 'cancel': 'default', 'done': 'success', 'approved': 'warning'}}"
                                    />
                                    </div>
                                </div>
                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>

        <record id="purchase_return_order_tree" model="ir.ui.view">
            <field name="name">purchase.return.order.tree</field>
            <field name="model">purchase.return.order</field>
            <field name="priority" eval="1" />
            <field name="arch" type="xml">
                <tree
                multi_edit="1"
                decoration-muted="state=='cancel'"
                decoration-info="state in ('wait','confirmed')"
                sample="1"
            >
                    <!-- pylint : disable=duplicate-xml-fields -->
                    <field
                    name="company_id"
                    invisible="1"
                    groups="!base.group_multi_company"
                />
                    <field name="partner_ref" optional="hide" />
                    <field name="name" string="Reference" readonly="1" />
                    <field
                    name="date_order"
                    invisible="not context.get('quotation_only', False)"
                    optional="show"
                />
                    <field
                    name="date_approve"
                    invisible="context.get('quotation_only', False)"
                    optional="show"
                />
                    <field name="partner_id" readonly="1" />
                    <field
                    name="company_id"
                    readonly="1"
                    options="{'no_create': True}"
                    groups="base.group_multi_company"
                    optional="show"
                />
                    <field
                    name="date_planned"
                    invisible="context.get('quotation_only', False)"
                    optional="show"
                />
                    <field name="user_id" optional="show" />
                    <field name="origin" optional="show" />
                    <field
                    name="amount_untaxed"
                    sum="Total Untaxed amount"
                    string="Untaxed"
                    widget="monetary"
                    optional="hide"
                />
                    <field
                    name="amount_total"
                    sum="Total amount"
                    widget="monetary"
                    optional="show"
                />
                    <field name="currency_id" invisible="1" />
                    <field name="state" optional="show" />
                    <field name="invoice_status" optional="hide" />
                    <field
                    name="activity_exception_decoration"
                    widget="activity_exception"
                />
                </tree>
            </field>
        </record>

        <record id="purchase_return_order_view_tree" model="ir.ui.view">
            <field name="name">purchase.return.order.view.tree</field>
            <field name="model">purchase.return.order</field>
            <field name="arch" type="xml">
                <tree
                decoration-muted="state=='cancel'"
                decoration-info="state in ('wait','confirmed')"
                class="o_purchase_order"
                sample="1"
            >
                    <header />
                    <field name="partner_ref" optional="hide" />
                    <field
                    name="name"
                    string="Reference"
                    readonly="1"
                    decoration-bf="1"
                />
                    <field
                    name="date_approve"
                    widget="date"
                    invisible="context.get('quotation_only', False)"
                    optional="show"
                />
                    <field name="partner_id" />
                    <field
                    name="company_id"
                    groups="base.group_multi_company"
                    options="{'no_create': True}"
                    optional="show"
                />
                    <field
                    name="date_planned"
                    invisible="context.get('quotation_only', False)"
                    optional="show"
                />
                    <field
                    name="user_id"
                    widget="many2one_avatar_user"
                    optional="show"
                />
                    <field
                    name="date_order"
                    invisible="not context.get('quotation_only', False)"
                    optional="show"
                />
                    <field name="activity_ids" widget="list_activity" optional="show" />
                    <field name="origin" optional="show" />
                    <field
                    name="amount_untaxed"
                    sum="Total Untaxed amount"
                    string="Untaxed"
                    widget="monetary"
                    optional="hide"
                />
                    <field
                    name="amount_total"
                    sum="Total amount"
                    widget="monetary"
                    optional="show"
                    decoration-bf="1"
                />
                    <field name="currency_id" invisible="1" />
                    <field name="state" invisible="1" />
                    <field
                    name="invoice_status"
                    widget="badge"
                    decoration-success="invoice_status == 'invoiced'"
                    decoration-info="invoice_status == 'to invoice'"
                    optional="show"
                />
                </tree>
            </field>
        </record>

        <record id="purchase_return_order_view_activity" model="ir.ui.view">
            <field name="name">purchase.return.order.activity</field>
            <field name="model">purchase.return.order</field>
            <field name="arch" type="xml">
                <activity string="Purchase Return Order">
                    <templates>
                        <div t-name="activity-box">
                            <div>
                                <field name="name" display="full" />
                                <field name="partner_id" muted="1" display="full" />
                            </div>
                        </div>
                    </templates>
                </activity>
            </field>
        </record>

        <record id="purchase_return_form_action" model="ir.actions.act_window">
            <field name="name">Purchase Return Orders</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">purchase.return.order</field>
            <field name="view_mode">tree,kanban,form,pivot,graph,activity</field>
            <field name="view_id" ref="purchase_return_order_view_tree" />
            <field name="search_view_id" ref="purchase_return_order_view_search" />
            <field name="context">{}</field>
            <field name="help" type="html">
              <p class="o_view_nocontent_smiling_face">
                No purchase order found. Let's create one!
              </p><p>
                Once you ordered your products to your supplier, confirm your request for quotation and it will turn into a purchase order.
              </p>
            </field>
        </record>
        <menuitem
        action="purchase_return_form_action"
        id="menu_purchase_return_form_action"
        parent="purchase.menu_procurement_management"
        sequence="6"
    />

        <record id="purchase_return_order_line_tree" model="ir.ui.view">
            <field name="name">purchase.return.order.line.tree</field>
            <field name="model">purchase.return.order.line</field>
            <field name="arch" type="xml">
                <tree create="false">
                    <field name="order_id" />
                    <field name="name" />
                    <field name="partner_id" string="Vendor" />
                    <field name="product_id" />
                    <field name="price_unit" />
                    <field name="product_qty" />
                    <field name="product_uom" groups="uom.group_uom" />
                    <field name="price_subtotal" widget="monetary" />
                    <field name="currency_id" invisible="1" />
                    <field name="date_planned" widget="date" />
                </tree>
            </field>
        </record>

        <record id="purchase_return_order_line_form2" model="ir.ui.view">
            <field name="name">purchase.return.order.line.form2</field>
            <field name="model">purchase.return.order.line</field>
            <field name="priority" eval="20" />
            <field name="arch" type="xml">
                <form string="Purchase Order Line" create="false">
                    <sheet>
                        <label for="order_id" class="oe_edit_only" />
                        <h1>
                            <field name="order_id" class="oe_inline" />
                            <label
                            string=","
                            for="date_order"
                            attrs="{'invisible':[('date_order','=',False)]}"
                        />
                            <field name="date_order" class="oe_inline" />
                        </h1>
                        <label for="partner_id" class="oe_edit_only" />
                        <h2><field name="partner_id" /></h2>
                        <group>
                            <group>
                                <field name="product_id" readonly="1" />
                                <label for="product_qty" />
                                <div class="o_row">
                                    <field name="product_qty" readonly="1" />
                                    <field
                                    name="product_uom"
                                    readonly="1"
                                    groups="uom.group_uom"
                                />
                                </div>
                                <field name="price_unit" />
                            </group>
                            <group>
                                <field
                                name="taxes_id"
                                widget="many2many_tags"
                                domain="[('type_tax_use', '=', 'purchase')]"
                            />
                                <field name="date_planned" widget="date" readonly="1" />
                                <field
                                name="company_id"
                                groups="base.group_multi_company"
                                options="{'no_create': True}"
                            />
                                <field
                                name="account_analytic_id"
                                colspan="4"
                                groups="analytic.group_analytic_accounting"
                            />
                            </group>
                        </group>
                        <field name="name" />
                        <separator string="Manual Invoices" />
                        <field name="invoice_lines" />
                    </sheet>
                </form>
            </field>
        </record>
          <record id="purchase_return_order_line_search" model="ir.ui.view">
            <field name="name">purchase.return.order.line.search</field>
            <field name="model">purchase.return.order.line</field>
            <field name="arch" type="xml">
                <search string="Search Return Purchase Order">
                    <field name="order_id" />
                    <field name="product_id" />
                    <field
                    name="partner_id"
                    string="Vendor"
                    filter_domain="[('partner_id', 'child_of', self)]"
                />
                    <filter
                    name="hide_cancelled"
                    string="Hide cancelled lines"
                    domain="[('state', '!=', 'cancel')]"
                />
                    <group expand="0" string="Group By">
                        <filter
                        name="groupby_supplier"
                        string="Vendor"
                        domain="[]"
                        context="{'group_by' : 'partner_id'}"
                    />
                        <filter
                        name="groupby_product"
                        string="Product"
                        domain="[]"
                        context="{'group_by' : 'product_id'}"
                    />
                        <filter
                        string="Order Reference"
                        name="order_reference"
                        domain="[]"
                        context="{'group_by' :'order_id'}"
                    />
                        <filter
                        string="Status"
                        name="status"
                        domain="[]"
                        context="{'group_by' : 'state'}"
                    />
                    </group>
                </search>
            </field>
        </record>


</odoo>
