跳至內容
選單
此問題已被標幟
2 回覆
4189 瀏覽次數

@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'
頭像
捨棄
最佳答案

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/')
頭像
捨棄
作者

Great! it works...

最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
5月 24
5920
1
2月 23
12130
1
3月 22
3779
2
3月 21
4101
2
12月 16
6961