Commit c80c5658 authored by Julien Muchembled's avatar Julien Muchembled

Fix testComplexTradeModelLineUseCase

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@39069 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e2075796
...@@ -57,17 +57,8 @@ class BaseAmount(dict): ...@@ -57,17 +57,8 @@ class BaseAmount(dict):
def getContext(self): def getContext(self):
return self._context return self._context
def updateCache(self, base_amount_set, amount_generator_line): def setAmountGeneratorLine(self, amount_generator_line):
cache = self._cache self._amount_generator_line = amount_generator_line
base_amount_set = base_amount_set.difference(cache)
if base_amount_set:
method = amount_generator_line._getTypeBasedMethod(
'getBaseAmountQuantityMethod')
for base_amount in base_amount_set:
if method is None:
cache[base_amount] = amount_generator_line.getBaseAmountQuantity
else:
cache[base_amount] = method(base_amount)
def recurse(self, portal_type=None): def recurse(self, portal_type=None):
for amount in self._context.objectValues(portal_type=portal_type): for amount in self._context.objectValues(portal_type=portal_type):
...@@ -92,7 +83,9 @@ class BaseAmount(dict): ...@@ -92,7 +83,9 @@ class BaseAmount(dict):
return dict.__getitem__(self, key) return dict.__getitem__(self, key)
except KeyError: except KeyError:
value = 0 value = 0
amount_generator_line = self._amount_generator_line
for lazy in self._lazy: for lazy in self._lazy:
lazy._amount_generator_line = amount_generator_line
value += lazy.getQuantity(key) value += lazy.getQuantity(key)
self[key] = value self[key] = value
return value return value
...@@ -109,7 +102,17 @@ class BaseAmount(dict): ...@@ -109,7 +102,17 @@ class BaseAmount(dict):
return dict.__getitem__(self, key) return dict.__getitem__(self, key)
self[key] # initialize entry before we freeze it self[key] # initialize entry before we freeze it
self._frozen.add(key) self._frozen.add(key)
self[key] = value = self._cache[key](self._context, key, **self._method_kw) try:
method = self._cache[key]
except KeyError:
method = self._amount_generator_line._getTypeBasedMethod(
'getBaseAmountQuantityMethod')
if method is not None:
method = method(key)
if method is None:
method = self._amount_generator_line.getBaseAmountQuantity
self._cache[key] = method
self[key] = value = method(self._context, key, **self._method_kw)
return value return value
...@@ -241,11 +244,9 @@ class AmountGeneratorMixin: ...@@ -241,11 +244,9 @@ class AmountGeneratorMixin:
cell.getBaseContributionList()) cell.getBaseContributionList())
property_dict['causality_value_list'].append(cell) property_dict['causality_value_list'].append(cell)
base_amount.setAmountGeneratorLine(self)
for property_dict in cell_aggregate.itervalues(): for property_dict in cell_aggregate.itervalues():
base_application_set = property_dict['base_application_set'] base_application_set = property_dict['base_application_set']
# Cache must be prepared with the right context in case that we iterate
# through different kinds of amount generator lines.
base_amount.updateCache(base_application_set, self)
# property_dict may include # property_dict may include
# resource - VAT service or a Component in MRP # resource - VAT service or a Component in MRP
# (if unset, the amount will only be used for reporting) # (if unset, the amount will only be used for reporting)
...@@ -293,12 +294,9 @@ class AmountGeneratorMixin: ...@@ -293,12 +294,9 @@ class AmountGeneratorMixin:
amount = getRoundingProxy(amount, context=self) amount = getRoundingProxy(amount, context=self)
result.append(amount) result.append(amount)
# Contribute # Contribute
base_contribution_set = property_dict['base_contribution_set']
if base_contribution_set:
quantity *= (property_dict.get('price') or 1) / \ quantity *= (property_dict.get('price') or 1) / \
(property_dict.get('efficiency') or 1) (property_dict.get('efficiency') or 1)
base_amount.updateCache(base_contribution_set, self) for base_contribution in property_dict['base_contribution_set']:
for base_contribution in base_contribution_set:
base_amount[base_contribution] += quantity base_amount[base_contribution] += quantity
is_mapped_value = isinstance(self, MappedValue) is_mapped_value = isinstance(self, MappedValue)
......
...@@ -60,7 +60,7 @@ class TestBPMMixin(ERP5TypeTestCase): ...@@ -60,7 +60,7 @@ class TestBPMMixin(ERP5TypeTestCase):
def createCategories(self): def createCategories(self):
category_tool = self.portal.portal_categories category_tool = self.portal.portal_categories
self.createCategoriesInCategory(category_tool.base_amount, ['discount', self.createCategoriesInCategory(category_tool.base_amount, ['discount',
'tax', 'total_tax', 'total_discount', 'total', 'fixed_quantity']) '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)
......
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
import unittest import unittest
import transaction import transaction
from Products.ERP5Type.tests.utils import createZODBPythonScript
from Products.ERP5.tests.testTradeModelLine import TestTradeModelLineMixin from Products.ERP5.tests.testTradeModelLine import TestTradeModelLineMixin
...@@ -39,201 +37,121 @@ class TestComplexTradeModelLineUseCase(TestTradeModelLineMixin): ...@@ -39,201 +37,121 @@ class TestComplexTradeModelLineUseCase(TestTradeModelLineMixin):
shop and make sure that trade model line is capable of real business scene. shop and make sure that trade model line is capable of real business scene.
""" """
def createOrder(self): def appendBaseContributionCategory(self, document, *new_category):
module = self.portal.getDefaultModule(portal_type=self.order_portal_type) document.setBaseContributionList(
return module.newContent(portal_type=self.order_portal_type, document.getBaseContributionList() + list(new_category))
title=self.id())
def createCategories(self):
def createTradeCondition(self): super(TestComplexTradeModelLineUseCase, self).createCategories()
module = self.portal.getDefaultModule( category_tool = self.portal.portal_categories
portal_type=self.trade_condition_portal_type) self.createCategoriesInCategory(category_tool.base_amount, (
trade_condition = module.newContent( 'additional_charge',
portal_type=self.trade_condition_portal_type, 'discount_amount',
title=self.id()) 'discount_amount_of_non_vat_taxable',
return trade_condition 'discount_amount_of_vat_taxable',
'total_price_of_ordered_items',
def getAmount(self, order, reference, return_object=False): 'total_price_of_vat_taxable',
amount_list = [] 'total_price_without_vat',
for amount in order.getAggregatedAmountList(): 'total_price_with_vat',
if amount.getProperty('reference') == reference: 'vat_amount',
amount_list.append(amount) 'vat_taxable',
if return_object: ))
return amount_list self.createCategoriesInCategory(category_tool.product_line, (
if amount_list: 'audio', 'video', 'other'))
return sum(amount.getTotalPrice() for amount in amount_list) self.createCategoriesInCategory(category_tool.product_line.audio, ('cd',))
self.createCategoriesInCategory(category_tool.product_line.video, ('dvd',))
def appendBaseContributionCategory(self, document, new_category): self.createCategoriesInCategory(category_tool.quantity_unit, ('unit',))
base_contribution_value_list = document.getBaseContributionValueList()
document.setBaseContributionValueList(
base_contribution_value_list+[new_category])
def beforeTearDown(self):
# abort any transaction
transaction.abort()
# put non finished activities into ignored state
activity_connection = self.portal.cmf_activity_sql_connection
for table in 'message', 'message_queue':
activity_connection.manage_test(
'delete from %s where processing_node=-2' % table)
def removeAll(*args):
for container in args:
container.manage_delObjects(ids=list(container.objectIds()))
removeAll(self.portal.sale_order_module,
self.portal.purchase_order_module,
self.portal.sale_trade_condition_module,
self.portal.purchase_trade_condition_module,
self.portal.person_module,
self.portal.organisation_module,
self.portal.service_module,
self.portal.product_module,
self.portal.currency_module,
self.portal.portal_categories.product_line,
self.portal.portal_categories.base_amount,
self.portal.portal_categories.trade_phase,
self.portal.portal_categories.use,
self.portal.portal_categories.quantity_unit,
)
self.stepTic()
def afterSetUp(self): def afterSetUp(self):
super(TestComplexTradeModelLineUseCase, self).afterSetUp()
portal = self.portal portal = self.portal
# inherited method
self.createCategories()
self.stepTic()
# add currency # add currency
jpy = portal.currency_module.newContent(title='Yen', reference='JPY', base_unit_quantity='1') jpy = portal.currency_module.newContent(title='Yen', reference='JPY',
base_unit_quantity='1')
self.stepTic()
# add organisations # add organisations
my_company = portal.organisation_module.newContent(title='My Company') my_company = portal.organisation_module.newContent(title='My Company')
client_1 = portal.organisation_module.newContent(title='Client 1') client_1 = portal.organisation_module.newContent(title='Client 1')
self.stepTic()
# add base amount subcategories
base_amount = portal.portal_categories.base_amount
self.total_price_of_ordered_items = base_amount.newContent(id='total_price_of_ordered_items')
self.discount_amount_of_non_vat_taxable = base_amount.newContent(id='discount_amount_of_non_vat_taxable')
self.discount_amount_of_vat_taxable = base_amount.newContent(id='discount_amount_of_vat_taxable')
self.vat_taxable = base_amount.newContent(id='vat_taxable')
self.additional_charge = base_amount.newContent('additional_charge')
self.total_price_without_vat = base_amount.newContent(id='total_price_without_vat')
self.total_price_of_vat_taxable = base_amount.newContent(id='total_price_of_vat_taxable')
self.discount_amount = base_amount.newContent(id='discount_amount')
self.vat_amount = base_amount.newContent(id='vat_amount')
self.total_price_with_vat = base_amount.newContent(id='total_price_with_vat')
self.poster_present_1dvd = base_amount.newContent(id='poster_present_1dvd')
self.poster_present_3cd = base_amount.newContent(id='poster_present_3cd')
self.special_discount_3cd = base_amount.newContent(id='special_discount_3cd')
# add product line subcategories
product_line = portal.portal_categories.product_line
audio = product_line.newContent(id='audio')
audio_cd = audio.newContent(id='cd')
video = product_line.newContent(id='video')
video_dvd = video.newContent(id='dvd')
other_product = product_line.newContent(id='other')
# add a quantity unit subcategory
self.unit = portal.portal_categories.quantity_unit.newContent(id='unit')
self.stepTic()
# create services # create services
self.service_vat = portal.service_module.newContent(title='VAT') self.service_vat = portal.service_module.newContent(title='VAT')
self.service_discount = portal.service_module.newContent(title='DISCOUNT') self.service_discount = portal.service_module.newContent(title='DISCOUNT')
self.service_shipping_fee = portal.service_module.newContent(title='SHIPPING FEE') self.service_shipping_fee = portal.service_module.newContent(title='SHIPPING FEE')
self.stepTic()
# create products # create products
def addProductDocument(title, product_line_value): def addProductDocument(title, product_line):
return portal.product_module.newContent( return portal.product_module.newContent(
title=title, title=title,
product_line_value=product_line_value, product_line=product_line,
quantity_unit_value=self.unit, quantity_unit='unit',
base_contribution_value_list=[self.vat_taxable, base_contribution_list=('base_amount/vat_taxable',
self.total_price_of_ordered_items]) 'base_amount/total_price_of_ordered_items'))
self.music_album_1 = addProductDocument('Music Album 1', 'audio/cd')
self.music_album_1 = addProductDocument('Music Album 1', audio_cd) self.movie_dvd_1 = addProductDocument('Movie DVD 1', 'video/dvd')
self.movie_dvd_1 = addProductDocument('Movie DVD 1', video_dvd) self.music_album_2 = addProductDocument('Movie Album 2', 'audio/cd')
self.music_album_2 = addProductDocument('Movie Album 2', audio_cd) self.candy = addProductDocument('Candy', 'other')
self.candy = addProductDocument('Candy', other_product) self.poster = addProductDocument('Poster', 'other')
self.poster = addProductDocument('Poster', other_product) self.music_album_3 = addProductDocument('Movie Album 3', 'audio/cd')
self.music_album_3 = addProductDocument('Movie Album 3', audio_cd) self.movie_dvd_2 = addProductDocument('Movie DVD 2', 'video/dvd')
self.movie_dvd_2 = addProductDocument('Movie DVD 2', video_dvd) self.music_album_4 = addProductDocument('Movie Album 4', 'audio/cd')
self.music_album_4 = addProductDocument('Movie Album 4', audio_cd)
# create a trade condition with several common trade model lines
self.stepTic() self.trade_condition = self.createTradeCondition(
self.createBusinessProcess(), (
# create a trade condition and add several common trade model lines in it. dict(title='Total Price Without VAT',
self.trade_condition = self.createTradeCondition()
self.trade_condition.edit(
source_section_value=my_company,
source_value=my_company,
source_decision_value=my_company,
destination_section_value=client_1,
destination_value=client_1,
destination_decision_value=client_1,
price_currency_value=jpy)
self.trade_condition.newContent(
portal_type='Trade Model Line',
title='Total Price Without VAT',
reference='TOTAL_PRICE_WITHOUT_VAT', reference='TOTAL_PRICE_WITHOUT_VAT',
price=1, price=1,
trade_phase=None,
int_index=10, int_index=10,
base_application_value_list=[self.discount_amount_of_non_vat_taxable, target_delivery=True,
self.discount_amount_of_vat_taxable, base_application_list=('base_amount/discount_amount_of_non_vat_taxable',
self.total_price_of_ordered_items, 'base_amount/discount_amount_of_vat_taxable',
self.additional_charge], 'base_amount/total_price_of_ordered_items',
base_contribution_value_list=[self.total_price_without_vat]) 'base_amount/additional_charge'),
self.trade_condition.newContent( base_contribution='base_amount/total_price_without_vat'),
portal_type='Trade Model Line', dict(title='Total Price Of VAT Taxable',
title='Total Price Of VAT Taxable',
reference='TOTAL_PRICE_OF_VAT_TAXABLE', reference='TOTAL_PRICE_OF_VAT_TAXABLE',
price=1, price=1,
trade_phase=None,
int_index=10, int_index=10,
base_application_value_list=[self.discount_amount_of_vat_taxable, target_delivery=True,
self.vat_taxable], base_application_list=('base_amount/discount_amount_of_vat_taxable',
base_contribution_value_list=[self.total_price_of_vat_taxable]) 'base_amount/vat_taxable'),
self.trade_condition.newContent( base_contribution='base_amount/total_price_of_vat_taxable'),
portal_type='Trade Model Line', dict(title='Discount Amount',
title='Discount Amount',
reference='DISCOUNT_AMOUNT', reference='DISCOUNT_AMOUNT',
resource_value=self.service_discount, resource_value=self.service_discount,
price=1, price=1,
trade_phase_value=portal.portal_categories.trade_phase.default.invoicing, trade_phase='default/invoicing',
int_index=10, int_index=10,
base_application_value_list=[self.discount_amount_of_vat_taxable, target_delivery=True,
self.discount_amount_of_non_vat_taxable], base_application_list=('base_amount/discount_amount_of_vat_taxable',
base_contribution_value_list=[self.discount_amount]) 'base_amount/discount_amount_of_non_vat_taxable'),
self.trade_condition.newContent( base_contribution='base_amount/discount_amount'),
portal_type='Trade Model Line', dict(title='VAT Amount',
title='VAT Amount',
reference='VAT_AMOUNT', reference='VAT_AMOUNT',
resource_value=self.service_vat, resource_value=self.service_vat,
price=0.05, price=0.05,
trade_phase_value=portal.portal_categories.trade_phase.default.invoicing, trade_phase='default/invoicing',
int_index=10, int_index=10,
base_application_value_list=[self.discount_amount_of_vat_taxable, target_delivery=True,
self.vat_taxable], base_application_list=('base_amount/discount_amount_of_vat_taxable',
base_contribution_value_list=[self.vat_amount]) 'base_amount/vat_taxable'),
self.trade_condition.newContent( base_contribution='base_amount/vat_amount'),
portal_type='Trade Model Line', dict(title='Total Price With VAT',
title='Total Price With VAT',
reference='TOTAL_PRICE_WITH_VAT', reference='TOTAL_PRICE_WITH_VAT',
price=1, price=1,
trade_phase=None,
int_index=20, int_index=20,
base_application_value_list=[self.vat_amount, target_delivery=True,
self.total_price_without_vat], base_application_list=('base_amount/vat_amount',
base_contribution_value_list=[self.total_price_with_vat]) 'base_amount/total_price_without_vat'),
base_contribution='base_amount/total_price_with_vat')
),
source_section_value=my_company,
source_value=my_company,
source_decision_value=my_company,
destination_section_value=client_1,
destination_value=client_1,
destination_decision_value=client_1,
price_currency_value=jpy)
self.stepTic() self.stepTic()
...@@ -247,65 +165,56 @@ class TestComplexTradeModelLineUseCase(TestTradeModelLineMixin): ...@@ -247,65 +165,56 @@ class TestComplexTradeModelLineUseCase(TestTradeModelLineMixin):
1 CD 2400 yen 1 CD 2400 yen
discount (5000+3000+2400) * 0.1 = 1040 yen discount (5000+3000+2400) * 0.1 = 1040 yen
""" """
createZODBPythonScript( special_discount = self.setBaseAmountQuantityMethod(
self.portal.portal_skins.custom, 'special_discount', """\
'TradeModelLine_getAmountProperty', def getBaseAmountQuantity(delivery_amount, base_application, **kw):
'amount, base_application, amount_list, *args, **kw', if delivery_amount.isDelivery():
"""\ total_quantity = sum([movement.getQuantity()
if base_application == 'base_amount/special_discount_3cd': for movement in delivery_amount.getMovementList()
total_quantity = sum([x.getQuantity() for x in amount_list if base_application in movement.getBaseContributionList()])
if x.isMovement() and base_application in x.getBaseContributionList()])
if total_quantity < 3: if total_quantity < 3:
return 0 return 0
""") return context.getBaseAmountQuantity(
order = self.createOrder() delivery_amount, base_application, **kw)
order.edit(specialise_value=self.trade_condition) return getBaseAmountQuantity""")
order.Order_applyTradeCondition(order.getSpecialiseValue())
order.newContent(portal_type='Trade Model Line', trade_condition = self.createTradeCondition(
reference='3CD_AND_10PERCENT_DISCOUNT_OFF_THEM', self.trade_condition, (
dict(reference='SPECIAL_DISCOUNT_3CD_LINEAR',
resource_value=self.service_discount, resource_value=self.service_discount,
price=-0.1, price=-0.1,
trade_phase=None,
int_index=0, int_index=0,
base_application_value_list=[self.special_discount_3cd], target_delivery=True,
base_contribution_value_list=[self.discount_amount_of_vat_taxable]) base_application=special_discount,
base_contribution='base_amount/discount_amount_of_vat_taxable'),
order_line_1 = order.newContent(portal_type=self.order_line_portal_type, ))
resource_value=self.music_album_1,
quantity=1, order = self.createOrder(trade_condition, (
price=5000) dict(id='1', price=5000, quantity=1, resource_value=self.music_album_1),
self.appendBaseContributionCategory(order_line_1, self.special_discount_3cd) dict(id='2', price=3000, quantity=1, resource_value=self.music_album_2),
order_line_2 = order.newContent(portal_type=self.order_line_portal_type, dict(id='3', price=100, quantity=1, resource_value=self.candy),
resource_value=self.music_album_2, ))
quantity=1, self.appendBaseContributionCategory(order['1'], special_discount)
price=3000) self.appendBaseContributionCategory(order['2'], special_discount)
self.appendBaseContributionCategory(order_line_2, self.special_discount_3cd) transaction.commit()
order_line_3 = order.newContent(portal_type=self.order_line_portal_type, self.getAggregatedAmountDict(order, partial_check=True,
resource_value=self.candy, SPECIAL_DISCOUNT_3CD_LINEAR=None,
quantity=1, TOTAL_PRICE_WITHOUT_VAT=dict(total_price=8100),
price=100) TOTAL_PRICE_WITH_VAT=dict(total_price=8505),
VAT_AMOUNT=dict(total_price=405))
self.stepTic()
# check the current amount
#self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITHOUT_VAT'), 8100)
self.assertEqual(self.getAmount(order, 'VAT_AMOUNT'), 405)
#self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITH_VAT'), 8505)
# add one more cd, then total is 3. the special discount will be applied. # add one more cd, then total is 3. the special discount will be applied.
order_line_4 = order.newContent(portal_type=self.order_line_portal_type, line = order.newContent(portal_type=self.order_line_portal_type,
resource_value=self.music_album_3, resource_value=self.music_album_3,
quantity=1, quantity=1,
price=2400) price=2400)
self.appendBaseContributionCategory(order_line_4, self.special_discount_3cd) self.appendBaseContributionCategory(line, special_discount)
transaction.commit()
self.stepTic() self.getAggregatedAmountDict(order, partial_check=True,
SPECIAL_DISCOUNT_3CD_LINEAR=dict(total_price=-1040),
# check again TOTAL_PRICE_WITHOUT_VAT=dict(total_price=9460),
self.assertEqual(self.getAmount(order, '3CD_AND_10PERCENT_DISCOUNT_OFF_THEM'), TOTAL_PRICE_WITH_VAT=dict(total_price=9933),
-1040) VAT_AMOUNT=dict(total_price=473))
#self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITHOUT_VAT'), 9460)
self.assertEqual(self.getAmount(order, 'VAT_AMOUNT'), 473)
#self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITH_VAT'), 9933)
def test_usecase2(self): def test_usecase2(self):
""" """
...@@ -317,64 +226,51 @@ if base_application == 'base_amount/special_discount_3cd': ...@@ -317,64 +226,51 @@ if base_application == 'base_amount/special_discount_3cd':
1 CD 2400 yen 1 CD 2400 yen
discount 500 yen discount 500 yen
""" """
createZODBPythonScript( special_discount = self.setBaseAmountQuantityMethod(
self.portal.portal_skins.custom, 'special_discount', """\
'TradeModelLine_calculate3CD500YenDiscount', return lambda delivery_amount, base_application, **kw: \\
'current_aggregated_amount_list, current_movement, aggregated_movement_list', 3 <= sum([movement.getQuantity()
"""\ for movement in delivery_amount.getMovementList()
total_quantity = sum([movement.getQuantity() for movement in aggregated_movement_list]) if base_application in movement.getBaseContributionList()])""")
if total_quantity >= 3:
current_movement.setQuantity(-500) trade_condition = self.createTradeCondition(
return current_movement self.trade_condition, (
else: dict(reference='SPECIAL_DISCOUNT_3CD_FIXED',
return None
""")
order = self.createOrder()
order.edit(specialise_value=self.trade_condition)
order.Order_applyTradeCondition(order.getSpecialiseValue())
order.newContent(portal_type='Trade Model Line',
reference='3CD_AND_500YEN_OFF',
resource_value=self.service_discount, resource_value=self.service_discount,
price=1, price=-1,
target_level=TARGET_LEVEL_DELIVERY, quantity=500,
calculation_script_id='TradeModelLine_calculate3CD500YenDiscount',
trade_phase=None,
int_index=0, int_index=0,
base_application_value_list=[self.special_discount_3cd], target_delivery=True,
base_contribution_value_list=[self.discount_amount_of_vat_taxable]) base_application=special_discount,
base_contribution='base_amount/discount_amount_of_vat_taxable'),
order_line_1 = order.newContent(portal_type=self.order_line_portal_type, ))
resource_value=self.music_album_1,
quantity=1, order = self.createOrder(trade_condition, (
price=5000) dict(id='1', price=5000, quantity=1, resource_value=self.music_album_1),
self.appendBaseContributionCategory(order_line_1, self.special_discount_3cd) dict(id='2', price=3000, quantity=1, resource_value=self.music_album_2),
order_line_2 = order.newContent(portal_type=self.order_line_portal_type, dict(id='3', price=3000, quantity=1, resource_value=self.movie_dvd_1),
resource_value=self.music_album_2, ))
quantity=1, self.appendBaseContributionCategory(order['1'], special_discount)
price=3000) self.appendBaseContributionCategory(order['2'], special_discount)
self.appendBaseContributionCategory(order_line_2, self.special_discount_3cd) transaction.commit()
order_line_3 = order.newContent(portal_type=self.order_line_portal_type, self.getAggregatedAmountDict(order, partial_check=True,
resource_value=self.movie_dvd_1, SPECIAL_DISCOUNT_3CD_FIXED=None,
quantity=1, TOTAL_PRICE_WITHOUT_VAT=dict(total_price=11000),
price=3000) TOTAL_PRICE_WITH_VAT=dict(total_price=11550),
VAT_AMOUNT=dict(total_price=550))
self.stepTic()
# check the current amount
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITHOUT_VAT'), 11000)
self.assertEqual(self.getAmount(order, 'VAT_AMOUNT'), 550)
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITH_VAT'), 11550)
# add one more cd, then total is 3. the special discount will be applied. # add one more cd, then total is 3. the special discount will be applied.
order_line_4 = order.newContent(portal_type=self.order_line_portal_type, line = order.newContent(portal_type=self.order_line_portal_type,
resource_value=self.music_album_3, resource_value=self.music_album_3,
quantity=1, quantity=1,
price=2400) price=2400)
self.appendBaseContributionCategory(order_line_4, self.special_discount_3cd) self.appendBaseContributionCategory(line, special_discount)
# check again transaction.commit()
self.assertEqual(self.getAmount(order, '3CD_AND_500YEN_OFF'), -500) self.getAggregatedAmountDict(order, partial_check=True,
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITHOUT_VAT'), 12900) SPECIAL_DISCOUNT_3CD_FIXED=dict(total_price=-500),
self.assertEqual(self.getAmount(order, 'VAT_AMOUNT'), 645) TOTAL_PRICE_WITHOUT_VAT=dict(total_price=12900),
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITH_VAT'), 13545) TOTAL_PRICE_WITH_VAT=dict(total_price=13545),
VAT_AMOUNT=dict(total_price=645))
def test_usecase3(self): def test_usecase3(self):
""" """
...@@ -386,66 +282,55 @@ else: ...@@ -386,66 +282,55 @@ else:
1 CD 2400 yen 1 CD 2400 yen
discount (5000+3000+3000+2400) * 0.1 = 1340 yen discount (5000+3000+3000+2400) * 0.1 = 1340 yen
""" """
createZODBPythonScript( special_discount = self.setBaseAmountQuantityMethod(
self.portal.portal_skins.custom, 'special_discount', """\
'TradeModelLine_calculate3CD10PercentDiscountFromTotal', def getBaseAmountQuantity(delivery_amount, base_application, **kw):
'current_aggregated_amount_list, current_movement, aggregated_movement_list', total_quantity = sum([movement.getQuantity()
'''\ for movement in delivery_amount.getMovementList()
special_discount_3cd = context.portal_categories.base_amount.special_discount_3cd if base_application in movement.getBaseContributionList()])
total_quantity = sum([movement.getQuantity() for movement in current_aggregated_amount_list if total_quantity < 3:
if special_discount_3cd in movement.getBaseContributionValueList()]) return 0
if total_quantity >= 3: return delivery_amount.getGeneratedAmountQuantity(
return current_movement 'base_amount/total_price_of_ordered_items')
else: return getBaseAmountQuantity""")
return None
''') trade_condition = self.createTradeCondition(
order = self.createOrder() self.trade_condition, (
order.edit(specialise_value=self.trade_condition) dict(reference='SPECIAL_DISCOUNT_3CD_LINEAR',
order.Order_applyTradeCondition(order.getSpecialiseValue())
order.newContent(portal_type='Trade Model Line',
reference='3CD_10PERCENT_OFF_FROM_TOTAL',
resource_value=self.service_discount, resource_value=self.service_discount,
price=-0.1, price=-0.1,
target_level=TARGET_LEVEL_DELIVERY,
calculation_script_id='TradeModelLine_calculate3CD10PercentDiscountFromTotal',
trade_phase=None,
int_index=0, int_index=0,
base_application_value_list=[self.total_price_of_ordered_items], target_delivery=True,
base_contribution_value_list=[self.discount_amount_of_vat_taxable]) base_application=special_discount,
base_contribution='base_amount/discount_amount_of_vat_taxable'),
order_line_1 = order.newContent(portal_type=self.order_line_portal_type, ))
resource_value=self.music_album_1,
quantity=1, order = self.createOrder(trade_condition, (
price=5000) dict(id='1', price=5000, quantity=1, resource_value=self.music_album_1),
self.appendBaseContributionCategory(order_line_1, self.special_discount_3cd) dict(id='2', price=3000, quantity=1, resource_value=self.movie_dvd_1),
order_line_2 = order.newContent(portal_type=self.order_line_portal_type, dict(id='3', price=3000, quantity=1, resource_value=self.music_album_2),
resource_value=self.movie_dvd_1, ))
quantity=1, self.appendBaseContributionCategory(order['1'], special_discount)
price=3000) self.appendBaseContributionCategory(order['3'], special_discount)
order_line_3 = order.newContent(portal_type=self.order_line_portal_type, transaction.commit()
resource_value=self.music_album_2, self.getAggregatedAmountDict(order, partial_check=True,
quantity=1, SPECIAL_DISCOUNT_3CD_LINEAR=None,
price=3000) TOTAL_PRICE_WITHOUT_VAT=dict(total_price=11000),
self.appendBaseContributionCategory(order_line_3, self.special_discount_3cd) TOTAL_PRICE_WITH_VAT=dict(total_price=11550),
VAT_AMOUNT=dict(total_price=550))
self.stepTic()
# check the current amount
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITHOUT_VAT'), 11000)
self.assertEqual(self.getAmount(order, 'VAT_AMOUNT'), 550)
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITH_VAT'), 11550)
# add one more cd, then total is 3. the special discount will be applied. # add one more cd, then total is 3. the special discount will be applied.
order_line_4 = order.newContent(portal_type=self.order_line_portal_type, line = order.newContent(portal_type=self.order_line_portal_type,
resource_value=self.music_album_3, resource_value=self.music_album_3,
quantity=1, quantity=1,
price=2400) price=2400)
self.appendBaseContributionCategory(order_line_4, self.special_discount_3cd) self.appendBaseContributionCategory(line, special_discount)
# check again transaction.commit()
self.assertEqual(self.getAmount(order, '3CD_10PERCENT_OFF_FROM_TOTAL'), self.getAggregatedAmountDict(order, partial_check=True,
-1340) SPECIAL_DISCOUNT_3CD_LINEAR=dict(total_price=-1340),
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITHOUT_VAT'), 12060) TOTAL_PRICE_WITHOUT_VAT=dict(total_price=12060),
self.assertEqual(self.getAmount(order, 'VAT_AMOUNT'), 603) TOTAL_PRICE_WITH_VAT=dict(total_price=12663),
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITH_VAT'), 12663) VAT_AMOUNT=dict(total_price=603))
def test_usecase4(self): def test_usecase4(self):
""" """
...@@ -455,97 +340,72 @@ else: ...@@ -455,97 +340,72 @@ else:
1 DVD 3000 yen 1 DVD 3000 yen
1 Poster 0 yen 1 Poster 0 yen
""" """
createZODBPythonScript( total_quantity = """\
self.portal.portal_skins.custom, def getBaseAmountQuantity(delivery_amount, base_application, **kw):
'TradeModelLine_calculate3CDOr1DVDForPoster', value = delivery_amount.getGeneratedAmountQuantity(base_application)
'current_aggregated_amount_list, current_movement, aggregated_movement_list', if base_application in delivery_amount.getBaseContributionList():
'''\ value += delivery_amount.getQuantity()
poster_present_3cd = context.portal_categories.base_amount.poster_present_3cd return value
poster_present_1dvd = context.portal_categories.base_amount.poster_present_1dvd return getBaseAmountQuantity"""
poster_present_1dvd = self.setBaseAmountQuantityMethod(
total_quantity_3cd = sum([movement.getQuantity() for movement in aggregated_movement_list 'poster_present_1dvd', total_quantity)
if poster_present_3cd in movement.getBaseContributionValueList()]) poster_present_3cd = self.setBaseAmountQuantityMethod(
total_quantity_1dvd = sum([movement.getQuantity() for movement in aggregated_movement_list 'poster_present_3cd', total_quantity)
if poster_present_1dvd in movement.getBaseContributionValueList()]) special_discount = self.setBaseAmountQuantityMethod(
if (total_quantity_3cd >= 3 or total_quantity_1dvd >= 1): 'special_discount', """\
current_movement.setQuantity(1) return lambda delivery_amount, base_application, **kw: \\
return current_movement 3 <= delivery_amount.getGeneratedAmountQuantity(%r) or \\
else: 1 <= delivery_amount.getGeneratedAmountQuantity(%r)"""
return None % (poster_present_3cd, poster_present_1dvd))
''')
order = self.createOrder() trade_condition = self.createTradeCondition(
order.edit(specialise_value=self.trade_condition) self.trade_condition, (
order.Order_applyTradeCondition(order.getSpecialiseValue()) dict(reference='SPECIAL_DISCOUNT_3CD_OR_1DVD_FIXED',
order.newContent(portal_type='Trade Model Line',
reference='3CD_OR_1DVD_GET_1_POSTER_FREE',
resource_value=self.poster, resource_value=self.poster,
price=0, price=0,
target_level=TARGET_LEVEL_DELIVERY, int_index=0,
calculation_script_id='TradeModelLine_calculate3CDOr1DVDForPoster', target_delivery=True,
trade_phase=None, base_application=special_discount),
base_application_value_list=[self.poster_present_1dvd, ))
self.poster_present_3cd])
order = self.createOrder(trade_condition, (
order_line_1 = order.newContent(portal_type=self.order_line_portal_type, dict(id='1', price=3000, quantity=2, resource_value=self.music_album_4),
resource_value=self.music_album_4, ))
quantity=2, self.appendBaseContributionCategory(order['1'], poster_present_3cd)
price=3000) transaction.commit()
self.appendBaseContributionCategory(order_line_1, self.poster_present_3cd) self.getAggregatedAmountDict(order, partial_check=True,
SPECIAL_DISCOUNT_3CD_OR_1DVD_FIXED=None,
self.stepTic() TOTAL_PRICE_WITHOUT_VAT=dict(total_price=6000),
TOTAL_PRICE_WITH_VAT=dict(total_price=6300),
VAT_AMOUNT=dict(total_price=300))
# check the current amount
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITHOUT_VAT'), 6000)
self.assertEqual(self.getAmount(order, 'VAT_AMOUNT'), 300)
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITH_VAT'), 6300)
self.assertEqual(self.getAmount(order, '3CD_OR_1DVD_GET_1_POSTER_FREE'),
None)
# add 1 dvd, then 1 poster will be given. # add 1 dvd, then 1 poster will be given.
order_line_2 = order.newContent(portal_type=self.order_line_portal_type, line = order.newContent(portal_type=self.order_line_portal_type,
resource_value=self.movie_dvd_1, resource_value=self.movie_dvd_1,
quantity=1, quantity=1,
price=3000) price=3000)
self.appendBaseContributionCategory(order_line_2, self.poster_present_1dvd) self.appendBaseContributionCategory(line, poster_present_1dvd)
transaction.commit()
self.stepTic() self.getAggregatedAmountDict(order, partial_check=True,
SPECIAL_DISCOUNT_3CD_OR_1DVD_FIXED=dict(total_price=None, quantity=1,
# check again resource_value=self.poster),
one_free_poster_amount_list = self.getAmount( TOTAL_PRICE_WITHOUT_VAT=dict(total_price=9000),
order, TOTAL_PRICE_WITH_VAT=dict(total_price=9450),
'3CD_OR_1DVD_GET_1_POSTER_FREE', VAT_AMOUNT=dict(total_price=450))
return_object=True)
self.assertEqual(len(one_free_poster_amount_list), 1)
one_free_poster_amount = one_free_poster_amount_list[0]
self.assertEqual(one_free_poster_amount.getTotalPrice(), 0)
self.assertEqual(one_free_poster_amount.getQuantity(), 1)
self.assertEqual(one_free_poster_amount.getPrice(), 0)
self.assertEqual(one_free_poster_amount.getResourceValue(), self.poster)
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITHOUT_VAT'), 9000)
self.assertEqual(self.getAmount(order, 'VAT_AMOUNT'), 450)
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITH_VAT'), 9450)
# even if we buy 3 CDs and 1 DVD, only one poster will be given. # even if we buy 3 CDs and 1 DVD, only one poster will be given.
order_line_3 = order.newContent(portal_type=self.order_line_portal_type, line = order.newContent(portal_type=self.order_line_portal_type,
resource_value=self.music_album_3, resource_value=self.music_album_3,
quantity=1, quantity=1,
price=2400) price=2400)
self.appendBaseContributionCategory(order_line_3, self.poster_present_3cd) self.appendBaseContributionCategory(line, poster_present_3cd)
transaction.commit()
self.stepTic() self.getAggregatedAmountDict(order, partial_check=True,
SPECIAL_DISCOUNT_3CD_OR_1DVD_FIXED=dict(total_price=None, quantity=1,
# check again resource_value=self.poster),
one_free_poster_amount_list = self.getAmount(order, TOTAL_PRICE_WITHOUT_VAT=dict(total_price=11400),
'3CD_OR_1DVD_GET_1_POSTER_FREE', TOTAL_PRICE_WITH_VAT=dict(total_price=11970),
return_object=True) VAT_AMOUNT=dict(total_price=570))
self.assertEqual(len(one_free_poster_amount_list), 1)
one_free_poster_amount = one_free_poster_amount_list[0]
self.assertEqual(one_free_poster_amount.getTotalPrice(), 0)
self.assertEqual(one_free_poster_amount.getQuantity(), 1)
self.assertEqual(one_free_poster_amount.getPrice(), 0)
self.assertEqual(one_free_poster_amount.getResourceValue(), self.poster)
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITHOUT_VAT'), 11400)
self.assertEqual(self.getAmount(order, 'VAT_AMOUNT'), 570)
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITH_VAT'), 11970)
def test_usecase5(self): def test_usecase5(self):
""" """
...@@ -557,156 +417,82 @@ else: ...@@ -557,156 +417,82 @@ else:
1 CD 3000 yen 1 CD 3000 yen
discount 3000 * 0.15 = 450 yen discount 3000 * 0.15 = 450 yen
""" """
createZODBPythonScript( special_discount = self.setBaseAmountQuantityMethod(
self.portal.portal_skins.custom, 'special_discount', """\
'TradeModelLine_calculate3CD15PercentDiscountOf1HighestPricedDVD', def getBaseAmountQuantity(delivery_amount, base_application, **kw):
'current_aggregated_amount_list, current_movement, aggregated_movement_list', highest_price = quantity = 0
'''\ for movement in delivery_amount.getMovementList():
total_quantity = sum([movement.getQuantity() for movement in aggregated_movement_list]) if base_application in movement.getBaseContributionList():
if total_quantity >= 3: quantity += movement.getQuantity()
price_dvd_list = [] if movement.getResourceValue().getProductLine() == 'video/dvd':
product_line_dvd = context.portal_categories.product_line.video.dvd highest_price = max(highest_price, movement.getPrice())
for movement in current_aggregated_amount_list: return quantity >= 3 and highest_price
resource = movement.getResourceValue() return getBaseAmountQuantity""")
if resource.getProductLineValue() == product_line_dvd:
price_dvd_list.append((movement.getPrice(), movement)) trade_condition = self.createTradeCondition(
if price_dvd_list: self.trade_condition, (
price_dvd_list.sort() dict(reference='SPECIAL_DISCOUNT_3CD',
highest_priced_dvd_movement = price_dvd_list[-1][1]
total_price = highest_priced_dvd_movement.getTotalPrice()
from Products.ERP5Type.Document import newTempSimulationMovement
causality_value_list = list(aggregated_movement_list) + [highest_priced_dvd_movement]
temporary_movement = newTempSimulationMovement(current_movement.getParentValue(), current_movement.getId())
temporary_movement.edit(title=current_movement.getProperty('title'),
description=current_movement.getProperty('description'),
resource=current_movement.getProperty('resource'),
reference=current_movement.getProperty('reference'),
int_index=current_movement.getProperty('int_index'),
base_application_list=current_movement.getProperty('base_application_list'),
base_contribution_list=current_movement.getProperty('base_contribution_list'),
start_date=highest_priced_dvd_movement.getStartDate(),
stop_date=highest_priced_dvd_movement.getStopDate(),
create_line=current_movement.getProperty('is_create_line'),
trade_phase_list=current_movement.getTradePhaseList(),
causality_list=[movement.getRelativeUrl() for movement in causality_value_list])
temporary_movement.setPrice(current_movement.getProperty('price'))
temporary_movement.setQuantity(highest_priced_dvd_movement.getPrice())
return temporary_movement
''')
order = self.createOrder()
order.edit(specialise_value=self.trade_condition)
order.Order_applyTradeCondition(order.getSpecialiseValue())
order.newContent(portal_type='Trade Model Line',
reference='3CD_AND_1HIGHEST_PRICED_DVD_15PERCENT_OFF',
resource_value=self.service_discount, resource_value=self.service_discount,
price=-0.15, price=-0.15,
target_level=TARGET_LEVEL_DELIVERY,
calculation_script_id='TradeModelLine_calculate3CD15PercentDiscountOf1HighestPricedDVD',
trade_phase=None,
int_index=0, int_index=0,
base_application_value_list=[self.special_discount_3cd], target_delivery=True,
base_contribution_value_list=[self.discount_amount_of_vat_taxable]) base_application=special_discount,
base_contribution='base_amount/discount_amount_of_vat_taxable'),
order_line_1 = order.newContent(portal_type=self.order_line_portal_type, ))
resource_value=self.movie_dvd_1,
quantity=1, order = self.createOrder(trade_condition, (
price=3000) dict(id='1', price=3000, quantity=1, resource_value=self.movie_dvd_1),
order_line_2 = order.newContent(portal_type=self.order_line_portal_type, dict(id='2', price=1000, quantity=1, resource_value=self.movie_dvd_2),
resource_value=self.movie_dvd_2, dict(id='3', price=5000, quantity=1, resource_value=self.music_album_1),
quantity=1, dict(id='4', price=3000, quantity=1, resource_value=self.music_album_2),
price=1000) ))
order_line_3 = order.newContent(portal_type=self.order_line_portal_type, self.appendBaseContributionCategory(order['3'], special_discount)
resource_value=self.music_album_1, self.appendBaseContributionCategory(order['4'], special_discount)
quantity=1, transaction.commit()
price=5000) self.getAggregatedAmountDict(order, partial_check=True,
self.appendBaseContributionCategory(order_line_3, self.special_discount_3cd) SPECIAL_DISCOUNT_3CD=None,
order_line_4 = order.newContent(portal_type=self.order_line_portal_type, TOTAL_PRICE_WITHOUT_VAT=dict(total_price=12000),
resource_value=self.music_album_2, TOTAL_PRICE_WITH_VAT=dict(total_price=12600),
quantity=1, VAT_AMOUNT=dict(total_price=600))
price=3000)
self.appendBaseContributionCategory(order_line_4, self.special_discount_3cd)
self.stepTic()
# check the current amount
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITHOUT_VAT'), 12000)
self.assertEqual(self.getAmount(order, 'VAT_AMOUNT'), 600)
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITH_VAT'),
12600)
# add one more cd, then total is 3. the special discount will be applied. # add one more cd, then total is 3. the special discount will be applied.
order_line_3.setQuantity(2) order['3'].setQuantity(2)
transaction.commit()
self.stepTic() self.getAggregatedAmountDict(order, partial_check=True,
SPECIAL_DISCOUNT_3CD=dict(total_price=-450),
# check again TOTAL_PRICE_WITHOUT_VAT=dict(total_price=16550),
self.assertEqual(self.getAmount(order, '3CD_AND_1HIGHEST_PRICED_DVD_15PERCENT_OFF'), TOTAL_PRICE_WITH_VAT=dict(total_price=17377.5),
-450) VAT_AMOUNT=dict(total_price=827.5))
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITHOUT_VAT'), 16550)
self.assertEqual(self.getAmount(order, 'VAT_AMOUNT'), 827.5)
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITH_VAT'), 17377.5)
def test_usecase6(self): def test_usecase6(self):
""" """
Use case 6 : Add a shipping fee by TradeModelLine and VAT is charged to Use case 6 : Add a shipping fee by TradeModelLine and VAT is charged to
this fee. this fee.
""" """
order = self.createOrder() fixed_quantity = self.setBaseAmountQuantityMethod('fixed_quantity', """\
order.edit(specialise_value=self.trade_condition) return lambda *args, **kw: 1""")
order.Order_applyTradeCondition(order.getSpecialiseValue())
order.newContent(portal_type='Trade Model Line', trade_condition = self.createTradeCondition(
reference='SHIPPING_FEE', self.trade_condition, (
resource_value=self.service_shipping_fee, dict(reference='SHIPPING_FEE',
price=1, resource_value=self.service_discount,
quantity=500, quantity=500,
target_level=TARGET_LEVEL_DELIVERY,
trade_phase=None,
int_index=0, int_index=0,
base_application_value_list=[], target_delivery=True,
base_contribution_value_list=[self.additional_charge, base_application=fixed_quantity,
self.vat_taxable]) base_contribution_list=('base_amount/additional_charge',
'base_amount/vat_taxable')),
order_line_1 = order.newContent(portal_type=self.order_line_portal_type, ))
resource_value=self.movie_dvd_1,
quantity=1, order = self.createOrder(trade_condition, (
price=3000) dict(id='1', price=3000, quantity=1, resource_value=self.movie_dvd_1),
order_line_2 = order.newContent(portal_type=self.order_line_portal_type, dict(id='2', price=1000, quantity=1, resource_value=self.movie_dvd_2),
resource_value=self.movie_dvd_2, ))
quantity=1, transaction.commit()
price=1000) self.getAggregatedAmountDict(order, partial_check=True,
TOTAL_PRICE_WITHOUT_VAT=dict(total_price=4500),
self.stepTic() TOTAL_PRICE_WITH_VAT=dict(total_price=4725),
VAT_AMOUNT=dict(total_price=225))
# check amounts
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITHOUT_VAT'), 4500)
self.assertEqual(self.getAmount(order, 'VAT_AMOUNT'), 225)
self.assertEqual(
len(self.getAmount(order, 'VAT_AMOUNT', return_object=True)),
1)
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITH_VAT'), 4725)
# change trade model line and calculate vat price per movement
order.newContent(portal_type='Trade Model Line',
title='VAT Amount',
reference='VAT_AMOUNT',
resource_value=self.service_vat,
price=0.05,
target_level=TARGET_LEVEL_MOVEMENT,
trade_phase_value=self.portal.portal_categories.trade_phase.default.invoicing,
int_index=10,
base_application_value_list=[self.discount_amount_of_vat_taxable,
self.vat_taxable],
base_contribution_value_list=[self.vat_amount])
self.stepTic()
# check amounts again
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITHOUT_VAT'), 4500)
self.assertEqual(self.getAmount(order, 'VAT_AMOUNT'), 225)
self.assertEqual(
len(self.getAmount(order, 'VAT_AMOUNT', return_object=True)),
3)
self.assertEqual(self.getAmount(order, 'TOTAL_PRICE_WITH_VAT'), 4725)
class TestComplexTradeModelLineUseCaseSale(TestComplexTradeModelLineUseCase): class TestComplexTradeModelLineUseCaseSale(TestComplexTradeModelLineUseCase):
......
...@@ -56,6 +56,8 @@ class TestTradeModelLineMixin(TestBPMMixin, UserDict): ...@@ -56,6 +56,8 @@ class TestTradeModelLineMixin(TestBPMMixin, UserDict):
"""Provides methods to implementations sharing similar logic to Trade Model Lines""" """Provides methods to implementations sharing similar logic to Trade Model Lines"""
# Constants and variables shared by tests # Constants and variables shared by tests
base_unit_quantity = 0.01 base_unit_quantity = 0.01
node_portal_type = 'Organisation'
order_date = DateTime()
def setBaseAmountQuantityMethod(self, base_amount_id, text): def setBaseAmountQuantityMethod(self, base_amount_id, text):
"""Populate TradeModelLine_getBaseAmountQuantityMethod shared script """Populate TradeModelLine_getBaseAmountQuantityMethod shared script
...@@ -65,10 +67,11 @@ class TestTradeModelLineMixin(TestBPMMixin, UserDict): ...@@ -65,10 +67,11 @@ class TestTradeModelLineMixin(TestBPMMixin, UserDict):
- data produced by previous still behaves as expected - data produced by previous still behaves as expected
""" """
base_amount = self.portal.portal_categories.base_amount base_amount = self.portal.portal_categories.base_amount
for name in self.__class__.__name__, self._testMethodName:
try: try:
base_amount = base_amount[self._testMethodName] base_amount = base_amount[name]
except KeyError: except KeyError:
base_amount = base_amount.newContent(self._testMethodName) base_amount = base_amount.newContent(name)
try: try:
return base_amount[base_amount_id].getRelativeUrl() return base_amount[base_amount_id].getRelativeUrl()
except KeyError: except KeyError:
...@@ -79,7 +82,7 @@ class TestTradeModelLineMixin(TestBPMMixin, UserDict): ...@@ -79,7 +82,7 @@ class TestTradeModelLineMixin(TestBPMMixin, UserDict):
try: try:
old_text = '\n' + skin[script_id].body() old_text = '\n' + skin[script_id].body()
except KeyError: except KeyError:
old_text = "\nreturn context.getBaseAmountQuantity" old_text = ''
else: else:
skin._delObject(script_id) skin._delObject(script_id)
text = test + '\n '.join(text.splitlines()) + old_text text = test + '\n '.join(text.splitlines()) + old_text
...@@ -176,18 +179,28 @@ class TestTradeModelLineMixin(TestBPMMixin, UserDict): ...@@ -176,18 +179,28 @@ class TestTradeModelLineMixin(TestBPMMixin, UserDict):
order.newContent(portal_type=self.order_line_portal_type, **line_kw) order.newContent(portal_type=self.order_line_portal_type, **line_kw)
return order return order
def getAggregatedAmountDict(self, amount_generator, **expected_amount_dict): def getAggregatedAmountDict(self, amount_generator, partial_check=False,
**expected_amount_dict):
amount_list = amount_generator.getAggregatedAmountList() amount_list = amount_generator.getAggregatedAmountList()
amount_dict = {} amount_dict = {}
for amount in amount_list: for amount in amount_list:
reference = amount.getReference() reference = amount.getReference()
try:
expected_amount = expected_amount_dict.pop(reference) expected_amount = expected_amount_dict.pop(reference)
except KeyError:
if not partial_check:
raise
else:
for k, v in expected_amount.iteritems(): for k, v in expected_amount.iteritems():
if k == 'causality_value_list': if k == 'causality_value_list':
self.assertEqual(v, amount.getValueList('causality')) self.assertEqual(v, amount.getValueList('causality'))
else: else:
self.assertEqual(v, amount.getProperty(k)) self.assertEqual(v, amount.getProperty(k))
amount_dict[reference] = amount amount_dict[reference] = amount
if partial_check:
for value in expected_amount_dict.itervalues():
self.assertEqual(None, value)
else:
self.assertEqual({}, expected_amount_dict) self.assertEqual({}, expected_amount_dict)
return amount_dict return amount_dict
...@@ -220,9 +233,6 @@ class TestTradeModelLine(TestTradeModelLineMixin): ...@@ -220,9 +233,6 @@ class TestTradeModelLine(TestTradeModelLineMixin):
new_discount_ratio = -0.04 # -4% new_discount_ratio = -0.04 # -4%
new_tax_ratio = 0.22 # 22% new_tax_ratio = 0.22 # 22%
node_portal_type = 'Organisation'
order_date = DateTime()
modified_order_line_price_ratio = 2.0 modified_order_line_price_ratio = 2.0
modified_packing_list_line_quantity_ratio = 0.4 modified_packing_list_line_quantity_ratio = 0.4
modified_invoice_line_quantity_ratio = modified_order_line_quantity_ratio \ modified_invoice_line_quantity_ratio = modified_order_line_quantity_ratio \
......
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