تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
5473 أدوات العرض

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


الصورة الرمزية
إهمال
أفضل إجابة

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

   

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أبريل 22
9275
2
أكتوبر 21
8549
1
يوليو 21
22381
6
أغسطس 20
5309
1
سبتمبر 19
2816