<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="view_stock_barcodes_read_picking_form" model="ir.ui.view">
        <field name="name">stock.barcodes.read.picking.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="arch" type="xml">
            <xpath expr="//button[@name='open_actions']" position="after">
                <button
                    name="action_open_picking"
                    type="object"
                    class="btn btn-primary"
                    data-hotkey="'shift+o'"
                >
                    <field name="picking_id" />
                </button>
                <t t-if="partner_id">
                    [<field
                        name="partner_id"
                        invisible="context.get('hide_partner', False)"
                    />]
                </t>
                <field name="candidate_picking_id" invisible="1" />

                <button
                    name="action_unlock_picking"
                    type="object"
                    title="unlock picking"
                    attrs="{'invisible': [('candidate_picking_id', '=', 'picking_id')]}"
                    class="float-end"
                >
                    <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>
                </button>
                <button
                    name="action_lock_picking"
                    type="object"
                    title="lock picking"
                    attrs="{'invisible': [('candidate_picking_id', '!=', 'picking_id')]}"
                    class="fa fa-thumb-tack fa-2x float-end"
                />
            </xpath>
            <xpath expr="//field[@name='message_type']" position="before">
                <field
                    name="candidate_picking_ids"
                    attrs="{'invisible': [('candidate_picking_ids', '=', [])]}"
                    mode="kanban"
                    nolabel="1"
                    force_save="1"
                    class="o_x2m_control_panel"
                    options="{'always_reload': True}"
                >
                    <kanban>
                        <field name="name" />
                        <field name="partner_id" />
                        <field name="date" />
                        <field name="state" />
                        <field name="picking_id" />
                        <field name="wiz_picking_id" />
                        <field name="product_qty_reserved" />
                        <field name="product_uom_qty" />
                        <field name="product_qty_done" />
                        <field name="scan_count" />
                        <field name="is_pending" />
                        <field name="note" />
                        <templates>
                            <t t-name="kanban-box">
                                <div
                                    t-if="!widget.isHtmlEmpty(record.note.raw_value)"
                                    t-att-class="'oe_kanban_color_alert' + (record.is_pending.raw_value == false ? ' bg-success' : '')"
                                >
                                    <div class="oe_kanban_details p-2">
                                        <field
                                            name="scan_count"
                                            invisible="1"
                                            force_save="1"
                                        />
                                        <div
                                            class="fw-bold text-center text-danger fst-italic"
                                        >
                                            <t
                                                t-out="record.note.value"
                                                invisible="context.get('hide_note', False)"
                                            />
                                        </div>
                                    </div>
                                </div>
                            </t>
                        </templates>
                    </kanban>
                </field>
                <field
                    name="todo_line_display_ids"
                    mode="kanban"
                    force_save="1"
                    attrs="{'invisible': [('todo_line_display_ids', '=', [])]}"
                />
            </xpath>
            <field name="location_id" position="before">
                <field name="picking_type_code" invisible="1" force_save="1" />
                <field name="picking_id" invisible="1" force_save="1" />
                <field name="show_detailed_operations" invisible="1" />
                <field name="picking_location_id" invisible="1" />
                <field name="picking_location_dest_id" invisible="1" />
                <field name="company_id" invisible="1" />
                <field name="todo_line_is_extra_line" invisible="1" />
                <field name="qty_available" invisible="1" />
            </field>
            <field name="location_id" position="attributes">
                <attribute
                    name="domain"
                >[('id', 'child_of', picking_location_id), '|', ('company_id', '=', False), ('company_id', '=',
                    company_id), ('usage', '!=', 'view')]
                </attribute>
            </field>
            <group name="location" position="attributes">
                <attribute
                    name="attrs"
                >{'readonly': [('manual_entry', '=', False)], 'invisible': [('picking_type_code', '=', 'incoming')]}
                </attribute>
            </group>
            <group name="location" position="after">
                <div attrs="{'invisible': [('picking_type_code', '=', 'outgoing')]}">
                    <strong class=" d-none d-sm-block">Dest. Location</strong>
                    <span
                        class="fa fa-2x fa-share text-center d-sm-none oe_span_small_icon"
                        title="Destination Location"
                    />
                    <field
                        name="location_dest_id"
                        options="{'no_create': True, 'no_open': True}"
                        attrs="{'readonly': [('manual_entry', '=', False)]}"
                        force_save="1"
                        nolabel="1"
                        style="width:90%"
                        class="h5"
                        domain="[('id', 'child_of', picking_location_dest_id), '|', ('company_id', '=', False), ('company_id', '=', company_id), ('usage', '!=', 'view')]"
                    />
                </div>
            </group>
            <group name="scan_fields" position="attributes">
                <!--  hide group scan_fields for extra todo lines -->
                <attribute
                    name="attrs"
                >{'invisible': [('todo_line_is_extra_line', '!=', False)]}
                </attribute>
            </group>
            <group name="scan_fields" position="after">
                <div
                    attrs="{'invisible': [('picking_state', '!=', 'done')]}"
                    class="oe_kanban_picking_done bg-dark d-flex flex-column justify-content-center align-items-center text-white"
                >
                    <span class="fa fa-6x mb-4 fa-exclamation-triangle" />
                    <span class="fa fa-2x fa-exclamation-triangle">
                        This picking is already done
                    </span>
                </div>
                <group
                    string="Pending moves"
                    attrs="{'invisible': ['|', ('picking_state', '=', 'done'), ('pending_move_ids', '=', [])]}"
                    col="2"
                >
                    <field
                        name="pending_move_ids"
                        options="{'no_open': True, 'always_reload': True}"
                        nolabel="1"
                        colspan="2"
                        force_save="1"
                        mode="kanban"
                    >
                        <kanban class="o_kanban_mobile">
                            <field name="id" />
                            <field name="state" />
                            <field name="product_id" />
                            <field name="product_uom_qty" />
                            <field name="qty_done" />
                            <field name="qty_done_rest" />
                            <field name="uom_id" />
                            <field name="product_qty_reserved" />
                            <field name="picking_state" />
                            <templates>
                                <t t-name="kanban-box">
                                    <div class="oe_kanban_global_click">
                                        <div class="row">
                                            <div class="col-8 col-md-8">
                                                <field name="product_id" class="h2" />
                                                <div
                                                    class="d-flex justify-content-start align-items-center indent h4 pt-3"
                                                >
                                                    <span
                                                        t-esc="record.qty_done.raw_value"
                                                    />
                                                    &#32;/&#32;
                                                    <span
                                                        t-esc="record.product_uom_qty.raw_value"
                                                    />

                                                    <span
                                                        t-if="record.uom_id"
                                                        t-esc="record.uom_id.value"
                                                    />
                                                </div>
                                            </div>
                                            <div
                                                class="col-4 col-md-4 d-flex justify-content-end align-items-center"
                                            >

                                                <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>
                                                <button
                                                    name="operation_quantities"
                                                    type="object"
                                                    class="btn btn-lg btn-primary btn-op-sum"
                                                    t-if="record.qty_done_rest.raw_value > 0"
                                                >
                                                    +
                                                    <span
                                                        class="text-white"
                                                        t-esc="record.qty_done_rest.raw_value"
                                                    />
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </t>
                            </templates>
                        </kanban>
                    </field>
                </group>
                <h3
                    class="mt-4 w-100 px-4"
                    attrs="{'invisible': ['|', ('move_line_ids', '=', []), ('show_detailed_operations', '=', False)]}"
                >
                    Detailed operations
                </h3>
                <group
                    string="Detailed operations"
                    col="2"
                    attrs="{'invisible': ['|', ('move_line_ids', '=', []), ('show_detailed_operations', '=', False)]}"
                >
                    <field
                        name="move_line_ids"
                        options="{'no_open': True, 'always_reload': True}"
                        nolabel="1"
                        colspan="2"
                        force_save="1"
                        mode="kanban"
                    >
                        <kanban class="o_kanban_mobile">
                            <field name="product_id" />
                            <field name="qty_done" />
                            <field name="product_uom_id" />
                            <field name="lot_id" />
                            <field name="result_package_id" />
                            <templates>
                                <t t-name="kanban-box">
                                    <div class="oe_kanban_global_click">
                                        <div class="row">
                                            <div class="col-8 col-md-8">
                                                <field name="product_id" class="h2" />
                                                <div
                                                    class="d-flex justify-content-start align-items-center indent h4 pt-3"
                                                >
                                                    <t t-if="record.lot_id.raw_value">
                                                        Lot:
                                                        <span
                                                            t-esc="record.lot_id.raw_value"
                                                        />
                                                    </t>
                                                    <t
                                                        t-if="record.result_package_id.raw_value"
                                                    >
                                                        Package:
                                                        <span
                                                            t-esc="record.result_package_id.raw_value"
                                                        />
                                                    </t>
                                                </div>
                                            </div>
                                            <div
                                                class="col-4 col-md-4 d-flex justify-content-end align-items-center"
                                            >
                                                <span
                                                    class="h3"
                                                    t-esc="record.qty_done.raw_value"
                                                />

                                                <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"
                                                    />
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </t>
                            </templates>
                        </kanban>
                    </field>
                </group>
            </group>
            <xpath expr="//button[@id='btn_create_lot']" position="after">
                <field name="display_assign_serial" invisible="1" />
                <button
                    name="action_assign_serial"
                    type="object"
                    string="Range"
                    title="Assign Serial Numbers"
                    attrs="{'invisible': [('display_assign_serial', '=', False)]}"
                    class="btn btn-secondary btn-sm"
                />
            </xpath>
            <xpath expr="//button[@name='action_clean_values']" position="before">
                <field name="picking_state" invisible="1" />
                <button
                    name="action_put_in_pack"
                    help="Put in pack"
                    type="object"
                    icon="fa-cube fa-2x"
                    title="Put in Pack"
                    attrs="{'invisible': ['|', ('picking_state', 'in', ('draft', 'done', 'cancel')), ('display_menu', '=', True)]}"
                    class="btn btn-secondary w-100 oe_kanban_action_button btn-sm text-uppercase
                    d-flex justify-content-center align-items-center fs-2"
                    groups="stock.group_tracking_lot"
                    data-hotkey="6"
                >
                    <span class="d-none d-lg-block">Put in back</span>
                </button>
                <!--                t-att-class="'btn float-end' + (record.is_pending.raw_value == false ? ' btn-primary' : ' btn-secondary border')"-->
                <button
                    name="action_validate_picking"
                    type="object"
                    icon="fa-check fa-2x"
                    class="btn btn-secondary w-100 oe_kanban_action_button btn-sm text-uppercase
                    d-flex justify-content-center align-items-center fs-2"
                    attrs="{'invisible': [('picking_state', 'not in', ['draft', 'assigned', 'confirmed'])]}"
                    confirm="Are you sure to validate the picking ?"
                    data-hotkey="'shift+v'"
                >
                    <span class="d-none d-lg-block">Validate</span>
                </button>
            </xpath>
            <xpath
                expr="//div[hasclass('oe_stock_barcodes_bottombar')]//div[hasclass('dropup')]"
                position="inside"
            >
                <field
                    name="show_detailed_operations"
                    widget="barcode_boolean_toggle"
                    class="d-none"
                />
                <button
                    name="action_show_detailed_operations"
                    type="object"
                    title="Detailed operations"
                    icon="fa-eye fa-2x"
                    attrs="{'invisible': ['|', ('move_line_ids', '=', []), ('show_detailed_operations', '=', True)]}"
                />

                <button
                    name="action_show_detailed_operations"
                    type="object"
                    title="Detailed operations"
                    icon="fa-eye-slash fa-2x"
                    attrs="{'invisible': ['|', ('move_line_ids', '=', []), ('show_detailed_operations', '=', False)]}"
                />
            </xpath>
        </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">
        <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_form" />
        <field name="target">fullscreen</field>
    </record>
    <record model="ir.actions.act_window" id="action_stock_barcodes_menu">
        <field name="res_model">wiz.stock.barcodes.read.picking</field>
        <field name="name">Barcodes menu</field>
        <field name="view_mode">form</field>
        <field
            name="context"
        >{'control_panel_hidden': True, "default_display_menu": True}
        </field>
        <field name="view_id" ref="view_stock_barcodes_read_picking_form" />
        <field name="target">current</field>
    </record>
</odoo>
