Skip to Content
Menu
This question has been flagged
1 Reply
2710 Views

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
Discard
Best Answer

Hi

do you find any solution

i need Some Help can you help me ?

Avatar
Discard

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

Related Posts Replies Views Activity
0
Dec 20
50
0
Dec 15
12183
2
Aug 24
5004
1
Oct 22
22088
2
Sep 21
11227