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

- add support (with tests) for creating composition of trade model lines in many trade conditions

 - add support (with tests) for ability to specialise trade condition on order


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26750 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f31dd5c4
......@@ -37,6 +37,8 @@ from Products.ERP5.Document.Transformation import Transformation
from Products.ERP5.Document.Path import Path
from Products.ERP5.AggregatedAmountList import AggregatedAmountList
class CircularException(Exception): pass
class TradeCondition(Path, Transformation):
"""
Trade Conditions are used to store the conditions (payment, logistic,...)
......@@ -82,14 +84,50 @@ class TradeCondition(Path, Transformation):
return [amount for amount in aggregated_amount_list if
amount.getResource() not in modified_resource_list]
def getTradeModelLineComposedList(self, context=None):
"""Returns list of Trade Model Lines using composition
Resource of Trade Model Line is used to hide other Trade Model Line
In chain first found Trade Model Line has precedence
Context's, if not None, Trade Model Lines have precedence"""
visited_trade_condition_list = []
def findSpecialiseValueList(context):
specialise_value_list = []
if context.getPortalType() in self.getPortalType():
specialise_value_list.append(context)
for specialise in context.getSpecialiseValueList():
if specialise in visited_trade_condition_list:
raise CircularException
visited_trade_condition_list.append(specialise)
specialise_value_list.extend(findSpecialiseValueList(specialise))
return specialise_value_list
resource_list = []
trade_model_line_composed_list = []
containting_object_list = []
if context is not None:
containting_object_list.append(context)
containting_object_list.extend(findSpecialiseValueList(self))
for specialise in containting_object_list:
for trade_model_line in specialise.contentValues(
portal_type='Trade Model Line'):
resource = trade_model_line.getResource()
if resource not in resource_list:
trade_model_line_composed_list.append(trade_model_line)
resource_list.append(resource)
return trade_model_line_composed_list
def getAggregatedAmountList(self, context, **kw):
result = AggregatedAmountList()
trade_model_line_composed_list = \
self.getTradeModelLineComposedList(context)
need_to_run = 1
movement_list = []
while need_to_run:
need_to_run = 0
for model in self.objectValues(portal_type='Trade Model Line'):
for model in trade_model_line_composed_list:
model_result = model.getAggregatedAmountList(context,
movement_list=movement_list, current_aggregated_amount_list = result,
**kw)
......
......@@ -365,10 +365,12 @@ class TestBPMMixin(ERP5TypeTestCase):
node = module.newContent(portal_type=self.node_portal_type)
sequence.edit(destination_section = node)
def stepCreateOrder(self, sequence=None, **kw):
def createOrder(self):
module = self.portal.getDefaultModule(portal_type=self.order_portal_type)
order = module.newContent(portal_type=self.order_portal_type)
sequence.edit(order = order)
return module.newContent(portal_type=self.order_portal_type)
def stepCreateOrder(self, sequence=None, **kw):
sequence.edit(order = self.createOrder())
def stepSpecialiseOrderTradeCondition(self, sequence=None, **kw):
order = sequence.get('order')
......@@ -971,13 +973,15 @@ class TestBPMMixin(ERP5TypeTestCase):
use='discount',
))
def stepCreateTradeCondition(self, sequence=None, **kw):
def createTradeCondition(self):
module = self.portal.getDefaultModule(
portal_type=self.trade_condition_portal_type)
trade_condition = module.newContent(
portal_type=self.trade_condition_portal_type)
return trade_condition
sequence.edit(trade_condition = trade_condition)
def stepCreateTradeCondition(self, sequence=None, **kw):
sequence.edit(trade_condition = self.createTradeCondition())
def stepCreateOrderLine(self, sequence=None, **kw):
order = sequence.get('order')
......@@ -1092,11 +1096,14 @@ class TestBPMMixin(ERP5TypeTestCase):
order_line_discounted_taxed = order_line
)
def createTradeModelLine(self, trade_condition, **kw):
return trade_condition.newContent(
portal_type='Trade Model Line',
**kw)
def stepCreateTradeModelLine(self, sequence=None, **kw):
trade_condition = sequence.get('trade_condition')
trade_model_line = trade_condition.newContent(
portal_type='Trade Model Line')
sequence.edit(trade_model_line = trade_model_line)
sequence.edit(trade_model_line = self.createTradeModelLine(trade_condition))
def stepSpecialiseTradeConditionWithBusinessProcess(self, sequence=None,
**kw):
......@@ -1358,6 +1365,150 @@ class TestBPMTestCases(TestBPMMixin):
Tic
""" + aggregated_amount_list_check
def test_TradeConditionTradeModelLineCircularComposition(self):
"""
If Trade Condition is specialised by another Trade Condition they
Trade Model Lines shall be merged.
"""
trade_condition_1 = self.createTradeCondition()
trade_condition_2 = self.createTradeCondition()
trade_condition_1.setSpecialiseValue(trade_condition_2)
trade_condition_2.setSpecialiseValue(trade_condition_1)
from Products.ERP5Type.Document.TradeCondition import CircularException
self.assertRaises(
CircularException,
trade_condition_1.getTradeModelLineComposedList
)
def test_TradeConditionTradeModelLineBasicComposition(self):
"""
If Trade Condition is specialised by another Trade Condition they
Trade Model Lines shall be merged.
"""
service_1 = self.createResource('Service')
service_2 = self.createResource('Service')
trade_condition_1 = self.createTradeCondition()
trade_condition_2 = self.createTradeCondition()
trade_condition_1.setSpecialiseValue(trade_condition_2)
trade_condition_1_trade_model_line = self.createTradeModelLine(
trade_condition_1,
resource_value = service_1)
trade_condition_2_trade_model_line = self.createTradeModelLine(
trade_condition_2,
resource_value = service_2)
self.assertSameSet(
[trade_condition_1_trade_model_line, trade_condition_2_trade_model_line],
trade_condition_1.getTradeModelLineComposedList()
)
def test_TradeConditionTradeModelLineBasicCompositionWithOrder(self):
"""
If Trade Condition is specialised by another Trade Condition they
Trade Model Lines shall be merged.
"""
service_1 = self.createResource('Service')
service_2 = self.createResource('Service')
service_3 = self.createResource('Service')
trade_condition_1 = self.createTradeCondition()
trade_condition_2 = self.createTradeCondition()
order = self.createOrder()
trade_condition_1.setSpecialiseValue(trade_condition_2)
order.setSpecialiseValue(trade_condition_1)
trade_condition_1_trade_model_line = self.createTradeModelLine(
trade_condition_1,
resource_value = service_1)
trade_condition_2_trade_model_line = self.createTradeModelLine(
trade_condition_2,
resource_value = service_2)
order_trade_model_line = self.createTradeModelLine(
order,
resource_value = service_3)
self.assertSameSet(
[trade_condition_1_trade_model_line, trade_condition_2_trade_model_line],
trade_condition_1.getTradeModelLineComposedList()
)
self.assertSameSet(
[trade_condition_1_trade_model_line, trade_condition_2_trade_model_line,
order_trade_model_line],
trade_condition_1.getTradeModelLineComposedList(context=order)
)
def test_TradeConditionTradeModelLineResourceIsShadowingCompositionWithOrder(self):
"""
If Trade Condition is specialised by another Trade Condition they
Trade Model Lines shall be merged.
"""
service_1 = self.createResource('Service')
service_2 = self.createResource('Service')
trade_condition_1 = self.createTradeCondition()
trade_condition_2 = self.createTradeCondition()
order = self.createOrder()
trade_condition_1.setSpecialiseValue(trade_condition_2)
order.setSpecialiseValue(trade_condition_1)
trade_condition_1_trade_model_line = self.createTradeModelLine(
trade_condition_1,
resource_value = service_1)
trade_condition_2_trade_model_line = self.createTradeModelLine(
trade_condition_2,
resource_value = service_2)
order_trade_model_line = self.createTradeModelLine(
order,
resource_value = service_2)
self.assertSameSet(
[trade_condition_1_trade_model_line, trade_condition_2_trade_model_line],
trade_condition_1.getTradeModelLineComposedList()
)
self.assertSameSet(
[trade_condition_1_trade_model_line, order_trade_model_line],
trade_condition_1.getTradeModelLineComposedList(context=order)
)
def test_TradeConditionTradeModelLineResourceIsShadowingComposition(self):
"""
If Trade Condition is specialised by another Trade Condition
and resource is repeated, only first Trade Model Line shall be returned.
"""
service = self.createResource('Service')
trade_condition_1 = self.createTradeCondition()
trade_condition_2 = self.createTradeCondition()
trade_condition_1.setSpecialiseValue(trade_condition_2)
trade_condition_1_trade_model_line = self.createTradeModelLine(
trade_condition_1,
resource_value = service)
trade_condition_2_trade_model_line = self.createTradeModelLine(
trade_condition_2,
resource_value = service)
self.assertSameSet(
[trade_condition_1_trade_model_line],
trade_condition_1.getTradeModelLineComposedList()
)
def test_getAggreagtedAmountList(self):
"""
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