<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <record id="vlm_task_action_form_view" model="ir.ui.view">
        <field name="model">stock.vlm.task.action</field>
        <field name="arch" type="xml">
            <form create="false" string="VLM Operation action needed">
                <field name="state" invisible="1" />
                <sheet>
                    <field name="next_vlm_task_id" invisible="1" />
                    <field name="previous_vlm_task_id" invisible="1" />
                    <field name="splitted_vlm_task_id" invisible="1" />
                    <widget
                        name="web_ribbon"
                        title="Done"
                        bg_color="bg-success"
                        attrs="{'invisible': [('state', '!=', 'done')]}"
                    />
                    <widget
                        name="web_ribbon"
                        title="Skipped"
                        bg_color="bg-warning"
                        attrs="{'invisible': [('state', '!=', 'skipped')]}"
                    />
                    <div
                        class="alert alert-warning"
                        role="alert"
                        attrs="{'invisible': [('warning', '=', False)]}"
                    >
                        <i class="fa fa-exclamation-triangle" />&amp;nbsp;
                        <field name="warning" />
                    </div>
                    <div
                        class="alert alert-info"
                        role="alert"
                        attrs="{'invisible': [('splitted_vlm_task_id', '=', False)]}"
                    >
                        <i class="fa fa-info-circle" />&amp;nbsp;Splitted from&amp;nbsp;
                        <field name="splitted_vlm_task_id" widget="selection" />
                    </div>
                    <div class="alert alert-info mb-0 h4" role="alert">
                        <button
                            name="action_command"
                            string="Start task"
                            type="object"
                            class="btn btn-primary btn-lg"
                            attrs="{'invisible': [('state', '=', 'done')]}"
                        />&amp;nbsp;
                        <i class="fa fa-info-circle" />&amp;nbsp;
                        <field name="vlm_task_id" readonly="1" widget="selection" />
                    </div>
                    <group>
                        <group name="quantity">
                            <field name="quantity_pending" />
                            <field
                                name="quantity_done"
                                attrs="{'readonly': [('state', '=', 'done')]}"
                            />
                        </group>
                        <group name="tray">
                            <field name="location_id" widget="selection" />
                            <field
                                name="tray_id"
                                domain="[('location_id', '=', location_id)]"
                                attrs="{'readonly': [('state', '=', 'done')]}"
                                widget="selection"
                            />
                            <field name="pos_x" invisible="1" force_save="1" />
                            <field name="pos_y" invisible="1" force_save="1" />
                        </group>
                    </group>
                    <group>
                        <group name="position" col="1">
                            <field
                                name="tray_matrix"
                                widget="location_tray_matrix"
                                options="{'live_cell_edit': True}"
                                nolabel="1"
                                attrs="{'readonly': [('state', '=', 'done')]}"
                            />
                        </group>
                        <group name="image">
                            <field
                                nolabel="1"
                                name="image_512"
                                widget="image"
                                class="vlm_task_image"
                            />
                        </group>
                    </group>
                    <footer>
                        <button
                            name="action_skip_task"
                            string="Skip"
                            type="object"
                            class="btn btn-secondary"
                            attrs="{'invisible': [('state', 'in', ['done','skipped'])]}"
                        />
                        <button
                            name="action_manual_set"
                            string="Manual set"
                            type="object"
                            class="btn btn-secondary"
                            attrs="{'invisible': [('state', '=', 'done')]}"
                        />
                        <!-- Navigation buttons -->
                        <button
                            name="action_previous_task"
                            string="🡸 Previous"
                            type="object"
                            class="btn btn-secondary"
                            attrs="{'invisible': [('previous_vlm_task_id', '=', False)]}"
                        />
                        <button
                            string="🡸 Previous"
                            disabled="1"
                            class="btn btn-secondary"
                            attrs="{'invisible': [('previous_vlm_task_id', '!=', False)]}"
                        />
                        <button
                            name="action_next_task"
                            string="Next 🡺"
                            type="object"
                            class="btn btn-primary"
                            attrs="{'invisible': ['|', ('next_vlm_task_id', '=', False), ('state', 'not in', ['done', 'skipped'])]}"
                        />
                        <button
                            name="action_next_task"
                            string="Next 🡺"
                            type="object"
                            class="btn btn-secondary"
                            attrs="{'invisible': ['|', ('next_vlm_task_id', '=', False), ('state', 'in', ['done', 'skipped'])]}"
                        />
                        <button
                            string="Next 🡺"
                            disabled="1"
                            class="btn btn-secondary"
                            attrs="{'invisible': ['|', ('next_vlm_task_id', '!=', False), ('state', '=', 'done')]}"
                        />
                    </footer>
                </sheet>
            </form>
        </field>
    </record>
    <record id="action_vlm_task_action" model="ir.actions.act_window">
        <field name="res_model">stock.vlm.task.action</field>
        <field name="name">VLM Operation Action</field>
        <field name="view_mode">form</field>
        <field name="context">{}</field>
        <field name="view_id" ref="vlm_task_action_form_view" />
        <field name="target">new</field>
    </record>
</odoo>
