Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
4170 Visualizações

@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
Cancelar
Melhor resposta

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
Cancelar
Autor

Great! it works...

Melhor resposta

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
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
1
mai. 24
5893
1
fev. 23
12123
1
mar. 22
3749
2
mar. 21
4086
2
dez. 16
6942