Commit 429960e5 authored by Julien Muchembled's avatar Julien Muchembled

Amount Generator: make lines sortable with float indices

parent 9623656d
...@@ -205,15 +205,20 @@ class AmountGeneratorMixin: ...@@ -205,15 +205,20 @@ class AmountGeneratorMixin:
base_amount_list = (BaseAmountDict(*args).__of__(amount) base_amount_list = (BaseAmountDict(*args).__of__(amount)
for amount in amount_list) for amount in amount_list)
# First define the method that will browse recursively def getLineSortKey(line):
# the amount generator lines and accumulate applicable values int_index = line.getIntIndex()
return (line.getFloatIndex() if int_index is None else int_index,
random.random())
def accumulateAmountList(self): def accumulateAmountList(self):
"""Browse recursively the amount generator lines
and accumulate applicable values
"""
amount_generator_line_list = self.contentValues( amount_generator_line_list = self.contentValues(
portal_type=amount_generator_line_type_list) portal_type=amount_generator_line_type_list)
# Recursively feed base_amount # Recursively feed base_amount
if amount_generator_line_list: if amount_generator_line_list:
amount_generator_line_list.sort(key=lambda x: (x.getIntIndex(), amount_generator_line_list.sort(key=getLineSortKey)
random.random()))
for amount_generator_line in amount_generator_line_list: for amount_generator_line in amount_generator_line_list:
accumulateAmountList(amount_generator_line) accumulateAmountList(amount_generator_line)
return return
...@@ -366,8 +371,6 @@ class AmountGeneratorMixin: ...@@ -366,8 +371,6 @@ class AmountGeneratorMixin:
delivery_amount = base_amount.getObject() delivery_amount = base_amount.getObject()
if not is_mapped_value: if not is_mapped_value:
self = delivery_amount.asComposedDocument(amount_generator_type_list) self = delivery_amount.asComposedDocument(amount_generator_type_list)
# Browse recursively the amount generator lines and accumulate
# applicable values - now execute the method
accumulateAmountList(self) accumulateAmountList(self)
return result return result
......
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