Use defaultdict to compute cost and revenue total of project

Since e35820296f3a, sum_tree is use to compute project total but it requires
to have a default value for parents that are not in the list of instances.

Closes #12305
This commit is contained in:
Cédric Krier
2023-06-05 12:53:59 +02:00
parent 08639d8b9b
commit 0bffc1c384
+2 -2
View File
@@ -62,7 +62,7 @@ class Work(metaclass=PoolMeta):
transaction = Transaction()
cursor = transaction.connection.cursor()
costs = dict.fromkeys([w.id for w in works], 0)
costs = defaultdict(Decimal)
table = cls.__table__()
work = Work.__table__()
@@ -156,7 +156,7 @@ class Work(metaclass=PoolMeta):
@classmethod
def _get_revenue(cls, works):
revenues = dict.fromkeys(map(int, works), Decimal(0))
revenues = defaultdict(Decimal)
for work in works:
if not work.list_price:
continue