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
2b5062e2
Commit
2b5062e2
authored
Jan 15, 2025
by
Titouan Soulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_trade: add test for variated products
parent
f7f6c0fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
12 deletions
+154
-12
bt5/erp5_trade/TestTemplateItem/portal_components/test.erp5.testInventoryModule.py
...teItem/portal_components/test.erp5.testInventoryModule.py
+151
-11
bt5/erp5_trade/TestTemplateItem/portal_components/test.erp5.testInventoryModule.xml
...eItem/portal_components/test.erp5.testInventoryModule.xml
+3
-1
No files found.
bt5/erp5_trade/TestTemplateItem/portal_components/test.erp5.testInventoryModule.py
View file @
2b5062e2
...
...
@@ -36,6 +36,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
"""
default_stock_entry_date
=
DateTime
(
2024
,
1
,
1
)
default_inventory_date
=
DateTime
(
2024
,
1
,
10
)
default_product_portal_type
=
"Product"
default_product_variation_portal_type
=
"Product Individual Variation"
def
getBusinessTemplateList
(
self
):
return
(
"erp5_core"
,
"erp5_base"
,
"erp5_pdm"
,
"erp5_simulation"
,
...
...
@@ -76,13 +78,30 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
stop_date
=
self
.
default_stock_entry_date
,
)
for
(
product_value
,
quantity
,
price
)
in
lines
:
purchase_packing_list_value
.
newContent
(
for
line
in
lines
:
purchase_packing_list_
line_value
=
purchase_packing_list_
value
.
newContent
(
portal_type
=
"Purchase Packing List Line"
,
resource_value
=
product_value
,
quantity
=
quantity
,
price
=
price
,
)
purchase_packing_list_line_variation_list
=
[]
if
len
(
line
)
==
2
:
(
product_value
,
cells
)
=
line
for
(
variation_value
,
quantity
,
price
)
in
cells
:
purchase_packing_list_line_value
.
newContent
(
portal_type
=
"Purchase Packing List Cell"
,
variation_value
=
variation_value
,
quantity
=
quantity
,
price
=
price
,
)
purchase_packing_list_line_variation_list
.
append
(
variation_value
)
elif
len
(
line
)
==
3
:
(
product_value
,
quantity
,
price
)
=
line
purchase_packing_list_line_value
.
setQuantity
(
quantity
)
purchase_packing_list_line_value
.
setPrice
(
price
)
purchase_packing_list_line_value
.
setResourceValue
(
product_value
)
purchase_packing_list_line_value
.
setVariationValueList
(
purchase_packing_list_line_variation_list
)
purchase_packing_list_value
.
confirm
()
self
.
tic
()
...
...
@@ -100,20 +119,47 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
destination_value
=
self
.
destination_organisation_value
,
start_date
=
self
.
default_inventory_date
,
)
inventory_line_variation_list
=
[]
for
(
product_value
,
quantity
,
price
)
in
lines
:
inventory_value
.
newContent
(
for
line
in
lines
:
inventory_
line_value
=
inventory_
value
.
newContent
(
portal_type
=
"Inventory Line"
,
resource_value
=
product_value
,
inventory
=
quantity
,
price
=
price
,
)
if
len
(
line
)
==
2
:
(
product_value
,
cells
)
=
line
inventory_line_variation_list
=
[
cell
[
0
]
for
cell
in
cells
]
inventory_line_cell_range
=
[
"variation/"
+
variation
.
getRelativeUrl
()
for
variation
in
inventory_line_variation_list
]
inventory_line_value
.
setResourceValue
(
product_value
)
inventory_line_value
.
setVariationValueList
(
inventory_line_variation_list
)
inventory_line_value
.
setCellRange
(
inventory_line_cell_range
,
base_id
=
"movement"
)
for
(
variation_value
,
quantity
,
price
)
in
cells
:
cell_variation_text
=
"variation/"
+
variation_value
.
getRelativeUrl
()
inventory_line_value
.
newCell
(
cell_variation_text
,
portal_type
=
"Inventory Cell"
,
variation_value
=
variation_value
,
inventory
=
quantity
,
price
=
price
,
base_id
=
"movement"
,
)
inventory_line_variation_list
.
append
(
variation_value
)
elif
len
(
line
)
==
3
:
(
product_value
,
quantity
,
price
)
=
line
inventory_line_value
.
edit
(
resource_value
=
product_value
,
inventory
=
quantity
,
price
=
price
)
inventory_value
.
Inventory_computeOffsetAction
()
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
(),
...
...
@@ -129,13 +175,28 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
return
(
inventory
,
total_price
)
# 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
(),
)
for
inventory
in
inventory_list
:
variation
=
inventory
.
variation_text
.
split
(
"/"
,
1
)[
1
]
inventory_dict
[
variation
]
=
(
inventory
.
quantity
,
inventory
.
total_price
)
return
inventory_dict
def
test_01_addUnvariatedToStock
(
self
):
"""
For an unvariated product, checks that quantity and price are correct
after noticing that there are more products than expected in stock.
"""
self
.
unvariated_product
=
self
.
portal
.
product_module
.
newContent
(
portal_type
=
"Product"
,
portal_type
=
self
.
default_product_portal_type
,
title
=
"Unvariated product"
,
)
self
.
unvariated_product
.
setQuantityUnitList
([
"unit/piece"
])
...
...
@@ -173,3 +234,82 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
# Note that the price is only taken into account when there actually
# are movements. Otherwise, it is totally discarded.
self
.
assertEqual
(
310.0
,
final_price
)
def
test_02_addVariatedToStock
(
self
):
"""
For a variated product, checks that quantity and price are correct
after noticing that there are more products than expected in stock.
"""
self
.
variated_product
=
self
.
portal
.
product_module
.
newContent
(
portal_type
=
self
.
default_product_portal_type
,
title
=
"Variated product"
,
)
self
.
variated_product
.
setQuantityUnitList
([
"unit/piece"
])
self
.
variated_product
.
setIndividualVariationBaseCategoryList
([
"variation"
])
self
.
variated_product_variation_list
=
[]
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
,
)
self
.
variated_product_variation_list
.
append
([
variated_product_variation
,
(
i
+
1
),
(
i
+
1
)
*
100.0
])
self
.
tic
()
self
.
_createPurchasePackingList
([
(
self
.
variated_product
,
self
.
variated_product_variation_list
),
])
# Sanity check: ensure Inventory API reports what's expected
inventory_dict
=
self
.
_getInventoryDict
(
self
.
variated_product
)
for
variation
in
self
.
variated_product_variation_list
:
variation_relative_url
=
variation
[
0
].
getRelativeUrl
()
# Assert: variation exists in stock
self
.
assertIn
(
variation_relative_url
,
inventory_dict
)
(
initial_inventory
,
initial_price
)
=
inventory_dict
[
variation_relative_url
]
# Assert: quantity is correct
self
.
assertEqual
(
variation
[
1
],
initial_inventory
)
# Assert: price is correct
self
.
assertEqual
(
variation
[
1
]
*
variation
[
2
],
initial_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
,
variation
)
in
enumerate
(
self
.
variated_product_variation_list
):
variation
[
1
]
+=
i
variation
[
2
]
=
i
*
100.0
inventory_value
=
self
.
_createInventory
([
(
self
.
variated_product
,
self
.
variated_product_variation_list
),
])
# Assert: one and only one offset line was created
inventory_offset_line_list
=
inventory_value
.
objectValues
(
portal_type
=
"Inventory Offset Line"
)
self
.
assertEqual
(
1
,
len
(
inventory_offset_line_list
))
inventory_offset_line
=
inventory_offset_line_list
[
0
]
inventory_offset_cell_list
=
inventory_offset_line
.
objectValues
(
portal_type
=
"Inventory Offset Cell"
)
# 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
)
for
(
i
,
variation
)
in
enumerate
(
self
.
variated_product_variation_list
):
variation_relative_url
=
variation
[
0
].
getRelativeUrl
()
# Assert: variation exists in stock
self
.
assertIn
(
variation_relative_url
,
inventory_dict
)
(
final_inventory
,
final_price
)
=
inventory_dict
[
variation_relative_url
]
# Assert: quantity is correct
self
.
assertEqual
(
variation
[
1
],
final_inventory
)
# Assert: price is correct
#self.assertEqual(i * 100.0 + (i + , final_price)
bt5/erp5_trade/TestTemplateItem/portal_components/test.erp5.testInventoryModule.xml
View file @
2b5062e2
...
...
@@ -43,7 +43,9 @@
<item>
<key>
<string>
text_content_warning_message
</string>
</key>
<value>
<tuple/>
<tuple>
<string>
W:311, 24: Unused variable \'final_price\' (unused-variable)
</string>
</tuple>
</value>
</item>
<item>
...
...
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