Commit 6e99f044 authored by Xiaowu Zhang's avatar Xiaowu Zhang

testInventory: add more test

multiple owner test case
multiple cancel packing list test
circular movement test
parent fbda0f1f
......@@ -1231,6 +1231,21 @@ class TestInventory(TestOrderMixin, ERP5TypeTestCase):
LOG('SQL Query was : ', 0, str(simulation.getInventory(src__=1, **kw)))
self.assertEqual(e_inventory, a_inventory, msg)
def _testGetInventoryAssetPrice(self, expected, **kw):
"""
Shared testing method
"""
simulation = self.getPortal().portal_simulation
e_inventory = expected
LOG('Testing inventory with args :', 0, kw)
a_inventory = simulation.getInventoryAssetPrice(**kw)
if e_inventory != a_inventory:
msg = 'Inventory differs between expected (%s) and real (%s) price'\
% (repr(e_inventory), repr(a_inventory))
LOG('TestInventory._testGetInventoryAssetPrice', 0, msg)
LOG('SQL Query was : ', 0, str(simulation.getInventoryAssetPrice(src__=1, **kw)))
self.assertEqual(e_inventory, a_inventory, msg)
def stepTestGetInventoryOnSimulationState(self, sequence=None,
sequence_list=None, **kw):
......@@ -3493,6 +3508,659 @@ class TestInventory(TestOrderMixin, ERP5TypeTestCase):
sequence_list.play(self)
def stepCreateNotVariatedThirdResource(self,sequence=None,
sequence_list=None,
**kw):
"""
Create a third resource with no variation
"""
portal = self.getPortal()
resource_module = portal.getDefaultModule(self.resource_portal_type)
resource = resource_module.newContent(portal_type=self.resource_portal_type)
resource.edit(
title = "NotVariatedThirdResource%s" % resource.getId(),
industrial_phase_list=["phase1", "phase2"],
product_line = 'apparel'
)
sequence.edit(third_resource = resource )
resource_list = sequence.get('resource_list',default=[])
resource_list.append(resource)
sequence.edit( resource_list = resource_list )
def stepCreatePackingList(self, sequence=None,
sequence_list=None, **kw):
"""
Create a single packing_list for Inventory Module testing
"""
node = kw.get('node', None)
section = kw.get('section', None)
resource = kw.get('resource', None)
quantity = kw.get('quantity', 100)
price = kw.get('price', None)
mirror_node = kw.get('mirror_node', None)
mirror_section = kw.get('mirror_section', None)
if mirror_node is None:
mirror_node = sequence.get('mirror_node')
if mirror_section is None:
mirror_section = sequence.get('mirror_section')
packing_list_portal_type = kw.get('packing_list', self.packing_list_portal_type)
packing_list_module = self.getPortal().getDefaultModule(
portal_type=packing_list_portal_type)
packing_list = packing_list_module.newContent(
portal_type=packing_list_portal_type)
if kw.get('start_date', None) is not None:
start_date = stop_date = kw['start_date']
else:
start_date = stop_date = DateTime() - 2
packing_list.edit(
specialise=self.business_process,
source_section_value = mirror_section,
source_value = mirror_node,
destination_section_value = section,
destination_value = node,
start_date = start_date,
stop_date = stop_date,
price_currency = self.price_currency
)
packing_list_line_portal_type = packing_list_portal_type + ' Line'
packing_list_line = packing_list.newContent(
portal_type = packing_list_line_portal_type)
packing_list_line.edit(resource_value = resource,
quantity = quantity,
price = price
)
sequence.edit(packing_list=packing_list)
return packing_list_line
def stepCreateSalePackingListToSectionNodeForFirstResource(self, sequence=None,
sequence_list=None,
**kw):
section = sequence.get('section')
node = sequence.get('node')
resource = sequence.get('resource')
self.stepCreatePackingList(sequence=sequence,
sequence_list=sequence_list,
section = section,
node = node,
resource = resource,
quantity = 100,
packing_list= 'Sale Packing List')
def stepCreateSalePackingListToOtherSectionNodeForFirstResource(self, sequence=None,sequence_list=None,**kw):
section = sequence.get('other_section')
node = sequence.get('node')
resource = sequence.get('resource')
self.stepCreatePackingList(sequence=sequence,
sequence_list=sequence_list,
section = section,
node = node,
resource = resource,
quantity = 200,
packing_list = 'Sale Packing List')
def stepCreatePurchasePackingListForSectionOtherNodeForSecondResource(self, sequence=None,
sequence_list=None,
**kw):
section = sequence.get('section')
node = sequence.get('other_node')
resource = sequence.get('second_resource')
self.stepCreatePackingList(sequence=sequence,
sequence_list=sequence_list,
section = section,
node = node,
resource = resource,
quantity = 50,
packing_list = 'Purchase Packing List')
def stepCreatePurchasePackingListForOtherSectionOtherNodeForThirdResource(self, sequence=None,
sequence_list=None,
**kw):
section = sequence.get('other_section')
node = sequence.get('other_node')
resource = sequence.get('third_resource')
self.stepCreatePackingList(sequence=sequence,
sequence_list=sequence_list,
section = section,
node = node,
resource = resource,
quantity = 30,
packing_list = 'Purchase Packing List')
def stepTestMultipleOwnerNode(self, sequence=None, sequence_list=None, **kw):
first_resource_value = sequence.get('resource')
second_resource_value = sequence.get('second_resource')
third_resource_value = sequence.get('third_resource')
node_value = sequence.get('node')
other_node_value = sequence.get('other_node')
section_value = sequence.get('section')
other_section_value = sequence.get('other_section')
self._testGetInventory(expected=100,
section_uid=section_value.getUid(),
node_uid=node_value.getUid(),
resource_uid=first_resource_value.getUid())
self._testGetInventory(expected=200,
section_uid=other_section_value.getUid(),
node_uid=node_value.getUid(),
resource_uid=first_resource_value.getUid())
self._testGetInventory(expected=50,
section_uid=section_value.getUid(),
node_uid=other_node_value.getUid(),
resource_uid=second_resource_value.getUid())
self._testGetInventory(expected=30,
section_uid=other_section_value.getUid(),
node_uid=other_node_value.getUid(),
resource_uid=third_resource_value.getUid())
def test_19_InventoryMultipleOwner(self, quiet = 0, run=run_all_test):
"""
Test multiple owner with multiple node resource.
The case:
1) movement: section=A,node=C,resource=X,quantity=100
2) movement: section=B,node=C,resource=X, quantity=200
3) movement: section=A,node=D,resource=Y,quantity=50
4) movement: section=B, node=D,reource=Z,quantity=30
[Test]
getInventory(section=A, node=C, resource=X) should return 100
getInventory(section=B, node=C, resource=X) should return 200
getInventory(section=A, node=D, resource=Y) should return 50
getInventory(section=B, node=D, resource=Z) should return 30
"""
if not run: return
sequence_list = SequenceList()
sequence_string = 'CreateOrganisationsForModule \
CreateNotVariatedResource \
CreateNotVariatedSecondResource \
stepCreateNotVariatedThirdResource \
Tic \
CreateSalePackingListToSectionNodeForFirstResource \
Tic \
DeliverPackingList \
Tic \
CreateSalePackingListToOtherSectionNodeForFirstResource \
Tic \
DeliverPackingList \
Tic \
CreatePurchasePackingListForSectionOtherNodeForSecondResource \
Tic \
DeliverPackingList \
Tic \
CreatePurchasePackingListForOtherSectionOtherNodeForThirdResource \
Tic \
DeliverPackingList \
Tic \
TestMultipleOwnerNode \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def stepCreateIPLForModule(self, sequence=None, sequence_list=None, **kw):
node = sequence.get('node')
section = sequence.get('section')
other_node = sequence.get('other_node')
resource = sequence.get('resource')
packing_list_module = self.getPortal().getDefaultModule(
portal_type='Internal Packing List')
packing_list = packing_list_module.newContent(
portal_type='Internal Packing List')
start_date = stop_date = self.start_date_1
#same owner but different warehouse
packing_list.edit(
specialise=self.business_process,
source_section_value = section,
source_value = node,
destination_section_value = section,
destination_value = other_node,
start_date = start_date,
stop_date = stop_date,
price_currency = self.price_currency
)
sequence.edit(packing_list=packing_list)
def stepCreatePackingListLineWithQuantity3(self, sequence=None,
sequence_list=None, **kw):
packing_list = sequence.get('packing_list')
resource_value = sequence.get('resource')
packing_list_line = packing_list.newContent(
portal_type='Internal Packing List Line')
packing_list_line.edit(resource_value = resource_value,
quantity = 3.
)
def stepCreatePackingListLineWithQuantity_3(self, sequence=None,
sequence_list=None, **kw):
packing_list = sequence.get('packing_list')
resource_value = sequence.get('resource')
packing_list_line = packing_list.newContent(
portal_type='Internal Packing List Line')
packing_list_line.edit(resource_value = resource_value,
quantity = -3.
)
def stepCreatePackingListLineWithQuantity30(self, sequence=None,
sequence_list=None, **kw):
packing_list = sequence.get('packing_list')
resource_value = sequence.get('resource')
packing_list_line = packing_list.newContent(
portal_type='Internal Packing List Line')
packing_list_line.edit(resource_value = resource_value,
quantity = 30.
)
def stepCreatePackingListLineWithQuantity_30(self, sequence=None,
sequence_list=None, **kw):
packing_list = sequence.get('packing_list')
resource_value = sequence.get('resource')
packing_list_line = packing_list.newContent(
portal_type='Internal Packing List Line')
packing_list_line.edit(resource_value = resource_value,
quantity = -30.
)
def stepCreatePackingListLineWithQuantity33(self, sequence=None,
sequence_list=None, **kw):
packing_list = sequence.get('packing_list')
resource_value = sequence.get('resource')
packing_list_line = packing_list.newContent(
portal_type='Internal Packing List Line')
packing_list_line.edit(resource_value = resource_value,
quantity = 33.
)
def stepTestMultiCancelInventory(self, sequence=None,
sequence_list=None, **kw):
resource_value = sequence.get('resource')
node_value = sequence.get('node')
other_node_value = sequence.get('other_node')
section_value = sequence.get('section')
at_date = self.start_date_1
self._testGetInventory(
expected=67,
section_uid=section_value.getUid(),
node_uid=node_value.getUid(),
resource_uid=resource_value.getUid(),
at_date=at_date)
self._testGetInventory(
expected=33,
section_uid=section_value.getUid(),
node_uid=other_node_value.getUid(),
resource_uid=resource_value.getUid(),
at_date=at_date)
def test_20_InventoryWhenCancelInternalPackingList(self, quite=0, run=run_all_test):
"""
When Company A's 33 of product G was shipped from warehouse X
to warehouse Y (ownership is still same, just location change)
in real world, an ERP5 user made many mistakes to enter the above
single fact and in the end he created five IPL(Internal Packing List)
to record the single fact.
IPL1 (quantity is wrong)
start_date 2013/Feb/10
source_section A destination_section A
source X destination Y
resource G quantity 3
simulation_state
IPL2 (Cancellation of IPL1)
start_date 2013/Feb/10
source_section A destination_section A
source X destination Y
resource G quantity -3
simulation_state delivered
IPL3 (He made a mistake again!)
start_date 2013/Feb/10
source_section A destination_section A
source X destination Y
resource H quantity 30
simulation_state delivered
IPL4 (Cancellation of IPL3)
start_date 2013/Feb/10
source_section A destination_section A
source X destination Y
resource H quantity -30
simulation_state delivered
IPL5 (Finally he was able to enter data correctly!)
start_date 2013/Feb/10
source_section A destination_section A
source X destination Y
resource G quantity 33
simulation_state delivered
"""
if not run: return
self.start_date_1 = '2013/02/10 00:00:00 GMT+9'
sequence_list = SequenceList()
sequence_string = 'CreateOrganisationsForModule \
CreateNotVariatedResource \
Tic \
CreatePackingListAtTheDate1 \
CreatePackingListLine \
Tic \
DeliverPackingList \
Tic \
CreateIPLForModule \
CreatePackingListLineWithQuantity3 \
Tic \
DeliverPackingList \
Tic \
CreateIPLForModule \
CreatePackingListLineWithQuantity_3 \
Tic \
DeliverPackingList \
Tic \
CreateIPLForModule \
CreatePackingListLineWithQuantity30 \
Tic \
DeliverPackingList \
Tic \
CreateIPLForModule \
CreatePackingListLineWithQuantity_30\
Tic \
DeliverPackingList \
Tic \
CreateIPLForModule \
CreatePackingListLineWithQuantity33 \
Tic \
DeliverPackingList\
Tic \
TestMultiCancelInventory\
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def stepCreateOneMoreSection(self, sequence=None,
sequence_list=None, **kw):
self.stepCreateOrganisation(sequence=sequence,
sequence_list=sequence_list, **kw)
one_more_section = sequence.get('organisation')
sequence.edit(
one_more_section = one_more_section
)
def stepCreateSalePackingListToA(self, sequence=None,
sequence_list=None, **kw):
#A
section = sequence.get('section')
node = sequence.get('node')
resource = sequence.get('resource')
self.stepCreatePackingList(sequence=sequence,
sequence_list=sequence_list,
section = section,
node = node,
resource = resource,
quantity = 10,
price = 100,
packing_list = 'Sale Packing List')
def stepCreatePurchasePackingListForASecond(self, sequence=None,
sequence_list=None, **kw):
#A
section = sequence.get('section')
node = sequence.get('node')
resource = sequence.get('resource')
self.stepCreatePackingList(sequence=sequence,
sequence_list=sequence_list,
section = section,
node = node,
resource = resource,
quantity = 15,
price = 200,
packing_list = 'Purchase Packing List')
def stepCreatePurchasePackingListForAThird(self, sequence=None,
sequence_list=None, **kw):
#A
section = sequence.get('section')
node = sequence.get('node')
resource = sequence.get('resource')
self.stepCreatePackingList(sequence=sequence,
sequence_list=sequence_list,
section = section,
node = node,
resource = resource,
quantity = 20,
price = 200,
packing_list = 'Purchase Packing List')
def stepCreatePurchasePackingListForB(self, sequence=None,
sequence_list=None, **kw):
#B
section = sequence.get('other_section')
node = sequence.get('other_node')
resource = sequence.get('resource')
self.stepCreatePackingList(sequence=sequence,
sequence_list=sequence_list,
section = section,
node = node,
resource = resource,
quantity = 20,
price = 55,
packing_list = 'Purchase Packing List')
def stepCreateSalePackingListFromAToB(self, sequence=None,
sequence_list=None, **kw):
#B
section = sequence.get('other_section')
node = sequence.get('other_node')
resource = sequence.get('resource')
#A
mirror_section = sequence.get('section')
mirror_node = sequence.get('node')
packing_list_line_a_to_b = self.stepCreatePackingList(sequence=sequence,
sequence_list=sequence_list,
section = section,
node = node,
mirror_section = mirror_section,
mirror_node = mirror_node,
resource = resource,
quantity = 30,
packing_list = 'Sale Packing List')
sequence.edit(packing_list_line_a_to_b = packing_list_line_a_to_b)
def stepCreatePurchasePackingListForCFromA(self, sequence=None,
sequence_list=None, **kw):
#C
section = sequence.get('one_more_section')
node = sequence.get('node')
resource = sequence.get('resource')
#A
mirror_section = sequence.get('section')
mirror_node = sequence.get('node')
packing_list_line_a_to_c = self.stepCreatePackingList(sequence=sequence,
sequence_list=sequence_list,
section = section,
node = node,
mirror_section = mirror_section,
mirror_node = mirror_node,
resource = resource,
quantity = 10,
packing_list = 'Purchase Packing List')
sequence.edit(packing_list_line_a_to_c = packing_list_line_a_to_c)
def stepCreatePurchasePackingListForCFromB(self, sequence=None,
sequence_list=None, **kw):
#C
section = sequence.get('one_more_section')
node = sequence.get('node')
resource = sequence.get('resource')
#B
mirror_section = sequence.get('other_section')
mirror_node = sequence.get('other_node')
packing_list_line_b_to_c = self.stepCreatePackingList(sequence=sequence,
sequence_list=sequence_list,
section = section,
node = node,
mirror_section = mirror_section,
mirror_node = mirror_node,
resource = resource,
quantity = 5,
packing_list='Purchase Packing List')
sequence.edit(packing_list_line_b_to_c = packing_list_line_b_to_c)
def stepCreateSalePackingListFromCToA(self, sequence=None,
sequence_list=None, **kw):
#A
section = sequence.get('section')
node = sequence.get('node')
resource = sequence.get('resource')
#C
mirror_section = sequence.get('one_more_section')
mirror_node = sequence.get('node')
packing_list_line_c_to_a = self.stepCreatePackingList(sequence=sequence,
sequence_list=sequence_list,
section = section,
node = node,
mirror_section = mirror_section,
mirror_node = mirror_node,
resource = resource,
quantity = 2,
packing_list = 'Sale Packing List')
sequence.edit(packing_list_line_c_to_a = packing_list_line_c_to_a)
def steptestCircularMovementQuantity(self, sequence=None,
sequence_list=None, **kw):
resource_value = sequence.get('resource')
node_value = sequence.get('node')
other_node_value = sequence.get('other_node')
section_value = sequence.get('section')
other_section_value = sequence.get('other_section')
one_more_section_value = sequence.get('one_more_section')
#C
self._testGetInventory(
expected=13,
section_uid=one_more_section_value.getUid(),
node_uid=node_value.getUid(),
resource_uid=resource_value.getUid()
)
#B
self._testGetInventory(
expected=45,
section_uid=other_section_value.getUid(),
node_uid=other_node_value.getUid(),
resource_uid=resource_value.getUid()
)
#A
self._testGetInventory(
expected=7,
section_uid=section_value.getUid(),
node_uid=node_value.getUid(),
resource_uid=resource_value.getUid()
)
def steptestCircularMovementPrice(self, sequence=None,
sequence_list=None, **kw):
resource_value = sequence.get('resource')
node_value = sequence.get('node')
other_node_value = sequence.get('other_node')
section_value = sequence.get('section')
other_section_value = sequence.get('other_section')
one_more_section_value = sequence.get('one_more_section')
#C
self._testGetInventoryAssetPrice(
expected=160,
section_uid=one_more_section_value.getUid(),
node_uid=node_value.getUid(),
resource_uid=resource_value.getUid(),
valuation_method='WeightedAverage'
)
#B
self._testGetInventoryAssetPrice(
expected=129,
section_uid=other_section_value.getUid(),
node_uid=other_node_value.getUid(),
resource_uid=resource_value.getUid(),
valuation_method='WeightedAverage'
)
#A
self._testGetInventoryAssetPrice(
expected=178,
section_uid=section_value.getUid(),
node_uid=node_value.getUid(),
resource_uid=resource_value.getUid(),
valuation_method='WeightedAverage'
)
def test_21_CircularMovements(self, quite=0, run=run_all_test):
"""
Owner A, warehouse X, product G, quantity 10, total price is 1000
Owner B, warehouse Y, product G, quantity 20, total price is 1100
Owner C, warehouse X, product G, quantity 0 , total price is 0
Then, product G was moved like below:
Owner A purchased 15 of product G for the price of 3000
Owner A purchased 20 of product G for the price of 4000
Owner B purchased 30 of product G from Owner A(price is determined at the end of Nov).
Owner C purchased 10 of product G from Owner A(price is determined at the end of Nov).
Owner C get 5 of product G from Owner B(price is determined at the end of Nov).
Owner A get 2 of product G from Owner C(price is determined at the end of Nov).
As we see in this example, product G was moved between A and B, B and
C, C and A, it is circulating. Then, at the end of Mouth, Price of
product G of Owner A depends on price of product G of owner B, this
kind of thing happens. (And if it is a real circulation, price can't be
decided, it must not happen, but theoretically it can happen.
"""
if not run: return
sequence_list = SequenceList()
sequence_string = 'CreateOrganisationsForModule \
CreateOneMoreSection \
CreateNotVariatedResource \
Tic \
CreateSalePackingListToA \
Tic \
DeliverPackingList \
Tic \
CreatePurchasePackingListForB \
Tic \
DeliverPackingList \
Tic \
CreatePurchasePackingListForASecond \
DeliverPackingList \
Tic \
CreatePurchasePackingListForAThird \
DeliverPackingList \
Tic \
CreateSalePackingListFromAToB\
DeliverPackingList \
Tic \
CreatePurchasePackingListForCFromA\
DeliverPackingList \
Tic \
CreatePurchasePackingListForCFromB\
DeliverPackingList \
Tic \
CreateSalePackingListFromCToA\
DeliverPackingList \
Tic \
steptestCircularMovementQuantity \
Tic \
steptestCircularMovementPrice \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestInventory))
......
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