Commit a16eabfb authored by Łukasz Nowak's avatar Łukasz Nowak

- implement sorting which allows to do easy traversal

 - test sorting order


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27470 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent aab1e367
...@@ -175,12 +175,35 @@ class TradeCondition(Path, Transformation): ...@@ -175,12 +175,35 @@ class TradeCondition(Path, Transformation):
portal_type=portal_type_list): portal_type=portal_type_list):
reference = trade_model_line.getReference() reference = trade_model_line.getReference()
if reference not in reference_list or reference is None: if reference not in reference_list or reference is None:
trade_model_line_composed_list.append(trade_model_line)
reference_list.append(reference) reference_list.append(reference)
base_contribution_list = trade_model_line \
.getBaseContributionList()
if len(base_contribution_list) == 0:
# when movement will not generate anything which contributes
# it is safe to be last on list
trade_model_line_composed_list.append(trade_model_line)
else:
# if movements contributes to anything it have to be placed
# just before to what it contributes
index = 0
inserted = False
for old_trade_model_line in trade_model_line_composed_list:
for base_application in old_trade_model_line \
.getBaseApplicationList():
if base_application in base_contribution_list:
trade_model_line_composed_list.insert(index,
trade_model_line)
inserted = True
break
if inserted:
break
index += 1
if not inserted:
# last resort - nothing was found, it is safe to put movement
# in beginning of list
trade_model_line_composed_list.insert(0, trade_model_line)
return sorted(trade_model_line_composed_list, return trade_model_line_composed_list
cmp=lambda x,y: set(x.getBaseContributionList()).
intersection(set(y.getBaseApplicationList())) and -1 or 1)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getAggregatedAmountList') 'getAggregatedAmountList')
......
...@@ -90,7 +90,7 @@ class TestBPMMixin(ERP5TypeTestCase): ...@@ -90,7 +90,7 @@ class TestBPMMixin(ERP5TypeTestCase):
def createCategories(self): def createCategories(self):
category_tool = getToolByName(self.portal, 'portal_categories') category_tool = getToolByName(self.portal, 'portal_categories')
self.createCategoriesInCategory(category_tool.base_amount, ['discount', self.createCategoriesInCategory(category_tool.base_amount, ['discount',
'tax', 'total_tax', 'total_discount']) 'tax', 'total_tax', 'total_discount', 'total'])
self.createCategoriesInCategory(category_tool.use, self.createCategoriesInCategory(category_tool.use,
self.normal_resource_use_category_list + \ self.normal_resource_use_category_list + \
self.invoicing_resource_use_category_list) self.invoicing_resource_use_category_list)
...@@ -1697,6 +1697,60 @@ class TestBPMTestCases(TestBPMMixin): ...@@ -1697,6 +1697,60 @@ class TestBPMTestCases(TestBPMMixin):
trade_condition_1.getTradeModelLineComposedList() trade_condition_1.getTradeModelLineComposedList()
) )
def test_getTradeModelLineComposedList(self):
"""Test that list of contribution/application relations is sorted to do easy traversal
Let assume such graph of contribution/application dependency:
D -----> B
/ \
E ---/ > A
/
F -----> C
/
G ---/
It shall return list which is sorted like:
* (DE) B (FG) C A
or
* (FG) C (DE) B A
where everything in parenthesis can be not sorted
"""
trade_condition = self.createTradeCondition()
A = self.createTradeModelLine(trade_condition, reference='A',
base_application_list=['base_amount/total'])
B = self.createTradeModelLine(trade_condition, reference='B',
base_contribution_list=['base_amount/total'],
base_application_list=['base_amount/total_tax'])
C = self.createTradeModelLine(trade_condition, reference='C',
base_contribution_list=['base_amount/total'],
base_application_list=['base_amount/total_discount'])
D = self.createTradeModelLine(trade_condition, reference='D',
base_contribution_list=['base_amount/total_tax'],
base_application_list=['base_amount/tax'])
E = self.createTradeModelLine(trade_condition, reference='E',
base_contribution_list=['base_amount/total_tax'],
base_application_list=['base_amount/tax'])
F = self.createTradeModelLine(trade_condition, reference='F',
base_contribution_list=['base_amount/total_discount'],
base_application_list=['base_amount/discount'])
G = self.createTradeModelLine(trade_condition, reference='G',
base_contribution_list=['base_amount/total_discount'],
base_application_list=['base_amount/discount'])
trade_model_line_list = trade_condition.getTradeModelLineComposedList()
# XXX: This is only one good possible sorting
self.assertEquals(sorted([q.getRelativeUrl() for q in trade_model_line_list]),
sorted([q.getRelativeUrl() for q in [D, E, B, F, G, C, A]]))
def test_getAggregatedAmountList(self): def test_getAggregatedAmountList(self):
""" """
Test for case, when discount contributes to tax, and order has mix of contributing lines Test for case, when discount contributes to tax, and order has mix of contributing lines
......
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