Commit 173d9cea authored by Julien Muchembled's avatar Julien Muchembled

composition: small fixes

- For the call to _findPredicateList, explicitely check the length of objects
  (instead of trying __nonzero__ first, which is wrong and slow).
- Do not allow to call asComposedDocument on a composed document for the moment.
- Make internal class private and fix __name__ of asComposedDocument method.
- Fix test_tradeModelLineWithTargetLevelSetting

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34265 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d2c340dc
......@@ -95,7 +95,7 @@ def _findPredicateList(*container_list):
return predicate_list
class _asComposedDocument(object):
class asComposedDocument(object):
"""Return a temporary object which is the composition of all effective models
The returned value is a temporary copy of the given object. The list of all
......@@ -106,6 +106,7 @@ class _asComposedDocument(object):
def __new__(cls, orig_self):
if '_effective_model_list' in orig_self.__dict__:
assert False, "not used yet (remove this line if needed)"
return orig_self # if asComposedDocument is called on a composed
# document after any access to its subobjects
self = orig_self.asContext()
......@@ -123,6 +124,7 @@ class _asComposedDocument(object):
assert False
def asComposedDocument(self):
assert False, "not used yet (remove this line if needed)"
return self # if asComposedDocument is called on a composed
# document before any access to its subobjects
......@@ -134,7 +136,7 @@ class _asComposedDocument(object):
# we filter out objects without any subobject to make the cache of
# '_findPredicateList' useful. Otherwise, the key would be always different
# (starting with 'orig_self').
for ob in _findPredicateList(*filter(None, self._effective_model_list)):
for ob in _findPredicateList(*filter(len, self._effective_model_list)):
self._setOb(ob.id, ob)
return self._folder_handler
......@@ -149,7 +151,7 @@ class CompositionMixin:
security.declareProtected(Permissions.AccessContentsInformation,
'asComposedDocument')
asComposedDocument = transactional_cached()(_asComposedDocument)
asComposedDocument = transactional_cached()(asComposedDocument)
# XXX add accessors to get properties from '_effective_model_list' ?
# (cf PaySheetModel)
......@@ -187,3 +189,5 @@ class CompositionMixin:
for model in parent_asComposedDocument()._effective_model_list
if model not in model_set]
return model_list
del asComposedDocument
......@@ -2476,6 +2476,8 @@ class TestTradeModelLine(TestTradeModelLineMixin):
# change target level to `movement`.
tax.edit(target_level=TARGET_LEVEL_MOVEMENT)
transaction.commit() # flush transactional cache
amount_list = trade_condition.getAggregatedAmountList(order)
self.assertEqual(2, len(amount_list))
self.assertEqual(1,
......@@ -2523,6 +2525,8 @@ return current_movement
base_contribution_list=['base_amount/total'],)
discount.edit(quantity=10, price=-1, target_level=TARGET_LEVEL_DELIVERY)
transaction.commit() # flush transactional cache
def getTotalAmount(amount_list):
result = 0
for amount in amount_list:
......@@ -2574,6 +2578,7 @@ return current_movement
extra_fee_a.edit(target_level=TARGET_LEVEL_DELIVERY)
extra_fee_b.edit(target_level=TARGET_LEVEL_DELIVERY)
tax.edit(target_level=TARGET_LEVEL_DELIVERY)
transaction.commit() # flush transactional cache
amount_list = trade_condition.getAggregatedAmountList(order)
self.assertEqual(4, len(amount_list))
self.assertEqual(100 + 1 - 10 + 1500*0.05,
......
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