diff --git a/product/ERP5/mixin/amount_generator.py b/product/ERP5/mixin/amount_generator.py index 4fbacb9a3208c1cddb3023724d1bbbd0e246e569..3fd289edb3071d1727278e56e3732cfcd30fcc8c 100644 --- a/product/ERP5/mixin/amount_generator.py +++ b/product/ERP5/mixin/amount_generator.py @@ -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(), diff --git a/product/ERP5/tests/testTradeModelLine.py b/product/ERP5/tests/testTradeModelLine.py index fee187b4d7fa32a72530d1ad7449fe3599aa0ad1..c8ee0a5264dd18017fac86168877c0a020eefcbd 100644 --- a/product/ERP5/tests/testTradeModelLine.py +++ b/product/ERP5/tests/testTradeModelLine.py @@ -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))