While double clicking the button function (V7), it performs operation twice. How to restrict the same using job queues.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
1
Trả lời
2069
Lượt xem
you should make the situation as done by using a boolean field or checking other data sources. so whenever you click on button can validate if the operation is already done or not.
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng ký
.py
_defaults = {
'flag_ref': False,
}
def processfn(cr,uid,ids,contex=None):
rec = self.browse(cr,uid,ids[0])
a_obj = self.pool.get('hr.employee')
a_ids = a_obj.search(cr,uid, [('ref_id','=',rec.id)])
if not a_ids and rec.flag_ref == False:
for line in rec.line_ids:
vals = {
'name':rec.emp_name,
'ref_id':rec.id
....
....
}
hr_id = a_obj.create(cr,uid,vals)
self.write(cr,uid,ids[0],{'flag_ref':True})
else:
pass
return True
.xml
<button name="processfn" string="Process" attrs="{'invisible': [('flag_ref', '=', True)]}"/>
sample .log
For every click (fraction of seconds difference), a process will be initiated which results in running of parallel process (p1,p2) for same operation (p).
Expected : With reference to above code, for every records in child table an equivalent entry to be created in hr_employee table.
Unexpected : Due to double click (fraction of seconds difference), entries are created twice in hr_employee table.
Reason : Before enabling the flag_ref true, a parallel process was initiated which makes the whole function mess.
So, I need a solution to enqueue the process in order to overcome unexpected result.