Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
3589 Vues

I got this function in python :

def picking_lot_scanned(self, barcode):
        self.ensure_one()

        picking_id = self.env['stock.picking'].browse(self.id)
        if picking_id.state in ['draft']:
            lot_id = self.env['stock.production.lot'].search([('name','=',str(barcode))], limit=1)

            if not lot_id:
                raise ValidationError("Le lot/numéro de série {} n'existe pas.".format(barcode))

            if lot_id:
                product_id = lot_id.product_id

                action = self.env.ref('elosys_picking_lot_scanner.action_lot_scanned_qty_wizard').read()[0]
                action['context'] = {
                    'default_picking_id': picking_id.id,
                    'default_product_id': product_id.id,
                }
                return action
        return False

it returns an action of wizard view ,now i want to call this action in a js function , i tried doing this :

odoo.define('ndjma_picking_camera.Nedjma', function(require) {
    "use strict";
$(document).ready(function(){
    let selectedDeviceId;
    var rpc = require('web.rpc');
    var core = require('web.core');
    
    function decodeOnce(codeReader, selectedDeviceId) {
        
        var self = this;

        codeReader.decodeFromInputVideoDevice(selectedDeviceId, 'video').then((result) => {
            
            var url = window.location.href;
            url = url.match(new RegExp('id=' + "(.*)" + '&'));
            url = String(url);
            var start_pos = url.indexOf('=') + 1;
            var end_pos = url.indexOf('&', start_pos);
            var id = url.substring(start_pos, end_pos);

            $('input[name="sh_invoice_barcode_mobile"]').val(result.text);
            $('input[name="sh_invoice_barcode_mobile"]').change();

            var barcode = result.text;
            alert(result.text);

            var res = rpc.query({
                model: 'stock.picking',
                method: 'picking_lot_scanned',
                args: [parseInt(id), barcode],
            }).then(function(result) {
                    if (result) {
                        self.do_action(result, {
                            on_close: function () {
                                self.trigger_up('reload');
                            }
                        });
                    }
                });

.......

and i keep getting error self in undefined ,i can't find another solution to this problem Any idea of what could be the problem!


Avatar
Ignorer
Meilleure réponse

Hi

do you find any solution

i need Some Help can you help me ?

Avatar
Ignorer

Hi, is the error coming from .js file of from .py file?

Publications associées Réponses Vues Activité
0
déc. 20
50
0
déc. 15
13171
2
août 24
6376
1
oct. 22
24119
2
sept. 21
12802