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

While double clicking the button function (V7), it performs operation twice. How to restrict the same using job queues.

Ảnh đại diện
Huỷ bỏ
Tác giả

.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.

Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ