Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
629 Zobrazení

Hola comunidad
Estoy personalizando la vista de código de barras para las transferencias internas (stock.picking) en Odoo 17, y necesito que, al hacer clic en un botón personalizado llamado "Recibir", se cierre automáticamente la transferencia y se muestre un mensaje de confirmación.

Quiero lograr el mismo comportamiento que ocurre cuando uno valida una orden desde la vista de código de barras: se cierra la vista de escaneo y se redirige a la vista kanban, mostrando un mensaje de éxito.

Actualmente el botón "Recibir" que implementé funciona y muestra el mensaje de éxito, pero no me redirige ni me saca de la vista de escaneo. Estoy usando: this.trigger('history-back');
Mi duda es 

¿Es this.trigger('history-back') la forma correcta de cerrar la vista de escaneo desde código?

¿O existe otro método o evento específico que Odoo utilice para salir correctamente de la vista de escaneo hacia la vista kanban después de validar o completar una operación?

Agradezco mucho cualquier orientación o ejemplo que puedan brindarme.

¡Gracias que pena!

 Este es el XML donde agrego los botones en la interfaz:

<?xml version="1.0" encoding="UTF-8"?>

<templates xml:space="preserve">

    <t t-inherit="stock_barcode.MainComponent" t-inherit-mode="extension" owl="1">       

        <xpath expr="//div[hasclass('o_barcode_lines_header')]" position="inside">

            <div class="oe_button_box mt-2">

                <!-- Botón "En Tránsito" -->

                <button t-on-click="button_dispatch"

                        t-att-class="{'btn btn-primary': true, 'd-none': !state.visibleTransitButton}"

                        type="button">

                    En Tránsito

                </button>

               

                <!-- Botón "Recibir" -->

                <button t-on-click="button_receive"

                        t-att-class="{'btn btn-success': true, 'd-none': state.currentState !== 'transit'}"

                        type="button">

                    Recibir

                </button>

            </div>     

        </xpath>

    </t>

</templates>

Y este es el archivo JS 
/** @odoo-module **/


import MainComponent from "@stock_barcode/components/main";

import { patch } from "@web/core/utils/patch";

import { useService } from "@web/core/utils/hooks";


patch(MainComponent.prototype, {

    setup() {

        super.setup();

        this.loadPickingData();

        this.notification = useService('notification');

    },


    async loadPickingData() {

        const [record] = await this.orm.read('stock.picking', [this.resId], ['visible_transit_button', 'state']);

        this.state.visibleTransitButton = record.visible_transit_button;

        this.state.currentState = record.state;

    },


    async button_dispatch() {

        try {

            await this.orm.call('stock.picking', 'button_dispatch', [[this.resId]]);

            await this.loadPickingData();

            this.notification.add("El proceso ha iniciado su fase de tránsito.", { type: 'success' });

        } catch (error) {

            this.notification.add(error.message, { type: 'danger' });

        }

    },


    async button_receive() {

        try {

            await this.orm.call('stock.picking', 'button_receive', [[this.resId]]);

            await this.loadPickingData();

            this.notification.add("El proceso ha sido recibido y cerrado exitosamente.", { type: "success" });


            // Aquí intento cerrar la vista de código de barras

            this.trigger('history-back');


        } catch (error) {

            this.notification.add(error.message, { type: 'danger' });

        }

    },

});



Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
čvc 25
5679
0
čvc 25
1308
0
čvn 25
1244
1
čvn 25
1321
1
čvn 25
1324