<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="view_stock_barcodes_read_inventory_form" model="ir.ui.view">
        <field name="name">stock.barcodes.read.inventory.form</field>
        <field name="model">wiz.stock.barcodes.read.inventory</field>
        <field name="inherit_id" ref="stock_barcodes.view_stock_barcodes_read_form" />
        <field name="mode">primary</field>
        <field name="priority">99</field>
        <field name="arch" type="xml">
            <field name="product_qty" position="after">
                <field name="inventory_product_qty" invisible="1" />
            </field>
            <!-- hide result package from inventory -->
            <group name="quant_package" position="replace">
                <div class="mt4">
                    <strong class="d-none d-sm-block">Package</strong>
                    <span
                        class="fa fa-inbox fa-2x d-sm-none oe_span_small_icon"
                        title="package"
                    />
                    <field
                        name="package_id"
                        options="{'no_create': True}"
                        attrs="{'readonly': [('manual_entry', '=', False)]}"
                        force_save="1"
                        style="width:85%"
                        class="h5"
                    />
                </div>
            </group>
            <field name="location_id" position="attributes">
                <attribute name="domain">[('usage', 'in', ['internal', 'transit'])]
                </attribute>
            </field>
            <group name="scan_fields" position="after">
                <group
                    string="Inventory quants"
                    attrs="{'invisible': [('inventory_quant_ids', '=', [])]}"
                    col="2"
                    class="px-3"
                >
                    <field
                        name="inventory_quant_ids"
                        options="{'no_open': True}"
                        nolabel="1"
                        colspan="2"
                        mode="kanban"
                    >
                        <kanban
                            class="o_kanban_mobile"
                            js_class="stock_barcodes_kanban"
                        >
                            <field name="product_id" />
                            <field name="inventory_quantity" />
                            <field name="product_uom_id" />
                            <templates>
                                <t t-name="kanban-box">
                                    <div t-on-click="onCustomGlobalClick">
                                        <div class="row w-auto">
                                            <div class="col-8 col-md-10">
                                                <field name="product_id" class="h2" />
                                            </div>
                                            <div
                                                class="col-4 col-md-2 d-flex justify-content-end align-items-center"
                                            >
                                                <img
                                                    t-att-src="kanban_image('product.product', 'image_128', record.product_id.raw_value)"
                                                    role="img"
                                                    t-att-title="record.product_id.value"
                                                    height="40"
                                                    width="40"
                                                    t-att-alt="record.product_id.value"
                                                />
                                                <button
                                                    name="action_barcode_inventory_quant_edit"
                                                    type="object"
                                                    class="btn mt0"
                                                    context="{'wiz_barcode_id': parent.id}"
                                                >
                                                    <i
                                                        class="fa fa-pencil"
                                                        title="Edit inventory quantity"
                                                    />
                                                </button>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div
                                                class="col-8 col-md-10 d-flex justify-content-start align-items-center"
                                            >
                                                <span
                                                    t-if="record.lot_id.raw_value"
                                                    class="h3"
                                                >Lot S/N:&#32;&#32;</span>
                                                <field
                                                    t-if="record.lot_id.raw_value"
                                                    name="lot_id"
                                                    class="h2"
                                                />
                                            </div>
                                            <div
                                                class="col-4 col-md-2 d-flex justify-content-end align-items-center"
                                            >
                                                <span class="fw-bold mx-3">
                                                    <field name="inventory_quantity" />
                                                </span>
                                                <button
                                                    name="action_barcode_inventory_quant_unlink"
                                                    type="object"
                                                    class="btn mt0"
                                                    context="{'wiz_barcode_id': parent.id}"
                                                >
                                                    <i
                                                        class="fa fa-trash"
                                                        title="Reset inventory quantity"
                                                    />
                                                </button>
                                            </div>
                                        </div>
                                        <div
                                            t-attf-class="row oe_kanban_operations oe_kanban_operations-#{record.id.raw_value} d-none"
                                        >
                                            <div
                                                class="d-flex justify-content-end align-items-center"
                                            >
                                                <button
                                                    name="operation_quantities_rest"
                                                    type="object"
                                                    class="btn btn-lg btn-op-rest text-white ms-2 ms-sm-4 mx-2"
                                                >-1
                                                </button>
                                                <button
                                                    name="operation_quantities"
                                                    type="object"
                                                    class="btn btn-lg btn-op-sum text-white"
                                                >+1
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </t>
                            </templates>
                        </kanban>
                    </field>
                </group>
            </group>
            <xpath
                expr="//div[hasclass('oe_stock_barcodes_bottombar')]//div[hasclass('dropup')]"
                position="inside"
            >
                <field
                    name="display_read_quant"
                    widget="barcode_boolean_toggle"
                    class="d-none"
                />
                <button
                    name="action_display_read_quant"
                    type="object"
                    title="Read items"
                    icon="fa-eye fa-2x"
                    attrs="{'invisible': [('display_read_quant', '=', True)]}"
                />

                <button
                    name="action_display_read_quant"
                    type="object"
                    title="Read items"
                    icon="fa-eye-slash fa-2x"
                    attrs="{'invisible': [('display_read_quant', '=', False)]}"
                />
            </xpath>
            <button name="action_clean_values" position="before">
                <button
                    name="apply_inventory"
                    type="object"
                    icon="fa-check fa-2x"
                    class="btn-primary w-100 oe_kanban_action_button btn-sm  d-flex justify-content-center align-items-center fs-1"
                    attrs="{'invisible': ['|', '|',('display_menu', '=', True), ('inventory_quant_ids', '=', []), ('display_read_quant', '=', False)]}"
                    data-hotkey="7"
                    groups="stock.group_stock_manager"
                >
                    <span class="d-none d-lg-block">Apply</span>
                    (<span class="count_apply_inventory" />)
                </button>
            </button>
        </field>
    </record>
    <!--
     Open wizard in current target option to avoid that the wizard is
     closed after any button click,
    -->
    <record id="action_stock_barcodes_read_inventory" model="ir.actions.act_window">
        <field name="res_model">wiz.stock.barcodes.read.inventory</field>
        <field name="name">Barcodes Read</field>
        <field name="view_mode">form</field>
        <field name="context">{"control_panel_hidden": True,
                               "form_view_initial_mode": "edit",
                               "inventory_mode": True,
                               }
        </field>
        <field name="view_id" ref="view_stock_barcodes_read_inventory_form" />
        <field name="target">fullscreen</field>
    </record>
</odoo>
