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
1
Merge Requests
1
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
Titouan Soulard
erp5
Commits
27ca39a4
Commit
27ca39a4
authored
Jan 21, 2025
by
Titouan Soulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_trade: FIXUP variated test
parent
fd132e85
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
57 deletions
+48
-57
bt5/erp5_trade/TestTemplateItem/portal_components/test.erp5.testInventoryModule.py
...teItem/portal_components/test.erp5.testInventoryModule.py
+48
-57
No files found.
bt5/erp5_trade/TestTemplateItem/portal_components/test.erp5.testInventoryModule.py
View file @
27ca39a4
...
...
@@ -161,39 +161,25 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
inventory_value
.
Inventory_computeOffsetAction
()
self
.
tic
()
inventory_value
.
deliver
()
self
.
tic
()
return
inventory_value
# Used for unvariated products, returns tuple
def
_getInventoryAmount
(
self
,
product_value
):
inventory
=
self
.
portal
.
portal_simulation
.
getInventory
(
section_uid
=
self
.
destination_organisation_value
.
getUid
(),
node_uid
=
self
.
destination_organisation_value
.
getUid
(),
resource_uid
=
product_value
.
getUid
(),
)
total_price
=
self
.
portal
.
portal_simulation
.
getInventoryAssetPrice
(
section_uid
=
self
.
destination_organisation_value
.
getUid
(),
node_uid
=
self
.
destination_organisation_value
.
getUid
(),
resource_uid
=
product_value
.
getUid
(),
)
return
(
inventory
,
total_price
)
def
_getInventory
(
self
,
product_value
,
variation
=
None
):
inventory_kw
=
{
"section_uid"
:
self
.
destination_organisation_value
.
getUid
(),
"node_uid"
:
self
.
destination_organisation_value
.
getUid
(),
"resource_uid"
:
product_value
.
getUid
(),
}
# Used for variated products, returns dict of tuples
def
_getInventoryDict
(
self
,
product_value
):
inventory_dict
=
{}
inventory_list
=
self
.
portal
.
portal_simulation
.
getInventoryList
(
section_uid
=
self
.
destination_organisation_value
.
getUid
(),
node_uid
=
self
.
destination_organisation_value
.
getUid
(),
resource_uid
=
product_value
.
getUid
(),
)
if
variation
is
not
None
:
inventory_kw
[
"variation_text"
]
=
"variation/"
+
variation
for
inventory
in
inventory_list
:
variation
=
inventory
.
variation_text
.
split
(
"/"
,
1
)[
1
]
inventory_dict
[
variation
]
=
(
inventory
.
quantity
,
inventory
.
total_price
)
inventory
=
self
.
portal
.
portal_simulation
.
getCurrentInventory
(
**
inventory_kw
)
total_price
=
self
.
portal
.
portal_simulation
.
getCurrentInventoryAssetPrice
(
**
inventory_kw
)
return
inventory_dict
return
(
inventory
,
total_price
)
def
test_01_addUnvariatedToStock
(
self
):
"""
...
...
@@ -212,7 +198,7 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
})
# Sanity check: ensure Inventory API reports what's expected
(
initial_inventory
,
initial_price
)
=
self
.
_getInventory
Amount
(
self
.
unvariated_product
)
(
initial_inventory
,
initial_price
)
=
self
.
_getInventory
(
self
.
unvariated_product
)
# Assert: initial stock is 2 units
self
.
assertEqual
(
2.0
,
initial_inventory
)
...
...
@@ -231,7 +217,7 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
self
.
assertEqual
(
1.0
,
inventory_offset_line_list
[
0
].
getQuantity
())
self
.
assertEqual
(
110.0
,
inventory_offset_line_list
[
0
].
getPrice
())
(
final_inventory
,
final_price
)
=
self
.
_getInventory
Amount
(
self
.
unvariated_product
)
(
final_inventory
,
final_price
)
=
self
.
_getInventory
(
self
.
unvariated_product
)
# Assert: final stock is 3 units
self
.
assertEqual
(
3.0
,
final_inventory
)
...
...
@@ -251,40 +237,43 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
)
self
.
variated_product
.
setQuantityUnitList
([
"unit/piece"
])
self
.
variated_product
.
setIndividualVariationBaseCategoryList
([
"variation"
])
variated_product_variation_dict
=
{}
initial_variated_product_variation_dict
=
{}
extra_variated_product_variation_dict
=
{}
total_variated_product_variation_dict
=
{}
for
(
i
,
variation_name
)
in
enumerate
([
"A"
,
"B"
,
"C"
]):
variated_product_variation
=
self
.
variated_product
.
newContent
(
portal_type
=
self
.
default_product_variation_portal_type
,
title
=
"Variation "
+
variation_name
,
)
variated_product_variation_dict
[
variated_product_variation
.
getRelativeUrl
()]
=
((
i
+
1
)
*
1.0
,
(
i
+
1
)
*
100.0
)
initial_
variated_product_variation_dict
[
variated_product_variation
.
getRelativeUrl
()]
=
((
i
+
1
)
*
1.0
,
(
i
+
1
)
*
100.0
)
self
.
tic
()
self
.
_createPurchasePackingList
({
self
.
variated_product
.
getRelativeUrl
():
variated_product_variation_dict
,
self
.
variated_product
.
getRelativeUrl
():
initial_
variated_product_variation_dict
,
})
# Sanity check: ensure Inventory API reports what's expected
inventory_dict
=
self
.
_getInventoryDict
(
self
.
variated_product
)
# Convert unit prices to total prices for comparison
for
variated_product_variation
in
variated_product_variation_dict
.
keys
():
(
quantity
,
unit_price
)
=
variated_product_variation_dict
[
variated_product_variation
]
variated_product_variation_dict
[
variated_product_variation
]
=
(
quantity
,
unit_price
*
quantity
)
self
.
assertEqual
(
variated_product_variation_dict
,
inventory_dict
)
for
variated_product_variation
in
initial_variated_product_variation_dict
.
keys
():
(
expected_quantity
,
unit_price
)
=
initial_variated_product_variation_dict
[
variated_product_variation
]
(
quantity
,
total_price
)
=
self
.
_getInventory
(
self
.
variated_product
,
variated_product_variation
)
# Assert: quantity is consistent
self
.
assertEqual
(
expected_quantity
,
quantity
)
# Assert: price is consistent
self
.
assertEqual
(
unit_price
*
quantity
,
total_price
)
# We are going to add:
# - 1 variation B at price 100;
# - 2 variations C at price 200.
# Then create an Inventory with the new values.
for
i
,
variated_product_variation
in
enumerate
(
variated_product_variation_dict
.
keys
()):
(
quantity
,
_
)
=
variated_product_variation_dict
[
variated_product_variation
]
variated_product_variation_dict
[
variated_product_variation
]
=
(
quantity
+
i
,
i
*
100.0
)
for
i
,
variated_product_variation
in
enumerate
(
initial_variated_product_variation_dict
.
keys
()):
(
quantity
,
unit_price
)
=
initial_variated_product_variation_dict
[
variated_product_variation
]
extra_variated_product_variation_dict
[
variated_product_variation
]
=
(
i
*
1.0
,
i
*
100.0
)
total_variated_product_variation_dict
[
variated_product_variation
]
=
(
quantity
+
i
,
i
*
100.0
)
inventory_value
=
self
.
_createInventory
({
self
.
variated_product
.
getRelativeUrl
():
variated_product_variation_dict
,
self
.
variated_product
.
getRelativeUrl
():
total_
variated_product_variation_dict
,
})
# Assert: one and only one offset line was created
...
...
@@ -296,17 +285,19 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
# Assert: two and only two offset cells were created
self
.
assertEqual
(
2
,
len
(
inventory_offset_cell_list
))
# Assert: offset cells were computed correctly
self
.
assertEqual
(
1.0
,
inventory_offset_cell_list
[
0
].
getQuantity
())
self
.
assertEqual
(
100.0
,
inventory_offset_cell_list
[
0
].
getPrice
())
self
.
assertEqual
(
2.0
,
inventory_offset_cell_list
[
1
].
getQuantity
())
self
.
assertEqual
(
200.0
,
inventory_offset_cell_list
[
1
].
getPrice
())
inventory_dict
=
self
.
_getInventoryDict
(
self
.
variated_product
)
# Fix total prices because their computation is weird
for
variated_product_variation
in
variated_product_variation_dict
.
keys
():
(
quantity
,
_
)
=
variated_product_variation_dict
[
variated_product_variation
]
variated_product_variation_dict
[
variated_product_variation
]
=
(
quantity
,
100.0
)
# Assert: strict equality of inventories
self
.
assertEqual
(
variated_product_variation_dict
,
inventory_dict
)
for
inventory_offset_cell
in
inventory_offset_cell_list
:
inventory_offset_cell_variation
=
inventory_offset_cell
.
getVariation
()
(
expected_quantity
,
expected_price
)
=
extra_variated_product_variation_dict
[
inventory_offset_cell_variation
]
self
.
assertEqual
(
expected_quantity
,
inventory_offset_cell
.
getQuantity
())
self
.
assertEqual
(
expected_price
,
inventory_offset_cell
.
getPrice
())
for
variated_product_variation
in
total_variated_product_variation_dict
.
keys
():
(
expected_quantity
,
_
)
=
total_variated_product_variation_dict
[
variated_product_variation
]
(
initial_quantity
,
initial_price
)
=
initial_variated_product_variation_dict
[
variated_product_variation
]
(
extra_quantity
,
extra_price
)
=
extra_variated_product_variation_dict
[
variated_product_variation
]
(
quantity
,
total_price
)
=
self
.
_getInventory
(
self
.
variated_product
,
variated_product_variation
)
# Assert: quantity is consistent
self
.
assertEqual
(
expected_quantity
,
quantity
)
# Assert: price is consistent
self
.
assertEqual
(
initial_quantity
*
initial_price
+
extra_quantity
*
extra_price
,
total_price
)
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