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
Labels
Merge Requests
139
Merge Requests
139
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
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
9af12423
Commit
9af12423
authored
Dec 05, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trade: prevent ZeroDivisionError for 0 quantity when using base_price_per_slice
parent
b2e93a3f
Pipeline
#38757
passed with stage
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
10 deletions
+14
-10
bt5/erp5_pdm/SkinTemplateItem/portal_skins/erp5_pdm/Resource_getPriceCalculationOperandDict.py
...skins/erp5_pdm/Resource_getPriceCalculationOperandDict.py
+13
-10
bt5/erp5_trade/TestTemplateItem/portal_components/test.erp5.testResource.py
...tTemplateItem/portal_components/test.erp5.testResource.py
+1
-0
No files found.
bt5/erp5_pdm/SkinTemplateItem/portal_skins/erp5_pdm/Resource_getPriceCalculationOperandDict.py
View file @
9af12423
...
...
@@ -24,16 +24,19 @@ result = context.getPriceParameterDict(context=movement, **kw)
if
result
[
"slice_base_price"
]:
total_price
=
0.
quantity
=
movement
.
getQuantity
()
sliced_base_price_list
=
zip
(
result
[
"slice_base_price"
],
result
[
"slice_quantity_range"
])
for
slice_price
,
slice_range
in
sliced_base_price_list
:
slice_min
,
slice_max
=
slice_range
if
slice_max
is
None
:
slice_max
=
quantity
+
1
if
slice_min
==
0
:
slice_min
=
1
priced_quantity
=
min
(
slice_max
-
1
,
quantity
)
-
(
slice_min
-
1
)
total_price
+=
priced_quantity
*
slice_price
result
[
"base_price"
]
=
total_price
/
quantity
if
quantity
:
sliced_base_price_list
=
zip
(
result
[
"slice_base_price"
],
result
[
"slice_quantity_range"
])
for
slice_price
,
slice_range
in
sliced_base_price_list
:
slice_min
,
slice_max
=
slice_range
if
slice_max
is
None
:
slice_max
=
quantity
+
1
if
slice_min
==
0
:
slice_min
=
1
priced_quantity
=
min
(
slice_max
-
1
,
quantity
)
-
(
slice_min
-
1
)
total_price
+=
priced_quantity
*
slice_price
result
[
"base_price"
]
=
total_price
/
quantity
else
:
result
[
"base_price"
]
=
0.
base_price
=
result
[
"base_price"
]
if
base_price
in
(
None
,
""
):
...
...
bt5/erp5_trade/TestTemplateItem/portal_components/test.erp5.testResource.py
View file @
9af12423
...
...
@@ -1338,6 +1338,7 @@ class TestResource(ERP5TypeTestCase):
{
'quantity'
:
21
,
'price'
:
198.
/
21
,
'total_price'
:
198.
},
{
'quantity'
:
22
,
'price'
:
206.
/
22
,
'total_price'
:
206.
},
{
'quantity'
:
25
,
'price'
:
230.
/
25
,
'total_price'
:
230.
},
{
'quantity'
:
0.
,
'price'
:
0.
,
'total_price'
:
0.
},
]:
_test
(
**
case
)
...
...
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