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: ...@@ -227,6 +227,13 @@ class AmountGeneratorMixin:
target_method = self.isTargetDelivery() and 'isDelivery' or default_target target_method = self.isTargetDelivery() and 'isDelivery' or default_target
if target_method and not getattr(delivery_amount, target_method)(): if target_method and not getattr(delivery_amount, target_method)():
return 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 # Try to collect cells and aggregate their mapped properties
# using resource + variation as aggregation key or base_application # using resource + variation as aggregation key or base_application
# for intermediate lines. # for intermediate lines.
...@@ -237,9 +244,7 @@ class AmountGeneratorMixin: ...@@ -237,9 +244,7 @@ class AmountGeneratorMixin:
base_application_list = self.getBaseApplicationList() base_application_list = self.getBaseApplicationList()
base_contribution_list = self.getBaseContributionList() base_contribution_list = self.getBaseContributionList()
for cell in amount_generator_cell_list: for cell in amount_generator_cell_list:
if not cell.test(delivery_amount): if not (cell is self or cell.test(delivery_amount)):
if cell is self:
return
continue continue
key = cell.getCellAggregateKey() key = cell.getCellAggregateKey()
try: try:
...@@ -253,7 +258,7 @@ class AmountGeneratorMixin: ...@@ -253,7 +258,7 @@ class AmountGeneratorMixin:
'efficiency': self.getEfficiency(), 'efficiency': self.getEfficiency(),
'quantity_unit': self.getQuantityUnit(), 'quantity_unit': self.getQuantityUnit(),
# XXX If they are several cells, we have duplicate references. # XXX If they are several cells, we have duplicate references.
'reference': self.getReference(), 'reference': reference,
} }
# Then collect the mapped values (quantity, price, trade_phase...) # Then collect the mapped values (quantity, price, trade_phase...)
for key in cell.getMappedValuePropertyList(): for key in cell.getMappedValuePropertyList():
...@@ -371,6 +376,9 @@ class AmountGeneratorMixin: ...@@ -371,6 +376,9 @@ 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)
# 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) accumulateAmountList(self)
return result return result
......
...@@ -87,18 +87,20 @@ def _getEffectiveModel(self, start_date, stop_date): ...@@ -87,18 +87,20 @@ def _getEffectiveModel(self, start_date, stop_date):
@transactional_cached() @transactional_cached()
def _findPredicateList(container_list, portal_type): def _findPredicateList(container_list, portal_type):
predicate_list = [] predicate_list = []
reference_dict = {} mask_set = set()
for container in container_list: for container in container_list:
mask_list = []
for ob in container.contentValues(portal_type=portal_type): for ob in container.contentValues(portal_type=portal_type):
if isinstance(ob, Predicate): if isinstance(ob, Predicate):
# reference is used to hide lines on farther containers # reference is used to hide lines on farther containers
reference = ob.getProperty('reference') reference = ob.getProperty('reference')
if reference: if reference:
reference_set = reference_dict.setdefault(ob.getPortalType(), set()) key = ob.getPortalType(), reference
if reference in reference_set: if key in mask_set:
continue continue
reference_set.add(reference) mask_list.append(key)
predicate_list.append(ob) predicate_list.append(ob)
mask_set.update(mask_list)
return predicate_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