Commit 68ec6bda authored by Julien Muchembled's avatar Julien Muchembled

Amount Generator: make first matching line mask other with same reference

This is implemented by first changing Composition so that a model can
define several lines with same reference, masking inherited ones.

There is actually no compatibility issue, because previously, the result would
have been undefined (composition only keeping a random line).
parent 429960e5
......@@ -227,6 +227,13 @@ class AmountGeneratorMixin:
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
reference = self.getReference()
if reference:
if reference in reference_set:
return
reference_set.add(reference)
# Try to collect cells and aggregate their mapped properties
# using resource + variation as aggregation key or base_application
# for intermediate lines.
......@@ -237,9 +244,7 @@ class AmountGeneratorMixin:
base_application_list = self.getBaseApplicationList()
base_contribution_list = self.getBaseContributionList()
for cell in amount_generator_cell_list:
if not cell.test(delivery_amount):
if cell is self:
return
if not (cell is self or cell.test(delivery_amount)):
continue
key = cell.getCellAggregateKey()
try:
......@@ -253,7 +258,7 @@ class AmountGeneratorMixin:
'efficiency': self.getEfficiency(),
'quantity_unit': self.getQuantityUnit(),
# XXX If they are several cells, we have duplicate references.
'reference': self.getReference(),
'reference': reference,
}
# Then collect the mapped values (quantity, price, trade_phase...)
for key in cell.getMappedValuePropertyList():
......@@ -371,6 +376,9 @@ class AmountGeneratorMixin:
delivery_amount = base_amount.getObject()
if not is_mapped_value:
self = delivery_amount.asComposedDocument(amount_generator_type_list)
# If several amount generator lines have same reference, the first
# (sorted by int_index or float_index) matching one will mask the others.
reference_set = set()
accumulateAmountList(self)
return result
......
......@@ -87,18 +87,20 @@ def _getEffectiveModel(self, start_date, stop_date):
@transactional_cached()
def _findPredicateList(container_list, portal_type):
predicate_list = []
reference_dict = {}
mask_set = set()
for container in container_list:
mask_list = []
for ob in container.contentValues(portal_type=portal_type):
if isinstance(ob, Predicate):
# reference is used to hide lines on farther containers
reference = ob.getProperty('reference')
if reference:
reference_set = reference_dict.setdefault(ob.getPortalType(), set())
if reference in reference_set:
key = ob.getPortalType(), reference
if key in mask_set:
continue
reference_set.add(reference)
mask_list.append(key)
predicate_list.append(ob)
mask_set.update(mask_list)
return predicate_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