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:
- 客户关系管理
- e-Commerce
- 会计
- 库存
- PoS
- Project
- MRP
此问题已终结
1
回复
2065
查看
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.
.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.