Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alecs_myu
erp5
Commits
62b17262
Commit
62b17262
authored
Jul 25, 2012
by
Yusei Tahara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move full inventory related test to TestInventoryDocument and add more tests to it.
parent
d2189e27
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
178 deletions
+121
-178
product/ERP5/tests/testInventoryAPI.py
product/ERP5/tests/testInventoryAPI.py
+121
-178
No files found.
product/ERP5/tests/testInventoryAPI.py
View file @
62b17262
...
...
@@ -457,67 +457,6 @@ class TestInventory(InventoryAPITestCase):
self
.
assertInventoryEquals
(
100
,
resource_category_strict_membership
=
[
'product_line/level1'
])
def
test_ResourceCategoryWithFullInventory
(
self
):
"""Make sure that resource category works when full inventory exists."""
self
.
resource
.
setProductLine
(
'level1/level2'
)
self
.
other_resource
.
setProductLine
(
'anotherlevel'
)
full_inventory1
=
self
.
portal
.
inventory_module
.
newContent
(
portal_type
=
'Inventory'
)
full_inventory1
.
edit
(
destination_section_value
=
self
.
section
,
destination_value
=
self
.
node
,
full_inventory
=
1
,
start_date
=
DateTime
(
'2012/05/18 00:00:00 GMT+9'
))
line11
=
full_inventory1
.
newContent
(
portal_type
=
'Inventory Line'
)
line11
.
setResourceValue
(
self
.
resource
)
line11
.
setQuantity
(
17
)
line12
=
full_inventory1
.
newContent
(
portal_type
=
'Inventory Line'
)
line12
.
setResourceValue
(
self
.
other_resource
)
line12
.
setQuantity
(
13
)
full_inventory1
.
deliver
()
self
.
commit
()
self
.
tic
()
self
.
assertInventoryEquals
(
17
,
resource_uid
=
self
.
resource
.
getUid
()
)
self
.
assertInventoryEquals
(
13
,
resource_uid
=
self
.
other_resource
.
getUid
()
)
self
.
assertInventoryEquals
(
17
,
section_uid
=
self
.
section
.
getUid
(),
node_uid
=
self
.
node
.
getUid
(),
resource_uid
=
self
.
resource
.
getUid
()
)
self
.
assertInventoryEquals
(
13
,
section_uid
=
self
.
section
.
getUid
(),
node_uid
=
self
.
node
.
getUid
(),
resource_uid
=
self
.
other_resource
.
getUid
()
)
self
.
assertInventoryEquals
(
17
,
resource_category
=
'product_line/level1'
)
self
.
assertInventoryEquals
(
13
,
resource_category
=
'product_line/anotherlevel'
)
# In reality this is not an expected failure, I will remove this very soon.(Yusei)
expectedFailure
(
self
.
assertInventoryEquals
)(
17
,
section_uid
=
self
.
section
.
getUid
(),
node_uid
=
self
.
node
.
getUid
(),
resource_category
=
'product_line/level1'
)
self
.
assertInventoryEquals
(
13
,
section_uid
=
self
.
section
.
getUid
(),
node_uid
=
self
.
node
.
getUid
(),
resource_category
=
'product_line/anotherlevel'
)
def
test_PaymentCategory
(
self
):
"""Tests inventory on payment_category """
# for now, BankAccount have a product_line category, so we can use this for
...
...
@@ -2428,6 +2367,90 @@ class TestInventoryDocument(InventoryAPITestCase):
self
.
getInventory
(
optimisation__
=
False
,
**
inventory_kw
))
def
setUpDefaultInventoryCalculationList
(
self
):
createZODBPythonScript
(
self
.
portal
.
portal_skins
.
custom
,
'Inventory_getDefaultInventoryCalculationList'
,
''
,
'''return ({
'inventory_params':{
'section_uid':context.getDestinationSectionUid(),
'node_uid':context.getDestinationUid(),
'group_by_variation':1,
'group_by_resource':1},
'list_method':'getMovementList',
'first_level':({'key':'resource_relative_url',
'getter':'getResource',
'setter':('appendToCategoryList', 'resource')},
{'key':'variation_text',
'getter':'getVariationText',
'setter':'splitAndExtendToCategoryList'},
),
},)
'''
)
self
.
commit
()
def
clearAllInventoryAndSetUpTwoInventory
(
self
):
self
.
portal
.
inventory_module
.
manage_delObjects
(
list
(
self
.
portal
.
inventory_module
.
objectIds
()))
self
.
folder
.
manage_delObjects
(
list
(
self
.
folder
.
objectIds
()))
self
.
resource
.
setProductLine
(
'level1/level2'
)
self
.
other_resource
.
setProductLine
(
'anotherlevel'
)
self
.
section
.
setGroup
(
'level1/level2'
)
self
.
other_section
.
setGroup
(
'anotherlevel'
)
self
.
node
.
setRegion
(
'level1'
)
self
.
other_node
.
setGroup
(
'anotherlevel'
)
full_inventory
=
self
.
portal
.
inventory_module
.
newContent
(
portal_type
=
'Inventory'
)
full_inventory
.
edit
(
destination_section_value
=
self
.
section
,
destination_value
=
self
.
node
,
full_inventory
=
1
,
start_date
=
DateTime
(
'2012/05/18 00:00:00 GMT+9'
))
line
=
full_inventory
.
newContent
(
portal_type
=
'Inventory Line'
)
line
.
setResourceValue
(
self
.
resource
)
line
.
setQuantity
(
1
)
line
=
full_inventory
.
newContent
(
portal_type
=
'Inventory Line'
)
line
.
setResourceValue
(
self
.
other_resource
)
line
.
setQuantity
(
10
)
full_inventory
.
deliver
()
full_inventory
=
self
.
portal
.
inventory_module
.
newContent
(
portal_type
=
'Inventory'
)
full_inventory
.
edit
(
destination_section_value
=
self
.
other_section
,
destination_value
=
self
.
node
,
full_inventory
=
1
,
start_date
=
DateTime
(
'2012/05/18 00:00:00 GMT+9'
))
line
=
full_inventory
.
newContent
(
portal_type
=
'Inventory Line'
)
line
.
setResourceValue
(
self
.
resource
)
line
.
setQuantity
(
100
)
line
=
full_inventory
.
newContent
(
portal_type
=
'Inventory Line'
)
line
.
setResourceValue
(
self
.
other_resource
)
line
.
setQuantity
(
1000
)
full_inventory
.
deliver
()
full_inventory
=
self
.
portal
.
inventory_module
.
newContent
(
portal_type
=
'Inventory'
)
full_inventory
.
edit
(
destination_section_value
=
self
.
section
,
destination_value
=
self
.
other_node
,
full_inventory
=
1
,
start_date
=
DateTime
(
'2012/05/18 00:00:00 GMT+9'
))
line
=
full_inventory
.
newContent
(
portal_type
=
'Inventory Line'
)
line
.
setResourceValue
(
self
.
resource
)
line
.
setQuantity
(
10000
)
line
=
full_inventory
.
newContent
(
portal_type
=
'Inventory Line'
)
line
.
setResourceValue
(
self
.
other_resource
)
line
.
setQuantity
(
100000
)
full_inventory
.
deliver
()
full_inventory
=
self
.
portal
.
inventory_module
.
newContent
(
portal_type
=
'Inventory'
)
full_inventory
.
edit
(
destination_section_value
=
self
.
other_section
,
destination_value
=
self
.
other_node
,
full_inventory
=
1
,
start_date
=
DateTime
(
'2012/05/18 00:00:00 GMT+9'
))
line
=
full_inventory
.
newContent
(
portal_type
=
'Inventory Line'
)
line
.
setResourceValue
(
self
.
resource
)
line
.
setQuantity
(
1000000
)
line
=
full_inventory
.
newContent
(
portal_type
=
'Inventory Line'
)
line
.
setResourceValue
(
self
.
other_resource
)
line
.
setQuantity
(
10000000
)
full_inventory
.
deliver
()
self
.
commit
()
self
.
tic
()
def
test_01_CurrentInventoryWithFullInventory
(
self
):
"""
Check that inventory optimisation is executed when querying current
...
...
@@ -2742,126 +2765,46 @@ class TestInventoryDocument(InventoryAPITestCase):
optimisation__
=
False
,
mirror_uid
=
self
.
mirror_node
.
getUid
())])
@
expectedFailure
def
test_MultipleSectionAndFullInventory
(
self
):
"""Make sure that getInventoryList works in the situation which
two sections use the same node and one section has full inventory for
the node.
"""
def
test_ResourceCategory
(
self
):
"""Make sure that resource category works when full inventory exists."""
# In this test we do not need doucments made by afterSetUp.
self
.
portal
.
inventory_module
.
manage_delObjects
(
list
(
self
.
portal
.
inventory_module
.
objectIds
()))
self
.
folder
.
manage_delObjects
(
list
(
self
.
folder
.
objectIds
()))
self
.
commit
()
self
.
tic
()
createZODBPythonScript
(
self
.
portal
.
portal_skins
.
custom
,
'Inventory_getDefaultInventoryCalculationList'
,
''
,
'''return ({
'inventory_params':{
'section_uid':context.getDestinationSectionUid(),
'node_uid':context.getDestinationUid(),
'group_by_variation':1,
'group_by_resource':1},
'list_method':'getMovementList',
'first_level':({'key':'resource_relative_url',
'getter':'getResource',
'setter':('appendToCategoryList', 'resource')},
{'key':'variation_text',
'getter':'getVariationText',
'setter':'splitAndExtendToCategoryList'},
),
},)
'''
)
self
.
commit
()
getCurrentInventoryList
=
self
.
getSimulationTool
().
getCurrentInventoryList
# Add movements for section
self
.
_makeMovement
(
source_section_value
=
None
,
source_value
=
None
,
destination_section_value
=
self
.
section
,
destination_value
=
self
.
node
,
start_date
=
DateTime
(
'2012/07/18 00:00:00 GMT+9'
),
simulation_state
=
'delivered'
,
resource_value
=
self
.
resource
,
quantity
=
1
)
self
.
_makeMovement
(
source_section_value
=
None
,
source_value
=
None
,
destination_section_value
=
self
.
section
,
destination_value
=
self
.
node
,
start_date
=
DateTime
(
'2012/07/21 00:00:00 GMT+9'
),
simulation_state
=
'delivered'
,
resource_value
=
self
.
resource
,
quantity
=
2
)
# Add movemnets for other section
self
.
_makeMovement
(
source_section_value
=
None
,
source_value
=
None
,
destination_section_value
=
self
.
other_section
,
destination_value
=
self
.
node
,
start_date
=
DateTime
(
'2012/07/19 00:00:00 GMT+9'
),
simulation_state
=
'delivered'
,
resource_value
=
self
.
resource
,
quantity
=
3
)
self
.
_makeMovement
(
source_section_value
=
None
,
source_value
=
None
,
destination_section_value
=
self
.
other_section
,
destination_value
=
self
.
node
,
start_date
=
DateTime
(
'2012/07/20 00:00:00 GMT+9'
),
simulation_state
=
'delivered'
,
resource_value
=
self
.
resource
,
quantity
=
4
)
self
.
commit
()
self
.
tic
()
# Check inventory
result
=
{}
for
brain
in
getCurrentInventoryList
(
node_uid
=
self
.
node
.
getUid
(),
group_by_resource
=
1
,
group_by_node
=
1
,
group_by_section
=
1
):
key
=
(
brain
.
section_uid
,
brain
.
node_uid
,
brain
.
resource_uid
)
if
not
key
in
result
:
result
[
key
]
=
0
result
[
key
]
=
result
[
key
]
+
brain
.
inventory
self
.
assertEqual
(
result
,
{(
self
.
section
.
getUid
(),
self
.
node
.
getUid
(),
self
.
resource
.
getUid
()):
3
,
(
self
.
other_section
.
getUid
(),
self
.
node
.
getUid
(),
self
.
resource
.
getUid
()):
7
})
# Add full inventory for section, not for other section
full_inventory1
=
self
.
portal
.
inventory_module
.
newContent
(
portal_type
=
'Inventory'
)
full_inventory1
.
edit
(
destination_section_value
=
self
.
section
,
destination_value
=
self
.
node
,
full_inventory
=
1
,
start_date
=
DateTime
(
'2012/07/20 00:00:00 GMT+9'
))
line
=
full_inventory1
.
newContent
(
portal_type
=
'Inventory Line'
)
line
.
setResourceValue
(
self
.
resource
)
line
.
setQuantity
(
100
)
full_inventory1
.
deliver
()
self
.
commit
()
self
.
tic
()
# Check inventory again. This time, full inventory should change
# section's inventory. It should not change other section's inventory.
result
=
{}
for
brain
in
getCurrentInventoryList
(
node_uid
=
self
.
node
.
getUid
(),
group_by_resource
=
1
,
group_by_node
=
1
,
group_by_section
=
1
):
key
=
(
brain
.
section_uid
,
brain
.
node_uid
,
brain
.
resource_uid
)
if
not
key
in
result
:
result
[
key
]
=
0
result
[
key
]
=
result
[
key
]
+
brain
.
inventory
self
.
setUpDefaultInventoryCalculationList
()
self
.
clearAllInventoryAndSetUpTwoInventory
()
self
.
assertEquals
(
1
,
self
.
getInventory
(
section_uid
=
self
.
section
.
getUid
(),
node_uid
=
self
.
node
.
getUid
(),
resource_category
=
'product_line/level1'
,
optimisation__
=
False
))
self
.
assertEquals
(
1
,
self
.
getInventory
(
section_uid
=
self
.
section
.
getUid
(),
node_uid
=
self
.
node
.
getUid
(),
resource_category
=
'product_line/level1'
,
optimisation__
=
True
))
self
.
assertEqual
(
result
,
{(
self
.
section
.
getUid
(),
self
.
node
.
getUid
(),
self
.
resource
.
getUid
()):
102
,
(
self
.
other_section
.
getUid
(),
self
.
node
.
getUid
(),
self
.
resource
.
getUid
()):
7
})
def
test_SectionCategory
(
self
):
"""Make sure that section category works when full inventory exists."""
# In this test we do not need doucments made by afterSetUp.
self
.
clearAllInventoryAndSetUpTwoInventory
()
self
.
assertEquals
(
11
,
self
.
getInventory
(
node_uid
=
self
.
node
.
getUid
(),
section_category
=
'group/level1/level2'
,
optimisation__
=
False
))
self
.
assertEquals
(
11
,
self
.
getInventory
(
node_uid
=
self
.
node
.
getUid
(),
section_category
=
'group/level1/level2'
,
optimisation__
=
True
))
def
test_NodeCategory
(
self
):
# In this test we do not need doucments made by afterSetUp.
self
.
clearAllInventoryAndSetUpTwoInventory
()
self
.
assertEquals
(
11
,
self
.
getInventory
(
section_uid
=
self
.
section
.
getUid
(),
node_category
=
'region/level1'
,
optimisation__
=
False
))
self
.
assertEquals
(
11
,
self
.
getInventory
(
section_uid
=
self
.
section
.
getUid
(),
node_category
=
'region/level1'
,
optimisation__
=
True
))
class
BaseTestUnitConversion
(
InventoryAPITestCase
):
QUANTITY_UNIT_DICT
=
{}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment