Automatic allocations generation fixed

This commit is contained in:
Jared Esparza 2020-06-26 14:09:51 +02:00
parent 1bd8fcd14c
commit 730e8e5908
1 changed files with 11 additions and 11 deletions

22
role.py
View File

@ -72,6 +72,7 @@ class Work(metaclass=PoolMeta):
def on_change_tracker(self):
pool = Pool()
Allocation = pool.get('project.allocation')
Configuration = Pool().get('work.configuration')
# try except needed cause super doesn't have on_change_tracker
# but it could have it in the future
try:
@ -81,18 +82,17 @@ class Work(metaclass=PoolMeta):
if not self.tracker or not self.tracker.workflow:
return
allocations = []
existing_roles = {x.role for x in self.allocations if x.role}
for line in self.tracker.workflow.lines:
for alocation in self.allocations:
if alocation.role.id == line.phase.role.id:
break
else:
Configuration = Pool().get('work.configuration')
allocation = Allocation()
allocation.role = line.phase.role
allocation.employee = (
Configuration(1).default_allocation_employee)
allocation.percentage = 100.0
allocations.append(allocation)
role = line.phase.role
if not role or role in existing_roles:
continue
existing_roles.add(role)
allocation = Allocation()
allocation.role = role
allocation.employee = Configuration(1).default_allocation_employee
allocation.percentage = 100.0
allocations.append(allocation)
self.allocations += tuple(allocations)