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
Thomas Gambier
erp5
Commits
14a7dc8e
Commit
14a7dc8e
authored
Sep 15, 2020
by
Arnaud Fontaine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testInventoryAPI: Fix pylint warnings.
parent
4a358ddd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
77 deletions
+63
-77
product/ERP5/tests/testInventoryAPI.py
product/ERP5/tests/testInventoryAPI.py
+63
-77
No files found.
product/ERP5/tests/testInventoryAPI.py
View file @
14a7dc8e
...
...
@@ -741,7 +741,7 @@ class TestInventory(InventoryAPITestCase):
# sum([0.1] * 10) != 1.0 but this is not a problem here
getInventoryAssetPrice
=
self
.
getSimulationTool
().
getInventoryAssetPrice
self
.
_makeMovement
(
quantity
=
1
,
price
=
1
)
for
i
in
range
(
10
):
for
_
in
range
(
10
):
self
.
_makeMovement
(
quantity
=-
0.1
,
price
=
1
)
self
.
assertInventoryEquals
(
0
,
precision
=
2
,
node_uid
=
self
.
node
.
getUid
())
self
.
assertEqual
(
0
,
getInventoryAssetPrice
(
precision
=
2
,
...
...
@@ -1009,8 +1009,8 @@ class TestInventoryList(InventoryAPITestCase):
getInventoryList
=
self
.
getSimulationTool
().
getInventoryList
self
.
section
.
setGroup
(
'level1'
)
self
.
other_section
.
setGroup
(
'level1'
)
m1
=
self
.
_makeMovement
(
quantity
=
2
)
m2
=
self
.
_makeMovement
(
destination_section_value
=
self
.
other_section
,
quantity
=
3
)
self
.
_makeMovement
(
quantity
=
2
)
self
.
_makeMovement
(
destination_section_value
=
self
.
other_section
,
quantity
=
3
)
inventory_list
=
getInventoryList
(
node_uid
=
self
.
node
.
getUid
(),
section_category
=
'group/level1'
,
...
...
@@ -1026,8 +1026,8 @@ class TestInventoryList(InventoryAPITestCase):
getInventoryList
=
self
.
getSimulationTool
().
getInventoryList
self
.
section
.
setGroup
(
'level1'
)
self
.
other_section
.
setGroup
(
'level1'
)
m1
=
self
.
_makeMovement
(
quantity
=
2
)
m2
=
self
.
_makeMovement
(
destination_section_value
=
self
.
other_section
,
quantity
=
3
)
self
.
_makeMovement
(
quantity
=
2
)
self
.
_makeMovement
(
destination_section_value
=
self
.
other_section
,
quantity
=
3
)
inventory_list
=
getInventoryList
(
node_uid
=
self
.
node
.
getUid
(),
section_category
=
'group/level1'
,
...
...
@@ -1412,8 +1412,8 @@ class TestInventoryList(InventoryAPITestCase):
#source_payment_value=self.payment_node,
#destination_payment_value=self.other_payment_node,
simulation_state
=
simulation_state
)
def
checkInventory
(
line
=
0
,
type
=
'Current'
,
destination
=
0
,
source
=
0
,
quantity
=
None
):
method
=
getattr
(
self
.
getSimulationTool
(),
'get%sInventoryList'
%
type
)
def
checkInventory
(
line
=
0
,
type
_
=
'Current'
,
destination
=
0
,
source
=
0
,
quantity
=
None
):
method
=
getattr
(
self
.
getSimulationTool
(),
'get%sInventoryList'
%
type
_
)
if
source
:
node_uid
=
self
.
node
.
getUid
()
if
destination
:
...
...
@@ -1424,24 +1424,24 @@ class TestInventoryList(InventoryAPITestCase):
self
.
assertEqual
(
sum
([
x
.
total_quantity
for
x
in
inventory_list
]),
quantity
)
makeMovement
(
quantity
=
1
,
simulation_state
=
'ordered'
)
checkInventory
(
line
=
0
,
type
=
'Current'
,
destination
=
1
)
checkInventory
(
line
=
0
,
type
=
'Available'
,
destination
=
1
)
checkInventory
(
line
=
1
,
type
=
'Future'
,
source
=
1
,
quantity
=-
1
)
checkInventory
(
line
=
1
,
type
=
'Future'
,
destination
=
1
,
quantity
=
1
)
checkInventory
(
line
=
0
,
type
_
=
'Current'
,
destination
=
1
)
checkInventory
(
line
=
0
,
type
_
=
'Available'
,
destination
=
1
)
checkInventory
(
line
=
1
,
type
_
=
'Future'
,
source
=
1
,
quantity
=-
1
)
checkInventory
(
line
=
1
,
type
_
=
'Future'
,
destination
=
1
,
quantity
=
1
)
makeMovement
(
quantity
=
3
,
simulation_state
=
'confirmed'
)
checkInventory
(
line
=
0
,
type
=
'Current'
,
source
=
1
)
checkInventory
(
line
=
0
,
type
=
'Current'
,
destination
=
1
)
checkInventory
(
line
=
1
,
type
=
'Available'
,
source
=
1
,
quantity
=-
3
)
checkInventory
(
line
=
0
,
type
=
'Available'
,
destination
=
1
)
checkInventory
(
line
=
2
,
type
=
'Future'
,
source
=
1
,
quantity
=-
4
)
checkInventory
(
line
=
2
,
type
=
'Future'
,
destination
=
1
,
quantity
=
4
)
checkInventory
(
line
=
0
,
type
_
=
'Current'
,
source
=
1
)
checkInventory
(
line
=
0
,
type
_
=
'Current'
,
destination
=
1
)
checkInventory
(
line
=
1
,
type
_
=
'Available'
,
source
=
1
,
quantity
=-
3
)
checkInventory
(
line
=
0
,
type
_
=
'Available'
,
destination
=
1
)
checkInventory
(
line
=
2
,
type
_
=
'Future'
,
source
=
1
,
quantity
=-
4
)
checkInventory
(
line
=
2
,
type
_
=
'Future'
,
destination
=
1
,
quantity
=
4
)
makeMovement
(
quantity
=
5
,
simulation_state
=
'started'
)
checkInventory
(
line
=
1
,
type
=
'Current'
,
source
=
1
,
quantity
=-
5
)
checkInventory
(
line
=
0
,
type
=
'Current'
,
destination
=
1
)
checkInventory
(
line
=
2
,
type
=
'Available'
,
source
=
1
,
quantity
=-
8
)
checkInventory
(
line
=
0
,
type
=
'Available'
,
destination
=
1
)
checkInventory
(
line
=
3
,
type
=
'Future'
,
source
=
1
,
quantity
=-
9
)
checkInventory
(
line
=
3
,
type
=
'Future'
,
destination
=
1
,
quantity
=
9
)
checkInventory
(
line
=
1
,
type
_
=
'Current'
,
source
=
1
,
quantity
=-
5
)
checkInventory
(
line
=
0
,
type
_
=
'Current'
,
destination
=
1
)
checkInventory
(
line
=
2
,
type
_
=
'Available'
,
source
=
1
,
quantity
=-
8
)
checkInventory
(
line
=
0
,
type
_
=
'Available'
,
destination
=
1
)
checkInventory
(
line
=
3
,
type
_
=
'Future'
,
source
=
1
,
quantity
=-
9
)
checkInventory
(
line
=
3
,
type
_
=
'Future'
,
destination
=
1
,
quantity
=
9
)
def
test_node_selection_domain
(
self
):
self
.
node
.
setSite
(
'site1'
)
...
...
@@ -1468,12 +1468,12 @@ class TestInventoryList(InventoryAPITestCase):
getInventoryList
=
self
.
getSimulationTool
().
getInventoryList
ledger_accounting_category
=
self
.
portal
.
portal_categories
.
ledger
.
accounting
self
.
node
.
setGroup
(
'level1'
)
movement1
=
self
.
_makeMovement
(
self
.
_makeMovement
(
ledger_value
=
ledger_accounting_category
.
general
,
destination_value
=
None
,
quantity
=
2
,
)
movement2
=
self
.
_makeMovement
(
self
.
_makeMovement
(
ledger_value
=
ledger_accounting_category
.
detailed
,
destination_value
=
None
,
source_value
=
self
.
node
,
...
...
@@ -1797,7 +1797,7 @@ class TestMovementHistoryList(InventoryAPITestCase):
getMovementHistoryList
=
self
.
getSimulationTool
().
getMovementHistoryList
start_date
=
DateTime
(
2001
,
1
,
1
)
stop_date
=
DateTime
(
2002
,
2
,
2
)
mvt
=
self
.
_makeMovement
(
quantity
=
100
,
self
.
_makeMovement
(
quantity
=
100
,
start_date
=
start_date
,
stop_date
=
stop_date
)
# start_date is for source
...
...
@@ -1827,10 +1827,9 @@ class TestMovementHistoryList(InventoryAPITestCase):
def
testResource
(
self
):
getMovementHistoryList
=
self
.
getSimulationTool
().
getMovementHistoryList
mvt
=
self
.
_makeMovement
(
quantity
=
100
)
self
.
_makeMovement
(
quantity
=
100
)
another_resource
=
self
.
_makeResource
()
another_mvt
=
self
.
_makeMovement
(
quantity
=
3
,
resource_value
=
another_resource
)
self
.
_makeMovement
(
quantity
=
3
,
resource_value
=
another_resource
)
# we can query resource directly by uid
mvt_history_list
=
getMovementHistoryList
(
node_uid
=
self
.
node
.
getUid
(),
...
...
@@ -1851,7 +1850,7 @@ class TestMovementHistoryList(InventoryAPITestCase):
def
testSectionCategory
(
self
):
getMovementHistoryList
=
self
.
getSimulationTool
().
getMovementHistoryList
self
.
section
.
setGroup
(
'level1/level2'
)
mvt
=
self
.
_makeMovement
(
quantity
=
100
)
self
.
_makeMovement
(
quantity
=
100
)
# for section category, both exact category or any parent category works
# section_category can also be a list.
...
...
@@ -1875,7 +1874,7 @@ class TestMovementHistoryList(InventoryAPITestCase):
# it is currently invalid to pass the same category twice to inventory API
getMovementHistoryList
=
self
.
getSimulationTool
().
getMovementHistoryList
self
.
section
.
setGroup
(
'level1/level2'
)
mvt
=
self
.
_makeMovement
(
quantity
=
100
)
self
.
_makeMovement
(
quantity
=
100
)
movement_history_list
=
getMovementHistoryList
(
section_category
=
[
'group/level1'
,
'group/level1/level2'
])
...
...
@@ -1887,7 +1886,7 @@ class TestMovementHistoryList(InventoryAPITestCase):
getMovementHistoryList
=
self
.
getSimulationTool
().
getMovementHistoryList
self
.
section
.
setGroup
(
'level1/level2'
)
self
.
node
.
setGroup
(
'level1'
)
mvt
=
self
.
_makeMovement
(
quantity
=
100
)
self
.
_makeMovement
(
quantity
=
100
)
valid_category_list
=
[
'group/level1'
,
[
'group/level1'
,
'group/anotherlevel'
],
...
...
@@ -1923,8 +1922,8 @@ class TestMovementHistoryList(InventoryAPITestCase):
getMovementHistoryList
=
self
.
getSimulationTool
().
getMovementHistoryList
ledger
=
self
.
portal
.
portal_categories
.
ledger
mvt
=
self
.
_makeMovement
(
quantity
=
100
,
ledger
=
"accounting/general"
)
another_mvt
=
self
.
_makeMovement
(
quantity
=
50
,
ledger
=
"accounting/detailed"
)
self
.
_makeMovement
(
quantity
=
100
,
ledger
=
"accounting/general"
)
self
.
_makeMovement
(
quantity
=
50
,
ledger
=
"accounting/detailed"
)
# first ledger
mvt_history_list
=
getMovementHistoryList
(
...
...
@@ -2129,7 +2128,7 @@ class TestMovementHistoryList(InventoryAPITestCase):
def
test_Limit
(
self
):
getMovementHistoryList
=
self
.
getSimulationTool
().
getMovementHistoryList
for
q
in
range
(
6
):
for
_
in
range
(
6
):
self
.
_makeMovement
(
quantity
=
1
)
self
.
assertEqual
(
3
,
len
(
getMovementHistoryList
(
limit
=
3
)))
self
.
assertEqual
(
4
,
len
(
getMovementHistoryList
(
limit
=
(
1
,
4
))))
...
...
@@ -2278,7 +2277,7 @@ class TestMovementHistoryList(InventoryAPITestCase):
def
testSameNodeDifferentDates
(
self
):
getMovementHistoryList
=
self
.
getSimulationTool
().
getMovementHistoryList
date
=
DateTime
()
mvt
=
self
.
_makeMovement
(
quantity
=
2
,
self
.
_makeMovement
(
quantity
=
2
,
start_date
=
date
,
stop_date
=
date
+
1
,
source_value
=
self
.
node
,
...
...
@@ -2291,10 +2290,10 @@ class TestMovementHistoryList(InventoryAPITestCase):
def
testSameNodeSameDates
(
self
):
getMovementHistoryList
=
self
.
getSimulationTool
().
getMovementHistoryList
mvt
=
self
.
_makeMovement
(
quantity
=
2
,
self
.
_makeMovement
(
quantity
=
2
,
start_date
=
DateTime
(),
source_value
=
self
.
node
,
destination_value
=
self
.
node
)
destination_value
=
self
.
node
)
mvt_history_list
=
getMovementHistoryList
(
node_uid
=
self
.
node
.
getUid
(),)
self
.
assertEqual
(
2
,
len
(
mvt_history_list
))
...
...
@@ -2302,12 +2301,12 @@ class TestMovementHistoryList(InventoryAPITestCase):
def
testSameNodeSameDatesSameSections
(
self
):
getMovementHistoryList
=
self
.
getSimulationTool
().
getMovementHistoryList
mvt
=
self
.
_makeMovement
(
quantity
=
2
,
self
.
_makeMovement
(
quantity
=
2
,
start_date
=
DateTime
(),
source_value
=
self
.
node
,
destination_value
=
self
.
node
,
source_section_value
=
self
.
section
,
destination_section_value
=
self
.
section
,
)
destination_section_value
=
self
.
section
)
# For now, if you want to get movements from same node, same dates, same
# sections, you have to pass ignore_group_by=True to ignore default
# grouping.
...
...
@@ -2381,8 +2380,8 @@ class TestMovementHistoryList(InventoryAPITestCase):
def
test_OmitAssetIncreaseDecrease
(
self
):
getMovementHistoryList
=
self
.
getSimulationTool
().
getMovementHistoryList
m1
=
self
.
_makeMovement
(
quantity
=
1
,
price
=-
1
)
m2
=
self
.
_makeMovement
(
quantity
=-
1
,
price
=-
1
)
self
.
_makeMovement
(
quantity
=
1
,
price
=-
1
)
self
.
_makeMovement
(
quantity
=-
1
,
price
=-
1
)
mvt_history_list
=
getMovementHistoryList
(
node_uid
=
self
.
node
.
getUid
(),
omit_asset_increase
=
1
)
self
.
assertEqual
(
1
,
len
(
mvt_history_list
))
...
...
@@ -2519,10 +2518,10 @@ class TestMovementHistoryList(InventoryAPITestCase):
m2
=
delivery
.
newContent
(
portal_type
=
'Dummy Movement'
,
quantity
=
1
,
price
=
2
,
resource_value
=
self
.
resource
,
start_date
=
DateTime
(
2010
,
1
,
1
))
m3
=
delivery
.
newContent
(
portal_type
=
'Dummy Movement'
,
quantity
=
1
,
delivery
.
newContent
(
portal_type
=
'Dummy Movement'
,
quantity
=
1
,
price
=
7
,
resource_value
=
self
.
other_resource
,
start_date
=
DateTime
(
2010
,
1
,
2
))
self
.
commit
()
;
self
.
commit
()
self
.
tic
()
# sanity check, our fake movements are all created in the same delivery,
# and have a valid explanation uid
...
...
@@ -2583,12 +2582,12 @@ class TestMovementHistoryList(InventoryAPITestCase):
getMovementHistoryList
=
self
.
getSimulationTool
().
getMovementHistoryList
ledger_accounting_category
=
self
.
portal
.
portal_categories
.
ledger
.
accounting
self
.
node
.
setGroup
(
'level1'
)
movement1
=
self
.
_makeMovement
(
self
.
_makeMovement
(
ledger_value
=
ledger_accounting_category
.
general
,
destination_value
=
None
,
quantity
=
2
,
)
movement2
=
self
.
_makeMovement
(
self
.
_makeMovement
(
ledger_value
=
ledger_accounting_category
.
detailed
,
destination_value
=
None
,
source_value
=
self
.
node
,
...
...
@@ -2842,9 +2841,6 @@ class TestTrackingList(InventoryAPITestCase):
item_a
=
data_dict
[
'item_a'
]
item_b
=
data_dict
[
'item_b'
]
node_b
=
data_dict
[
'node_b'
]
movement_a
=
data_dict
[
'movement_a'
]
movement_b
=
data_dict
[
'movement_b'
]
movement_c
=
data_dict
[
'movement_c'
]
getTrackingList
=
self
.
portal
.
portal_simulation
.
getTrackingList
path_list
=
[
i
.
path
for
i
in
getTrackingList
(
...
...
@@ -3526,7 +3522,7 @@ class TestInventoryCacheTable(InventoryAPITestCase):
# Create an old movement
INVENTORY_QUANTITY_4
=
100
INVENTORY_DATE_4
=
self
.
NOW
-
3
*
self
.
CACHE_LAG
movement
=
self
.
_makeMovement
(
quantity
=
INVENTORY_QUANTITY_4
,
self
.
_makeMovement
(
quantity
=
INVENTORY_QUANTITY_4
,
start_date
=
INVENTORY_DATE_4
,
simulation_state
=
'delivered'
)
# Get inventory in past so that cache is filled
...
...
@@ -3592,7 +3588,7 @@ class TestInventoryCacheTable(InventoryAPITestCase):
# Create a new movement, indexation should not fail
INVENTORY_QUANTITY_4
=
5000
INVENTORY_DATE_4
=
self
.
CACHE_DATE
movement
=
self
.
_makeMovement
(
self
.
_makeMovement
(
quantity
=
INVENTORY_QUANTITY_4
,
start_date
=
INVENTORY_DATE_4
,
simulation_state
=
'delivered'
,
...
...
@@ -3879,16 +3875,6 @@ class TestUnitConversion(BaseTestUnitConversion):
self
.
assertEqual
(
13
*
.
056
-
2
*
.
043
,
self
.
convertedSimulation
(
'mass/nutr/lipid'
))
def
testInventoryNoMetricType
(
self
):
"""
providing only the quantity_unit argument should also work,
and the standard metric type is used
"""
self
.
assertEqual
((
11
*
123
-
789
)
/
1e6
,
self
.
getSimulationTool
().
getInventory
(
node_uid
=
self
.
node
.
getUid
(),
quantity_unit
=
"mass/t"
))
class
TestUnitConversionDefinition
(
BaseTestUnitConversion
):
QUANTITY_UNIT_DICT
=
{
# base: (reference, dict_of_others)
...
...
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