"config/dependency_decisions.yml" did not exist on "3c3234121575ce271f8b50f3dcf1880db328fed1"
Commit a6b1b63f authored by Julien Muchembled's avatar Julien Muchembled

amount_generator: revert last change in testApparelTransformation

parents 1abc4bac 5b3055d8
......@@ -39,7 +39,7 @@ from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.Utils import deprecated
from Products.ERP5.mixin.composition import _getEffectiveModel
from Products.ERP5.Document.Transformation import Transformation
from Products.ERP5.AggregatedAmountList import AggregatedAmountList
from Products.ERP5.GeneratedAmountList import GeneratedAmountList
from Products.ERP5.Document.MappedValue import MappedValue
from Products.ERP5.mixin.amount_generator import AmountGeneratorMixin
from Products.ERP5.mixin.variated import VariatedMixin
......
......@@ -31,7 +31,7 @@ import zope.interface
from AccessControl import allow_class
from Products.ERP5Type import interfaces
class AggregatedAmountList(list):
class GeneratedAmountList(list):
"""
Temporary object needed to aggregate Amount value
And to calculate some report or total value
......@@ -60,4 +60,25 @@ class AggregatedAmountList(list):
result += duration
return result
allow_class(AggregatedAmountList)
def aggregate(self):
# XXX: Do we handle rounding correctly ?
# What to do if only total price is rounded ??
aggregate_dict = {}
result_list = self.__class__()
for amount in self:
key = (amount.getPrice(), amount.getEfficiency(),
amount.getReference(), amount.categories)
aggregate = aggregate_dict.get(key)
if aggregate is None:
aggregate_dict[key] = [amount, amount.getQuantity()]
result_list.append(amount)
else:
aggregate[1] += amount.getQuantity()
for amount, quantity in aggregate_dict.itervalues():
# Before we ignore 'quantity==0' amount here for better performance,
# but it is not a good idea, especially when the first expand causes
# non-zero quantity and then quantity becomes zero.
amount._setQuantity(quantity)
return result_list
allow_class(GeneratedAmountList)
......@@ -32,7 +32,7 @@ import zope.interface
from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass
from Acquisition import aq_base, Implicit
from Products.ERP5.AggregatedAmountList import AggregatedAmountList
from Products.ERP5.GeneratedAmountList import GeneratedAmountList
from Products.ERP5Type import Permissions, interfaces
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5.Document.MappedValue import MappedValue
......@@ -281,7 +281,7 @@ class AmountGeneratorMixin:
portal.getPortalAmountGeneratorCellTypeList()
# Set empty result by default
result = AggregatedAmountList()
result = GeneratedAmountList()
args = (getTransactionalVariable().setdefault(
"amount_generator.BaseAmountDict", {}),
......@@ -503,42 +503,12 @@ class AmountGeneratorMixin:
security.declareProtected(Permissions.AccessContentsInformation,
'getAggregatedAmountList')
def getAggregatedAmountList(self, amount_list=None, rounding=False,
amount_generator_type_list=None,
generate_empty_amounts=True):
def getAggregatedAmountList(self, *args, **kw):
"""
Implementation of a generic transformation algorith which is
applicable to payroll, tax generation and BOMs. Return the
list of amounts with aggregation.
"""
generated_amount_list = self.getGeneratedAmountList(
amount_list=amount_list, rounding=rounding,
amount_generator_type_list=amount_generator_type_list)
# 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)
aggregate = aggregate_dict.get(key)
if aggregate is None:
aggregate_dict[key] = [amount, amount.getQuantity()]
result_list.append(amount)
else:
aggregate[1] += amount.getQuantity()
for amount, quantity in aggregate_dict.itervalues():
# Before we ignore 'quantity==0' amount here for better
# performance, but it is not a good idea, especially when the
# first expand causes non-zero quantity and then quantity
# becomes zero.
amount._setQuantity(quantity)
if 0:
print 'getAggregatedAmountList(%r) -> (%s)' % (
self.getRelativeUrl(),
', '.join('(%s, %s, %s)'
% (x.getResourceTitle(), x.getQuantity(), x.getPrice())
for x in result_list))
return result_list
return self.getGeneratedAmountList(*args, **kw).aggregate()
InitializeClass(AmountGeneratorMixin)
......@@ -55,7 +55,7 @@ implements_tuple_list = [
(('Products.ERP5.Document.EmailDocument', 'EmailDocument'), 'IDocument'),
(('Products.ERP5.Document.Event', 'Event'), 'IDocument'),
# IAmountList
(('Products.ERP5.AggregatedAmountList', 'AggregatedAmountList'), 'IAmountList'),
(('Products.ERP5.GeneratedAmountList', 'GeneratedAmountList'), 'IAmountList'),
]
# IMovementGroup
for movement_group_class_name in ['MovementGroup', 'BaseVariantMovementGroup',
......
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