在我的代码中,我得到了这个错误:
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
打印vals['partner_ids']时,我得到了:[(4,3(]这是我的密码,请问怎么了?
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)
试试这个:
list_data = vals.get('partner_ids')[0][2]
blank_list = [ls for ls in list_data] # you'll get the list
或者您可以使用循环创建列表
blank_list = []
for l in list_data:
blank_list.append(l)
# then use [(6, _, ids)]
vals.update({'present_ids': [(6, 0, blank_list)]})