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,13 +294,10 @@ class AmountGeneratorMixin: ...@@ -293,13 +294,10 @@ 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'] quantity *= (property_dict.get('price') or 1) / \
if base_contribution_set: (property_dict.get('efficiency') or 1)
quantity *= (property_dict.get('price') or 1) / \ for base_contribution in property_dict['base_contribution_set']:
(property_dict.get('efficiency') or 1) base_amount[base_contribution] += quantity
base_amount.updateCache(base_contribution_set, self)
for base_contribution in base_contribution_set:
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,140 +37,114 @@ class TestComplexTradeModelLineUseCase(TestTradeModelLineMixin): ...@@ -39,140 +37,114 @@ 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() reference='TOTAL_PRICE_WITHOUT_VAT',
self.trade_condition.edit( price=1,
int_index=10,
target_delivery=True,
base_application_list=('base_amount/discount_amount_of_non_vat_taxable',
'base_amount/discount_amount_of_vat_taxable',
'base_amount/total_price_of_ordered_items',
'base_amount/additional_charge'),
base_contribution='base_amount/total_price_without_vat'),
dict(title='Total Price Of VAT Taxable',
reference='TOTAL_PRICE_OF_VAT_TAXABLE',
price=1,
int_index=10,
target_delivery=True,
base_application_list=('base_amount/discount_amount_of_vat_taxable',
'base_amount/vat_taxable'),
base_contribution='base_amount/total_price_of_vat_taxable'),
dict(title='Discount Amount',
reference='DISCOUNT_AMOUNT',
resource_value=self.service_discount,
price=1,
trade_phase='default/invoicing',
int_index=10,
target_delivery=True,
base_application_list=('base_amount/discount_amount_of_vat_taxable',
'base_amount/discount_amount_of_non_vat_taxable'),
base_contribution='base_amount/discount_amount'),
dict(title='VAT Amount',
reference='VAT_AMOUNT',
resource_value=self.service_vat,
price=0.05,
trade_phase='default/invoicing',
int_index=10,
target_delivery=True,
base_application_list=('base_amount/discount_amount_of_vat_taxable',
'base_amount/vat_taxable'),
base_contribution='base_amount/vat_amount'),
dict(title='Total Price With VAT',
reference='TOTAL_PRICE_WITH_VAT',
price=1,
int_index=20,
target_delivery=True,
base_application_list=('base_amount/vat_amount',
'base_amount/total_price_without_vat'),
base_contribution='base_amount/total_price_with_vat')
),
source_section_value=my_company, source_section_value=my_company,
source_value=my_company, source_value=my_company,
source_decision_value=my_company, source_decision_value=my_company,
...@@ -180,60 +152,6 @@ class TestComplexTradeModelLineUseCase(TestTradeModelLineMixin): ...@@ -180,60 +152,6 @@ class TestComplexTradeModelLineUseCase(TestTradeModelLineMixin):
destination_value=client_1, destination_value=client_1,
destination_decision_value=client_1, destination_decision_value=client_1,
price_currency_value=jpy) price_currency_value=jpy)
self.trade_condition.newContent(
portal_type='Trade Model Line',
title='Total Price Without VAT',
reference='TOTAL_PRICE_WITHOUT_VAT',
price=1,
trade_phase=None,
int_index=10,
base_application_value_list=[self.discount_amount_of_non_vat_taxable,
self.discount_amount_of_vat_taxable,
self.total_price_of_ordered_items,
self.additional_charge],
base_contribution_value_list=[self.total_price_without_vat])
self.trade_condition.newContent(
portal_type='Trade Model Line',
title='Total Price Of VAT Taxable',
reference='TOTAL_PRICE_OF_VAT_TAXABLE',
price=1,
trade_phase=None,
int_index=10,
base_application_value_list=[self.discount_amount_of_vat_taxable,
self.vat_taxable],
base_contribution_value_list=[self.total_price_of_vat_taxable])
self.trade_condition.newContent(
portal_type='Trade Model Line',
title='Discount Amount',
reference='DISCOUNT_AMOUNT',
resource_value=self.service_discount,
price=1,
trade_phase_value=portal.portal_categories.trade_phase.default.invoicing,
int_index=10,
base_application_value_list=[self.discount_amount_of_vat_taxable,
self.discount_amount_of_non_vat_taxable],
base_contribution_value_list=[self.discount_amount])
self.trade_condition.newContent(
portal_type='Trade Model Line',
title='VAT Amount',
reference='VAT_AMOUNT',
resource_value=self.service_vat,
price=0.05,
trade_phase_value=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.trade_condition.newContent(
portal_type='Trade Model Line',
title='Total Price With VAT',
reference='TOTAL_PRICE_WITH_VAT',
price=1,
trade_phase=None,
int_index=20,
base_application_value_list=[self.vat_amount,
self.total_price_without_vat],
base_contribution_value_list=[self.total_price_with_vat])
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(
""") delivery_amount, base_application, **kw)
order = self.createOrder() return getBaseAmountQuantity""")
order.edit(specialise_value=self.trade_condition)
order.Order_applyTradeCondition(order.getSpecialiseValue()) trade_condition = self.createTradeCondition(
order.newContent(portal_type='Trade Model Line', self.trade_condition, (
reference='3CD_AND_10PERCENT_DISCOUNT_OFF_THEM', 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, target_delivery=True,
base_application_value_list=[self.special_discount_3cd], base_application=special_discount,
base_contribution_value_list=[self.discount_amount_of_vat_taxable]) 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, order = self.createOrder(trade_condition, (
quantity=1, dict(id='1', price=5000, quantity=1, resource_value=self.music_album_1),
price=5000) dict(id='2', price=3000, quantity=1, resource_value=self.music_album_2),
self.appendBaseContributionCategory(order_line_1, self.special_discount_3cd) dict(id='3', price=100, quantity=1, resource_value=self.candy),
order_line_2 = order.newContent(portal_type=self.order_line_portal_type, ))
resource_value=self.music_album_2, self.appendBaseContributionCategory(order['1'], special_discount)
quantity=1, self.appendBaseContributionCategory(order['2'], special_discount)
price=3000) transaction.commit()
self.appendBaseContributionCategory(order_line_2, self.special_discount_3cd) self.getAggregatedAmountDict(order, partial_check=True,
order_line_3 = order.newContent(portal_type=self.order_line_portal_type, SPECIAL_DISCOUNT_3CD_LINEAR=None,
resource_value=self.candy, TOTAL_PRICE_WITHOUT_VAT=dict(total_price=8100),
quantity=1, TOTAL_PRICE_WITH_VAT=dict(total_price=8505),
price=100) 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 resource_value=self.service_discount,
""") price=-1,
order = self.createOrder() quantity=500,
order.edit(specialise_value=self.trade_condition) int_index=0,
order.Order_applyTradeCondition(order.getSpecialiseValue()) target_delivery=True,
order.newContent(portal_type='Trade Model Line', base_application=special_discount,
reference='3CD_AND_500YEN_OFF', base_contribution='base_amount/discount_amount_of_vat_taxable'),
resource_value=self.service_discount, ))
price=1,
target_level=TARGET_LEVEL_DELIVERY, order = self.createOrder(trade_condition, (
calculation_script_id='TradeModelLine_calculate3CD500YenDiscount', dict(id='1', price=5000, quantity=1, resource_value=self.music_album_1),
trade_phase=None, dict(id='2', price=3000, quantity=1, resource_value=self.music_album_2),
int_index=0, dict(id='3', price=3000, quantity=1, resource_value=self.movie_dvd_1),
base_application_value_list=[self.special_discount_3cd], ))
base_contribution_value_list=[self.discount_amount_of_vat_taxable]) self.appendBaseContributionCategory(order['1'], special_discount)
self.appendBaseContributionCategory(order['2'], special_discount)
order_line_1 = order.newContent(portal_type=self.order_line_portal_type, transaction.commit()
resource_value=self.music_album_1, self.getAggregatedAmountDict(order, partial_check=True,
quantity=1, SPECIAL_DISCOUNT_3CD_FIXED=None,
price=5000) TOTAL_PRICE_WITHOUT_VAT=dict(total_price=11000),
self.appendBaseContributionCategory(order_line_1, self.special_discount_3cd) TOTAL_PRICE_WITH_VAT=dict(total_price=11550),
order_line_2 = order.newContent(portal_type=self.order_line_portal_type, VAT_AMOUNT=dict(total_price=550))
resource_value=self.music_album_2,
quantity=1,
price=3000)
self.appendBaseContributionCategory(order_line_2, self.special_discount_3cd)
order_line_3 = order.newContent(portal_type=self.order_line_portal_type,
resource_value=self.movie_dvd_1,
quantity=1,
price=3000)
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()) resource_value=self.service_discount,
order.newContent(portal_type='Trade Model Line', price=-0.1,
reference='3CD_10PERCENT_OFF_FROM_TOTAL', int_index=0,
resource_value=self.service_discount, target_delivery=True,
price=-0.1, base_application=special_discount,
target_level=TARGET_LEVEL_DELIVERY, base_contribution='base_amount/discount_amount_of_vat_taxable'),
calculation_script_id='TradeModelLine_calculate3CD10PercentDiscountFromTotal', ))
trade_phase=None,
int_index=0, order = self.createOrder(trade_condition, (
base_application_value_list=[self.total_price_of_ordered_items], dict(id='1', price=5000, quantity=1, resource_value=self.music_album_1),
base_contribution_value_list=[self.discount_amount_of_vat_taxable]) dict(id='2', price=3000, quantity=1, resource_value=self.movie_dvd_1),
dict(id='3', price=3000, quantity=1, resource_value=self.music_album_2),
order_line_1 = order.newContent(portal_type=self.order_line_portal_type, ))
resource_value=self.music_album_1, self.appendBaseContributionCategory(order['1'], special_discount)
quantity=1, self.appendBaseContributionCategory(order['3'], special_discount)
price=5000) transaction.commit()
self.appendBaseContributionCategory(order_line_1, self.special_discount_3cd) self.getAggregatedAmountDict(order, partial_check=True,
order_line_2 = order.newContent(portal_type=self.order_line_portal_type, SPECIAL_DISCOUNT_3CD_LINEAR=None,
resource_value=self.movie_dvd_1, TOTAL_PRICE_WITHOUT_VAT=dict(total_price=11000),
quantity=1, TOTAL_PRICE_WITH_VAT=dict(total_price=11550),
price=3000) VAT_AMOUNT=dict(total_price=550))
order_line_3 = order.newContent(portal_type=self.order_line_portal_type,
resource_value=self.music_album_2,
quantity=1,
price=3000)
self.appendBaseContributionCategory(order_line_3, self.special_discount_3cd)
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', resource_value=self.poster,
reference='3CD_OR_1DVD_GET_1_POSTER_FREE', price=0,
resource_value=self.poster, int_index=0,
price=0, target_delivery=True,
target_level=TARGET_LEVEL_DELIVERY, base_application=special_discount),
calculation_script_id='TradeModelLine_calculate3CDOr1DVDForPoster', ))
trade_phase=None,
base_application_value_list=[self.poster_present_1dvd, order = self.createOrder(trade_condition, (
self.poster_present_3cd]) dict(id='1', price=3000, quantity=2, resource_value=self.music_album_4),
))
order_line_1 = order.newContent(portal_type=self.order_line_portal_type, self.appendBaseContributionCategory(order['1'], poster_present_3cd)
resource_value=self.music_album_4, transaction.commit()
quantity=2, self.getAggregatedAmountDict(order, partial_check=True,
price=3000) SPECIAL_DISCOUNT_3CD_OR_1DVD_FIXED=None,
self.appendBaseContributionCategory(order_line_1, self.poster_present_3cd) TOTAL_PRICE_WITHOUT_VAT=dict(total_price=6000),
TOTAL_PRICE_WITH_VAT=dict(total_price=6300),
VAT_AMOUNT=dict(total_price=300))
self.stepTic()
# 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] resource_value=self.service_discount,
total_price = highest_priced_dvd_movement.getTotalPrice() price=-0.15,
int_index=0,
from Products.ERP5Type.Document import newTempSimulationMovement target_delivery=True,
causality_value_list = list(aggregated_movement_list) + [highest_priced_dvd_movement] base_application=special_discount,
temporary_movement = newTempSimulationMovement(current_movement.getParentValue(), current_movement.getId()) base_contribution='base_amount/discount_amount_of_vat_taxable'),
temporary_movement.edit(title=current_movement.getProperty('title'), ))
description=current_movement.getProperty('description'),
resource=current_movement.getProperty('resource'), order = self.createOrder(trade_condition, (
reference=current_movement.getProperty('reference'), dict(id='1', price=3000, quantity=1, resource_value=self.movie_dvd_1),
int_index=current_movement.getProperty('int_index'), dict(id='2', price=1000, quantity=1, resource_value=self.movie_dvd_2),
base_application_list=current_movement.getProperty('base_application_list'), dict(id='3', price=5000, quantity=1, resource_value=self.music_album_1),
base_contribution_list=current_movement.getProperty('base_contribution_list'), dict(id='4', price=3000, quantity=1, resource_value=self.music_album_2),
start_date=highest_priced_dvd_movement.getStartDate(), ))
stop_date=highest_priced_dvd_movement.getStopDate(), self.appendBaseContributionCategory(order['3'], special_discount)
create_line=current_movement.getProperty('is_create_line'), self.appendBaseContributionCategory(order['4'], special_discount)
trade_phase_list=current_movement.getTradePhaseList(), transaction.commit()
causality_list=[movement.getRelativeUrl() for movement in causality_value_list]) self.getAggregatedAmountDict(order, partial_check=True,
temporary_movement.setPrice(current_movement.getProperty('price')) SPECIAL_DISCOUNT_3CD=None,
temporary_movement.setQuantity(highest_priced_dvd_movement.getPrice()) TOTAL_PRICE_WITHOUT_VAT=dict(total_price=12000),
return temporary_movement TOTAL_PRICE_WITH_VAT=dict(total_price=12600),
''') VAT_AMOUNT=dict(total_price=600))
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,
price=-0.15,
target_level=TARGET_LEVEL_DELIVERY,
calculation_script_id='TradeModelLine_calculate3CD15PercentDiscountOf1HighestPricedDVD',
trade_phase=None,
int_index=0,
base_application_value_list=[self.special_discount_3cd],
base_contribution_value_list=[self.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,
price=3000)
order_line_2 = order.newContent(portal_type=self.order_line_portal_type,
resource_value=self.movie_dvd_2,
quantity=1,
price=1000)
order_line_3 = order.newContent(portal_type=self.order_line_portal_type,
resource_value=self.music_album_1,
quantity=1,
price=5000)
self.appendBaseContributionCategory(order_line_3, self.special_discount_3cd)
order_line_4 = order.newContent(portal_type=self.order_line_portal_type,
resource_value=self.music_album_2,
quantity=1,
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, int_index=0,
trade_phase=None, target_delivery=True,
int_index=0, base_application=fixed_quantity,
base_application_value_list=[], base_contribution_list=('base_amount/additional_charge',
base_contribution_value_list=[self.additional_charge, 'base_amount/vat_taxable')),
self.vat_taxable]) ))
order_line_1 = order.newContent(portal_type=self.order_line_portal_type, order = self.createOrder(trade_condition, (
resource_value=self.movie_dvd_1, dict(id='1', price=3000, quantity=1, resource_value=self.movie_dvd_1),
quantity=1, dict(id='2', price=1000, quantity=1, resource_value=self.movie_dvd_2),
price=3000) ))
order_line_2 = order.newContent(portal_type=self.order_line_portal_type, transaction.commit()
resource_value=self.movie_dvd_2, self.getAggregatedAmountDict(order, partial_check=True,
quantity=1, TOTAL_PRICE_WITHOUT_VAT=dict(total_price=4500),
price=1000) TOTAL_PRICE_WITH_VAT=dict(total_price=4725),
VAT_AMOUNT=dict(total_price=225))
self.stepTic()
# 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
try: for name in self.__class__.__name__, self._testMethodName:
base_amount = base_amount[self._testMethodName] try:
except KeyError: base_amount = base_amount[name]
base_amount = base_amount.newContent(self._testMethodName) except KeyError:
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,19 +179,29 @@ class TestTradeModelLineMixin(TestBPMMixin, UserDict): ...@@ -176,19 +179,29 @@ 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()
expected_amount = expected_amount_dict.pop(reference) try:
for k, v in expected_amount.iteritems(): expected_amount = expected_amount_dict.pop(reference)
if k == 'causality_value_list': except KeyError:
self.assertEqual(v, amount.getValueList('causality')) if not partial_check:
else: raise
self.assertEqual(v, amount.getProperty(k)) else:
amount_dict[reference] = amount for k, v in expected_amount.iteritems():
self.assertEqual({}, expected_amount_dict) if k == 'causality_value_list':
self.assertEqual(v, amount.getValueList('causality'))
else:
self.assertEqual(v, amount.getProperty(k))
amount_dict[reference] = amount
if partial_check:
for value in expected_amount_dict.itervalues():
self.assertEqual(None, value)
else:
self.assertEqual({}, expected_amount_dict)
return amount_dict return amount_dict
def getTradeModelSimulationMovementList(self, delivery_line): def getTradeModelSimulationMovementList(self, delivery_line):
...@@ -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