Commit dd10a334 authored by Julien Muchembled's avatar Julien Muchembled

Amount Generator: automatic sort based on application/contribution dependencies [1/2]

Preliminary commit only to indent a big section of code.
parent 10be013b
...@@ -237,75 +237,76 @@ class AmountGeneratorMixin: ...@@ -237,75 +237,76 @@ class AmountGeneratorMixin:
"""Browse recursively the amount generator lines """Browse recursively the amount generator lines
and accumulate applicable values and accumulate applicable values
""" """
amount_generator_line_list = self.contentValues( if 1:
portal_type=amount_generator_line_type_list) amount_generator_line_list = self.contentValues(
# Recursively feed base_amount portal_type=amount_generator_line_type_list)
if amount_generator_line_list: # Recursively feed base_amount
amount_generator_line_list.sort(key=getLineSortKey) if amount_generator_line_list:
for amount_generator_line in amount_generator_line_list: amount_generator_line_list.sort(key=getLineSortKey)
accumulateAmountList(amount_generator_line) for amount_generator_line in amount_generator_line_list:
return accumulateAmountList(amount_generator_line)
elif (self.getPortalType() not in amount_generator_line_type_list):
return
target_method = self.isTargetDelivery() and 'isDelivery' or default_target
if target_method and not getattr(delivery_amount, target_method)():
return
if not self.test(delivery_amount):
return
self = self.asPredicate()
reference = self.getReference()
if reference:
if reference in reference_set:
return return
reference_set.add(reference) elif (self.getPortalType() not in amount_generator_line_type_list):
# Try to collect cells and aggregate their mapped properties return
# using resource + variation as aggregation key or base_application target_method = self.isTargetDelivery() and 'isDelivery' or default_target
# for intermediate lines. if target_method and not getattr(delivery_amount, target_method)():
amount_generator_cell_list = [self] + self.contentValues( return
portal_type=amount_generator_cell_type_list) if not self.test(delivery_amount):
cell_aggregate = {} # aggregates final line information return
self = self.asPredicate()
base_application_list = self.getBaseApplicationList() reference = self.getReference()
base_contribution_list = self.getBaseContributionList() if reference:
for cell in amount_generator_cell_list: if reference in reference_set:
if cell is not self: return
if not cell.test(delivery_amount): reference_set.add(reference)
continue # Try to collect cells and aggregate their mapped properties
cell = cell.asPredicate() # using resource + variation as aggregation key or base_application
key = cell.getCellAggregateKey() # for intermediate lines.
try: amount_generator_cell_list = [self] + self.contentValues(
property_dict = cell_aggregate[key] portal_type=amount_generator_cell_type_list)
except KeyError: cell_aggregate = {} # aggregates final line information
cell_aggregate[key] = property_dict = {
'base_application_set': set(base_application_list), base_application_list = self.getBaseApplicationList()
'base_contribution_set': set(base_contribution_list), base_contribution_list = self.getBaseContributionList()
'category_list': [], for cell in amount_generator_cell_list:
'causality_value_list': [], if cell is not self:
'efficiency': self.getEfficiency(), if not cell.test(delivery_amount):
'quantity_unit': self.getQuantityUnit(), continue
# XXX If they are several cells, we have duplicate references. cell = cell.asPredicate()
'reference': reference, key = cell.getCellAggregateKey()
} try:
# Then collect the mapped values (quantity, price, trade_phase...) property_dict = cell_aggregate[key]
for key in cell.getMappedValuePropertyList(): except KeyError:
if key in ('net_converted_quantity', cell_aggregate[key] = property_dict = {
'net_quantity', 'converted_quantity'): 'base_application_set': set(base_application_list),
# XXX only 'quantity' is accepted and it is treated 'base_contribution_set': set(base_contribution_list),
# as if it was 'converted_quantity' 'category_list': [],
raise NotImplementedError 'causality_value_list': [],
# XXX-JPS Make sure handling of list properties can be handled 'efficiency': self.getEfficiency(),
property_dict[key] = cell.getProperty(key) 'quantity_unit': self.getQuantityUnit(),
category_list = cell.getAcquiredCategoryMembershipList( # XXX If they are several cells, we have duplicate references.
cell.getMappedValueBaseCategoryList(), base=1) 'reference': reference,
property_dict['category_list'] += category_list }
property_dict['resource'] = cell.getResource() # Then collect the mapped values (quantity, price, trade_phase...)
if cell is not self: for key in cell.getMappedValuePropertyList():
# cells inherit base_application and base_contribution from line if key in ('net_converted_quantity',
property_dict['base_application_set'].update( 'net_quantity', 'converted_quantity'):
cell.getBaseApplicationList()) # XXX only 'quantity' is accepted and it is treated
property_dict['base_contribution_set'].update( # as if it was 'converted_quantity'
cell.getBaseContributionList()) raise NotImplementedError
property_dict['causality_value_list'].append(cell) # XXX-JPS Make sure handling of list properties can be handled
property_dict[key] = cell.getProperty(key)
category_list = cell.getAcquiredCategoryMembershipList(
cell.getMappedValueBaseCategoryList(), base=1)
property_dict['category_list'] += category_list
property_dict['resource'] = cell.getResource()
if cell is not self:
# cells inherit base_application and base_contribution from line
property_dict['base_application_set'].update(
cell.getBaseApplicationList())
property_dict['base_contribution_set'].update(
cell.getBaseContributionList())
property_dict['causality_value_list'].append(cell)
base_amount.setAmountGeneratorLine(self) base_amount.setAmountGeneratorLine(self)
for property_dict in cell_aggregate.itervalues(): for property_dict in cell_aggregate.itervalues():
......
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