<?xml version="1.0" ?>
<!-- Copyright 2018 Tecnativa - Carlos Dauden
     Copyright 2023 Tecnativa - Carolina Fernandez
     Copyright 2024 Tecnativa - Juan José Seguí
     License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
    <record id="view_sales_order_line_input_tree" model="ir.ui.view">
        <field name="name">sale.order.line.input.list.view</field>
        <field name="model">sale.order.line</field>
        <field name="priority">20</field>
        <field name="arch" type="xml">
            <list
                decoration-info="invoice_status == 'to invoice'"
                decoration-warning="state == 'draft'"
                decoration-muted="state == 'cancel'"
                decoration-success="invoice_status == 'invoiced'"
                editable="top"
                create="true"
            >
                <!-- We do not display the type because we don't want the user to be bothered with
                that information if he has no section or note. -->
                <field
                    name="force_company_id"
                    optional="hide"
                    readonly="order_id"
                    options="{'no_create': True}"
                />
                <field
                    name="order_id"
                    string="Order"
                    required="0"
                    placeholder="New"
                    readonly="order_id"
                    domain="[('state', '!=', 'cancel'),('company_id', '=', company_id)]"
                    force_save="1"
                    options='{"no_create": True}'
                />
                <field
                    name="order_partner_id"
                    context="{'res_partner_search_mode': 'customer', 'default_is_company': True, 'default_customer_rank': 1}"
                    options='{"always_reload": True}'
                    required="1"
                    readonly="order_partner_id and order_id"
                />
                <field name="write_date" widget="date" optional="hide" />
                <!-- The product_id field does not have optional="hide" and widget="sol_product_many2one" intentionally because it is not compatible outside the sales order form view.. !-->
                <field
                    name="product_id"
                    string="Product Variant"
                    readonly="not product_updatable"
                    required="not display_type and not is_downpayment"
                    force_save="1"
                    context="{
                        'partner_id': order_partner_id,
                        'quantity': product_uom_qty,
                        'pricelist': pricelist_id,
                        'uom':product_uom,
                        'company_id': company_id,
                        'default_lst_price': price_unit,
                        'default_uom_id': product_uom,
                    }"
                    options="{
                        'no_open': True,
                    }"
                    domain="[('sale_ok', '=', True)]"
                />
                <!-- The product_template_id field has column_invisible=1 intentionally because it is not compatible outside the sales order form view. !-->
                <field
                    name="product_template_id"
                    string="Product"
                    readonly="id and not product_updatable"
                    required="not display_type and not is_downpayment"
                    context="{
                        'partner_id': order_partner_id,
                        'quantity': product_uom_qty,
                        'pricelist': pricelist_id,
                        'uom':product_uom,
                        'company_id': company_id,
                        'default_list_price': price_unit,
                        'default_uom_id': product_uom,
                    }"
                    options="{
                        'no_open': True,
                    }"
                    optional="show"
                    domain="[('sale_ok', '=', True)]"
                    widget="sol_product_many2one"
                    column_invisible="True"
                    placeholder="Type to find a product..."
                />
                <field name="name" widget="sol_text" optional="show" />
                <field
                    name="analytic_distribution"
                    widget="analytic_distribution"
                    optional="hide"
                    groups="analytic.group_analytic_accounting"
                    options="{'product_field': 'product_id', 'business_domain': 'sale_order', 'amount_field': 'price_subtotal'}"
                />
                <field
                    name="product_uom_qty"
                    decoration-info="(not display_type and invoice_status == 'to invoice')"
                    decoration-bf="(not display_type and invoice_status == 'to invoice')"
                    context="{
                        'partner_id': order_partner_id,
                        'quantity': product_uom_qty,
                        'pricelist': pricelist_id,
                        'uom': product_uom,
                        'company_id': company_id
                    }"
                    readonly="is_downpayment"
                />
                <field
                    name="qty_delivered"
                    decoration-info="(not display_type and invoice_status == 'to invoice')"
                    decoration-bf="(not display_type and invoice_status == 'to invoice')"
                    string="Delivered"
                    invisible="state != 'sale'"
                    readonly="qty_delivered_method != 'manual' or is_downpayment"
                    optional="show"
                />
                <field
                    name="qty_invoiced"
                    decoration-info="(not display_type and invoice_status == 'to invoice')"
                    decoration-bf="(not display_type and invoice_status == 'to invoice')"
                    string="Invoiced"
                    invisible="state != 'sale'"
                    optional="show"
                />
                <field name="product_uom" column_invisible="1" />
                <field
                    name="product_uom"
                    force_save="1"
                    string="UoM"
                    readonly="product_uom_readonly"
                    required="not display_type and not is_downpayment"
                    context="{'company_id': company_id}"
                    groups="uom.group_uom"
                    options='{"no_open": True}'
                    width="60px"
                    optional="show"
                />
                <field
                    name="customer_lead"
                    optional="hide"
                    width="80px"
                    readonly="state not in ['draft', 'sent', 'sale'] or is_downpayment"
                />
                <field
                    name="product_packaging_qty"
                    invisible="not product_id or not product_packaging_id"
                    groups="product.group_stock_packaging"
                    optional="show"
                />
                <field
                    name="product_packaging_id"
                    invisible="not product_id"
                    context="{'default_product_id': product_id, 'list_view_ref':'product.product_packaging_tree_view', 'form_view_ref':'product.product_packaging_form_view'}"
                    groups="product.group_stock_packaging"
                    optional="show"
                />
                <field name="price_unit" readonly="qty_invoiced &gt; 0" />
                <field
                    name="tax_id"
                    widget="many2many_tags"
                    options="{'no_create': True}"
                    domain="[('type_tax_use', '=', 'sale'), ('company_id', 'parent_of', company_id), ('country_id', '=', tax_country_id)]"
                    context="{'active_test': True}"
                    readonly="qty_invoiced &gt; 0 or is_downpayment"
                    optional="show"
                />
                <field
                    name="discount"
                    string="Disc.%"
                    groups="sale.group_discount_per_so_line"
                    width="50px"
                    optional="show"
                />
                <!-- There are 2 "Amount" fields (price_subtotal + price_total), and they are shown according to the option defined in the company in the account_price_include field, we don't want to show always 2 columns and only 1 has the right data, therefore, the new company_price_amount field reflects the right data of each row. !-->
                <field
                    name="company_price_amount"
                    invisible="is_downpayment"
                    string="Amount"
                />
                <!-- Optional amounts -->
                <!-- There are 2 "similar" fields (price_total + price_subtotal), and they are shown according to the option defined in the company in the account_price_include field, we don't want to show always 2 columns and only 1 has the right data, therefore, the new company_price_tax_incl_excl field reflects the right data of each row. !-->
                <field
                    name="company_price_tax_incl_excl"
                    optional="hide"
                    invisible="is_downpayment"
                    string="Total"
                />
            </list>
        </field>
    </record>
    <record id="view_sales_order_line_filter" model="ir.ui.view">
        <field name="model">sale.order.line</field>
        <field name="inherit_id" ref="sale.view_sales_order_line_filter" />
        <field name="arch" type="xml">
            <xpath expr="//field[@name='salesman_id']" position="after">
                <field name="name" />
                <field name="product_uom" groups="uom.group_uom" />
                <field
                    name="analytic_distribution"
                    groups="analytic.group_analytic_accounting"
                />
                <separator />
                <filter
                    name="not_invoice_related"
                    string="Not Invoice Related"
                    domain="[('invoice_lines', '=', False)]"
                />
                <filter
                    name="invoice_related"
                    string="Invoice Related"
                    domain="[('invoice_lines', '!=', False)]"
                    context="{'tax_hide': True}"
                />
            </xpath>
            <xpath expr="//filter[@name='product']/.." position="inside">
                <filter
                    name="order_state"
                    string="Order State"
                    context="{'group_by': 'state'}"
                />
                <filter
                    name="invoice_status"
                    string="Invoice Status"
                    context="{'group_by': 'invoice_status'}"
                />
                <filter
                    name="uom_filter"
                    string="UoM"
                    context="{'group_by': 'product_uom'}"
                    groups="uom.group_uom"
                />
            </xpath>
        </field>
    </record>
    <record id="action_sales_order_line_input" model="ir.actions.act_window">
        <field name="name">Sales Orders Lines</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">sale.order.line</field>
        <field name="view_mode">list,form,pivot,graph</field>
        <field name="view_id" ref="view_sales_order_line_input_tree" />
    </record>
    <menuitem
        id="menu_sales_order_line_input"
        action="action_sales_order_line_input"
        parent="sale.sale_order_menu"
        groups="sales_team.group_sale_salesman"
        sequence="30"
    />
</odoo>
