[FIX] hr_work_entry_contract: Fix work entry generation cron
Purpose ======= The cron is breaking (expected singleton error) if treating contracts from the same company at the same time. Actually, this shouldn't be done that way to avoid mixing unrelated resource.calendar.leave. Handle the contracts over 2 cron execution instead.
This commit is contained in:
committed by
Rob Coekaerts
parent
0a0ea0336b
commit
c78bfc1463
@@ -388,6 +388,12 @@ class HrContract(models.Model):
|
||||
(not c.last_generation_date or c.last_generation_date < today))
|
||||
if not contracts_todo:
|
||||
return
|
||||
countract_todo_count = len(contracts_todo)
|
||||
# Filter contracts by company, work entries generation is not supposed to be called on
|
||||
# contracts from differents companies, as we will retrieve the resource.calendar.leave
|
||||
# and we don't want to mix everything up. The other contracts will be treated when the
|
||||
# cron is re-triggered
|
||||
contracts_todo = contracts_todo.filtered(lambda c: c.company_id == contracts_todo[0].company_id)
|
||||
# generate a batch of work entries
|
||||
BATCH_SIZE = 100
|
||||
# Since attendance based are more volatile for their work entries generation
|
||||
@@ -398,5 +404,5 @@ class HrContract(models.Model):
|
||||
contracts_todo = contracts_todo.sorted(key=lambda c: 1 if c.has_static_work_entries() else 100)
|
||||
contracts_todo[:BATCH_SIZE]._generate_work_entries(start, stop, False)
|
||||
# if necessary, retrigger the cron to generate more work entries
|
||||
if len(contracts_todo) > BATCH_SIZE:
|
||||
if countract_todo_count > BATCH_SIZE:
|
||||
self.env.ref('hr_work_entry_contract.ir_cron_generate_missing_work_entries')._trigger()
|
||||
|
||||
Reference in New Issue
Block a user