Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
6246 Lượt xem

I have created a button in the module, i want users to be registered using the button. I have used self.ensure_one (), but it does not seem to be working (Users are able to register multiple times using the button, the same record is being generated multiple times). Here is the code for that, Please let me know the correction.

@ api.multi 
def action_generate_event_registration (self, event): 
"" "Generate an event registration." "" 
self.ensure_one () 
partner_id = event.pop ('partner_id', self.env.user.partner_id) 
er = self. env ["event.registration"] 
for s in self: 
s.event_registration_id = er.create ({
"event_id": s.id,
"partner_id": partner_id.id, 
"name": event.get ('name', partner_id.name), 
"email": event.get ('email', partner_id.email), 
"phone": event.get ('phone', partner_id.phone)
})        ​
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất


self.ensure_one ()  ensures that theres only one record in recordset
Ảnh đại diện
Huỷ bỏ

in self u have only one record set from that buttons model of current record

use different logic

please check the documentation for ensure one

https://www.odoo.com/documentation/8.0/reference/orm.html

Really helpful !!!

Thanks

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 9 21
5768
0
thg 11 19
3423
0
thg 8 19
3716
7
thg 8 20
36057
0
thg 12 19
2746