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

PY code

    def js_positions(self):
        vehicle_obj                             =self.env['fleet.vehicle']       
        vehicle_args                            =[]       
        return_positions                        ={}
        vehicle_data                            =vehicle_obj.search(vehicle_args, offset=0, limit=None, order=None)       
        if len(vehicle_data)>0:        
            for vehicle in vehicle_data:
                positions_arg                   =[]               
                positions_data                  =self.search_read(positions_arg, offset=0, limit=1, order='devicetime DESC')       
                if len(positions_data)>0:
                    return_positions[vehicle.id]    =positions_data[0]           
        return return_positions



JS Code

    rpc.query({
        model: 'MYMODEL',
        method: 'js_positions',
        fields: ['deviceid','devicetime'],
        limit:  10,        
    })
    .then(function (result)
    {     
        //console.log("Device  " + result);                   
    });



Odoo v11 Error

File "/usr/lib/python3/dist-packages/odoo/api.py", line 699, in call_kw return call_kw_multi(method, model, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 686, in call_kw_multi ids, args = args[0], args[1:]
IndexError: list index out of range


Avatar
Discard
Best Answer

Hello,


Please follow the below code hope this might help you...

The error is coming in your code from this line - 'return_positions[vehicle.id] = positions_data[0]' because here we have get the record set in position_data variable and you had pass the data in list format i.e list[].


def js_positions(self):    

        

        positions_arg = []

        vehicle_data = self.env['fleet.vehicle'].search([])

        if vehicle_data:        

            for vehicle in vehicle_data:

                positions_data  = self.search_read([], offset=0, limit=1, order='devicetime DESC')

                if positions_data:

                    positions_arg.append(positions_data)       

        return_positions = {name: record.name for record in positions_arg if record}


        return return_positions

Regards,




Email:   odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

Avatar
Discard
Related Posts Replies Views Activity
1
Apr 22
8063
2
Oct 21
7023
1
Jul 21
18893
6
Aug 20
4309
1
Sep 19
1758