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
- Financeiro
- Inventário
- PoS
- Project
- MRP
Esta pergunta foi sinalizada
1
Responder
2095
Visualizações
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.
Está gostando da discussão? Não fique apenas lendo, participe!
Crie uma conta hoje mesmo para aproveitar os recursos exclusivos e interagir com nossa incrível comunidade!
Inscreva-se
.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.