From 0bffc1c38466227f4deff424e21520e529cfefed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 5 Jun 2023 12:53:59 +0200 Subject: [PATCH] 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 --- modules/project_revenue/work.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/project_revenue/work.py b/modules/project_revenue/work.py index 644917f3eb..5f0220de9a 100644 --- a/modules/project_revenue/work.py +++ b/modules/project_revenue/work.py @@ -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