<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="view_stock_barcodes_read_picking_batch_form" model="ir.ui.view">
        <field name="name">stock.barcodes.read.picking.batch.form</field>
        <field name="model">wiz.stock.barcodes.read.picking</field>
        <field name="inherit_id" ref="stock_barcodes.view_stock_barcodes_read_form" />
        <field name="mode">primary</field>
        <field name="priority">60</field>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='message_type']" position="before">
                <field
                    name="candidate_picking_batch_ids"
                    mode="kanban"
                    attrs="{'invisible': [('candidate_picking_batch_ids', '=', [])]}"
                    nolabel="1"
                    options='{"always_reload": True}'
                    force_save="1"
                >
                    <kanban>
                        <field name="name" />
                        <field name="date" />
                        <field name="state" />
                        <field name="picking_batch_id" />
                        <field name="wiz_picking_batch_id" />
                        <field name="scan_count" />
                        <field name="is_pending" />
                        <field name="product_ref_count" />
                        <field name="product_ref_done" />
                        <templates>
                            <t t-name="kanban-box">
                                <div
                                    t-att-class="'oe_kanban_color_alert' + (record.is_pending.raw_value == false ? ' bg-success text-white' : '')"
                                >
                                    <!-- TODO: Remove if not useful-->
                                    <div invisible="1">
                                        <a
                                            name="action_lock_picking"
                                            type="object"
                                            t-if="record.picking_batch_id.raw_value != record.wiz_picking_batch_id.raw_value"
                                            class="fa fa-thumb-tack fa-2x pull-right"
                                            context="{'wiz_barcode_id': parent.id, 'picking_batch_id': picking_batch_id}"
                                        />
                                        <a
                                            name="action_unlock_picking"
                                            type="object"
                                            class="pull-right"
                                            t-if="record.picking_batch_id.raw_value == record.wiz_picking_batch_id.raw_value"
                                            context="{'wiz_barcode_id': parent.id}"
                                        >
                                            <span class="fa-stack fa-lg">
                                                <!-- FIXME: Use fa-thumbtack fa-stack-2x on v13 with FA v5.4 -->
                                                <i
                                                    class="fa fa-thumb-tack fa-stack-1x"
                                                />
                                                <!-- FIXME: Use fa-slash on v13 with FA v5.4 -->
                                                <i class="fa fa-ban fa-stack-2x" />
                                            </span>
                                        </a>
                                    </div>
                                    <div>
                                    </div>
                                    <div class="oe_kanban_details">
                                        <div class="row">
                                            <div class="col">
                                                <strong>
                                                    <field name="name" />
                                                    <field
                                                        name="scan_count"
                                                        invisible="1"
                                                        force_save="1"
                                                    />
                                                </strong>
                                            </div>
                                            <div class="col">
                                                <div class="float-end">
                                                    <span
                                                        for="product_ref_count"
                                                    >#Ref: </span>
                                                    <strong>
                                                        <field
                                                            name="product_ref_count"
                                                        />
                                                    </strong>
                                                    <span> | </span>
                                                    <span
                                                        for="product_ref_done"
                                                    >#Read: </span>
                                                    <strong>
                                                        <field
                                                            name="product_ref_done"
                                                        />
                                                    </strong>
                                                </div>
                                            </div>
                                        </div>
                                        <div>
                                            <button
                                                name="action_open_picking_batch"
                                                type="object"
                                                class="btn btn-secondary float-start border"
                                                context="{'wiz_barcode_id': parent.id, 'picking_batch_id': picking_batch_id}"
                                            >Open</button>
                                            <!-- FIXME:  Fix confirm question -->
                                            <button
                                                name="action_validate_picking_batch"
                                                type="object"
                                                t-att-class="'btn float-end' + (record.is_pending.raw_value == false ? ' btn-primary' : ' btn-secondary border')"
                                                attrs="{'invisible': [('state', '!=', 'in_progress')]}"
                                                confirm="Are you sure to validate the picking batch?"
                                                context="{'wiz_barcode_id': parent.id, 'picking_batch_id': picking_batch_id}"
                                            >Validate</button>
                                        </div>
                                    </div>
                                </div>
                            </t>
                        </templates>
                    </kanban>
                </field>
                <field name="todo_line_display_ids" mode="kanban" force_save="1" />
            </xpath>
            <field name="location_id" position="before">
                <field name="picking_type_code" invisible="1" force_save="1" />
                <field name="picking_batch_id" invisible="1" force_save="1" />
                <field name="show_detailed_operations" invisible="1" />
            </field>
            <group name="scan_fields" position="after">
                <group
                    string="Pending moves"
                    attrs="{'invisible': [('pending_move_ids', '=', [])]}"
                >
                    <field
                        name="pending_move_ids"
                        options="{'no_open': True, 'always_reload': True}"
                        nolabel="1"
                        colspan="2"
                        force_save="1"
                        mode="tree,kanban"
                    >
                        <tree>
                            <field name="state" invisible="1" />
                            <field name="product_id" />
                            <field name="product_uom_qty" />
                            <field name="line_ids" invisible="1" />
                            <field
                                name="lot_id"
                                groups="stock.group_production_lot"
                                optional="hide"
                            />
                            <field
                                name="package_id"
                                groups="stock.group_tracking_lot"
                                optional="hide"
                            />
                            <field name="qty_done" />
                            <button
                                name="fill_from_pending_line"
                                type="object"
                                class="btn"
                                icon="fa-upload"
                                context="{'wiz_barcode_id': parent.id}"
                            />
                        </tree>
                        <kanban class="o_kanban_mobile">
                            <field name="state" />
                            <field name="product_id" />
                            <field name="product_uom_qty" />
                            <field name="qty_done" />
                            <templates>
                                <t t-name="kanban-box">
                                    <div t-attf-class="oe_kanban_card">
                                        <div class="row">
                                            <div class="col-6">
                                                <strong>
                                                    <span>
                                                        <field name="product_id" />
                                                    </span>
                                                </strong>
                                            </div>
                                            <div class="col-2">
                                                <span
                                                    class="pull-right text-right text-muted"
                                                >
                                                    <field name="product_uom_qty" />
                                                </span>
                                            </div>
                                            <div class="col-2">
                                                <span
                                                    class="pull-right text-right"
                                                    t-att-class="qty_done >= product_uom_qty ? 'text-success' : ''"
                                                >
                                                    <field name="qty_done" />
                                                </span>
                                            </div>
                                            <div class="col-2 text-right">
                                                <button
                                                    name="fill_from_pending_line"
                                                    type="object"
                                                    class="btn"
                                                    context="{'wiz_barcode_id': parent.id}"
                                                >
                                                    <i
                                                        class="fa fa-upload"
                                                        title="Fill from pencil"
                                                        style="font-size:1.5em"
                                                    />
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </t>
                            </templates>
                        </kanban>
                    </field>
                </group>
                <group
                    string="Detailed operations"
                    attrs="{'invisible': ['|', ('move_line_ids', '=', []), ('show_detailed_operations', '=', False)]}"
                >
                    <field
                        name="move_line_ids"
                        options="{'no_open': True, 'always_reload': True}"
                        nolabel="1"
                        force_save="1"
                        colspan="2"
                        mode="tree,kanban"
                    >
                        <tree>
                            <field name="picking_code" invisible="1" />
                            <field name="product_id" options="{'no_open': True}" />
                            <field
                                name="location_id"
                                options="{'no_open': True}"
                                groups="stock.group_stock_multi_locations"
                                attrs="{'invisible': [('picking_code', '=', 'incoming')]}"
                                optional="show"
                            />
                            <field
                                name="location_dest_id"
                                options="{'no_open': True}"
                                groups="stock.group_stock_multi_locations"
                                attrs="{'invisible': [('picking_code', '=', 'outgoing')]}"
                                optional="show"
                            />
                            <field
                                name="lot_id"
                                groups="stock.group_production_lot"
                                options="{'no_open': True}"
                                optional="show"
                            />
                            <field
                                name="result_package_id"
                                groups="stock.group_tracking_lot"
                                options="{'no_open': True}"
                                optional="show"
                            />
                            <field name="qty_done" />
                            <field
                                name="product_uom_id"
                                groups="uom.group_uom"
                                options="{'no_open': True}"
                            />
                            <button
                                name="action_barcode_detailed_operation_unlink"
                                type="object"
                                class="btn"
                                icon="fa-trash"
                                context="{'wiz_barcode_id': parent.id}"
                            />
                        </tree>
                        <kanban class="o_kanban_mobile">
                            <field name="product_id" />
                            <field name="qty_done" />
                            <field name="product_uom_id" />
                            <templates>
                                <t t-name="kanban-box">
                                    <div t-attf-class="oe_kanban_card">
                                        <div class="row">
                                            <div class="col-7">
                                                <strong>
                                                    <span>
                                                        <field name="product_id" />
                                                    </span>
                                                </strong>
                                            </div>
                                            <div class="col-2">
                                                <span
                                                    class="pull-right text-right font-weight-bold"
                                                >
                                                    <field name="qty_done" />
                                                </span>
                                            </div>
                                            <div class="col-3 text-right">
                                                <button
                                                    name="action_barcode_detailed_operation_unlink"
                                                    type="object"
                                                    class="btn mt0"
                                                    context="{'wiz_barcode_id': parent.id}"
                                                >
                                                    <i
                                                        class="fa fa-trash"
                                                        title="Remove"
                                                        style="font-size:1.5em"
                                                    />
                                                </button>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-4">
                                                Lot: <field name="lot_id" />
                                            </div>
                                            <t
                                                t-if="record.result_package_id.raw_value"
                                            >
                                                <div class="col-4">
                                                    Package: <field
                                                        name="result_package_id"
                                                    />
                                                </div>
                                            </t>
                                        </div>
                                    </div>
                                </t>
                            </templates>
                        </kanban>
                    </field>
                </group>
            </group>
        </field>
    </record>
    <!--
     Open wizard in current target option to avoid that the wizard is
     closed after any button click,
    -->
    <record model="ir.actions.act_window" id="action_stock_barcodes_read_picking_batch">
        <field name="res_model">wiz.stock.barcodes.read.picking</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"}
        </field>
        <field name="view_id" ref="view_stock_barcodes_read_picking_batch_form" />
        <field name="target">current</field>
    </record>
</odoo>
