In my code, I got this error:
File "/usr/lib/python3/dist-packages/odoo/http.py", line 315, in _handle_exception
raise exception.with_traceback(None) from new_cause
IndexError: tuple index out of range
When printing vals['partner_ids'], I got: [(4, 3)] Here is my code, what's wrong please?
class CalendarEvent(models.Model):
_inherit = 'calendar.event'
present_ids = fields.Many2many('res.partner', 'calendar_event_present_ids', 'calendar_id', 'present_id', string='Presents')
minutes = fields.Html(string='Minutes')
@api.model
def create(self, vals):
if vals.get('partner_ids', False):
_logger.info("%s", vals['partner_ids'])
vals.update({'present_ids': [(6, 0, vals.get('partner_ids')[0][2])]})
return super(CalendarEvent, self).create(vals)
Try this:
list_data = vals.get('partner_ids')[0][2]
blank_list = [ls for ls in list_data] # you'll get the list
or you can use loop to create list
blank_list = []
for l in list_data:
blank_list.append(l)
# then use [(6, _, ids)]
vals.update({'present_ids': [(6, 0, blank_list)]})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.