Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
4172 Visualizzazioni

@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
Abbandona
Risposta migliore

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
Abbandona
Autore

Great! it works...

Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
mag 24
5893
1
feb 23
12123
1
mar 22
3749
2
mar 21
4086
2
dic 16
6942