This question has been flagged
2 Replies
3307 Views

@http.route('/tour/<model("tour.tour"):tour>/add-exist-passenger', type='http', auth='public', website=True)

def exist_passenger(self, tour, **kw):

passenger_id = int(kw.get('passenger_id', False))

passenger = http.request.env['tour.passenger'].search([('id', '=', passenger_id)])

tour.write({'passenger_ids': [(0, 0, passenger)]}) 

return http.request.redirect('/tour/')

From above this codes, i have tour.passenger_ids as Many2many field and i need to link new passenger called passenger from my total record. when i write to tour.passenger_ids it say me the error

'tour.passenger' object has no attribute 'pop'
Avatar
Discard
Best Answer

Hello Prabakaran,
I think you're trying to add a existing passenger to model "tour.tour". but your codes telling creating new passenger in model "tour.tour" like [(0, 0, passenger)] and also passenger is an recordset but  it should be a dict of values. Here is my suggestion

@http.route('/tour/<model("tour.tour"):tour>/add-exist-passenger', type='http', auth='public', website=True)
def exist_passenger(self, tour, **kw):
    passenger_id = int(kw.get('passenger_id', False))
    tour.write({'passenger_ids': [(4, passenger_id)]}) 
    return http.request.redirect('/tour/')
Avatar
Discard
Author

Great! it works...

Best Answer

Hi,

The issue is that here the passenger is not a dict, you have pass a dict of a values here,

 tour.write({'passenger_ids': [(0, 0, passenger)]}) 

uptd:

Thanks

Avatar
Discard