Commit f6e2b212 authored by Julien Muchembled's avatar Julien Muchembled

getAggregatedAmountList: example of implementation for support of 'rounding'

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@39857 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 41d58c16
......@@ -349,20 +349,21 @@ class AmountGeneratorMixin:
generated_amount_list = self.getGeneratedAmountList(
amount_list=amount_list, rounding=rounding,
amount_generator_type_list=amount_generator_type_list)
aggregated_amount_dict = {}
# XXX: Do we handle rounding correctly ?
# What to do if only total price is rounded ??
aggregate_dict = {}
result_list = AggregatedAmountList()
for amount in generated_amount_list:
key = (amount.getPrice(), amount.getEfficiency(),
amount.getReference(), amount.categories)
aggregated_amount = aggregated_amount_dict.get(key)
if aggregated_amount is None:
aggregated_amount_dict[key] = amount
aggregate = aggregate_dict.get(key)
if aggregate is None:
aggregate_dict[key] = [amount, amount.getQuantity()]
result_list.append(amount)
else:
# XXX How to aggregate rounded amounts ?
# What to do if the total price is rounded ??
assert not rounding, "TODO"
aggregated_amount.quantity += amount.quantity
aggregate[1] += amount.getQuantity()
for amount, quantity in aggregate_dict.itervalues():
amount._setQuantity(quantity)
if 0:
print 'getAggregatedAmountList(%r) -> (%s)' % (
self.getRelativeUrl(),
......
......@@ -36,7 +36,6 @@ import transaction
from Products.ERP5.tests.testBPMCore import TestBPMMixin
from Products.ERP5Type.Base import Base
from Products.ERP5Type.Utils import simple_decorator
from Products.ERP5Type.tests.backportUnittest import expectedFailure
from DateTime import DateTime
from Products.ERP5Type.tests.utils import createZODBPythonScript
......@@ -1093,7 +1092,7 @@ return lambda *args, **kw: 1""")
amount, = order.getAggregatedAmountList(rounding=False)
self.assertEqual(3333*0.05+171*0.05, amount.getTotalPrice()) # 175.2
# check the result with rounding
expectedFailure(order.getAggregatedAmountList)(rounding=True)
amount_list = order.getAggregatedAmountList(rounding=True)
self.assertEqual(2, len(amount_list)) # XXX 1 or 2 ???
self.assertEqual(174, getTotalAmount(amount_list))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment