Cédric Krier pushed to branch branch/default at Tryton / Tryton
Commits:
bd90b075 by Cédric Krier at 2023-06-05T12:53:59+02:00
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
- - - - -
b3ba331b by Cédric Krier at 2023-06-05T12:55:00+02:00
Fill result for unknown parent in sum_tree
The parent of a record may not be in the list of instances computed.
- - - - -
2 changed files:
- modules/project_revenue/work.py
- trytond/trytond/model/tree.py
Changes:
=====================================
modules/project_revenue/work.py
=====================================
@@ -62,7 +62,7 @@
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 @@
@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
=====================================
trytond/trytond/model/tree.py
=====================================
@@ -160,7 +160,10 @@
records.remove(leaf)
parent = parents.get(leaf)
if parent:
- result[parent] += result[leaf]
+ try:
+ result[parent] += result[leaf]
+ except KeyError:
+ result[parent] = result[leaf]
next_leafs = set(records)
for record in records:
parent = parents.get(record)
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/compare/3e415fd7a9f23bb8182c164bae02fd6dd909e83c...b3ba331b59d8c2d3de593dda958dfb9940e45b37
--
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/compare/3e415fd7a9f23bb8182c164bae02fd6dd909e83c...b3ba331b59d8c2d3de593dda958dfb9940e45b37
You're receiving this email because of your account on foss.heptapod.net.