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
Paul Graydon
erp5
Commits
27c8d4c9
Commit
27c8d4c9
authored
Feb 21, 2024
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RoundingModel: optimise roundValue().
parent
d015e4b1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
25 deletions
+8
-25
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.RoundingModel.py
...lateItem/portal_components/document.erp5.RoundingModel.py
+8
-25
No files found.
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.RoundingModel.py
View file @
27c8d4c9
...
...
@@ -29,8 +29,7 @@ from AccessControl import ClassSecurityInfo
from
Products.ERP5Type
import
PropertySheet
,
Permissions
from
Products.ERP5Type.Core.Predicate
import
Predicate
from
Products.ERP5Type.Utils
import
UpperCase
from
decimal
import
Decimal
from
erp5.component.tool.RoundingTool
import
ROUNDING_OPTION_DICT
from
erp5.component.tool.RoundingTool
import
round
as
round_
import
ExtensionClass
from
math
import
log
...
...
@@ -61,37 +60,21 @@ class RoundingModel(Predicate):
if
not
value
:
return
value
precision
=
self
.
getPrecision
()
rounding_method_id
=
self
.
getRoundingMethodId
()
if
rounding_method_id
is
not
None
:
rounding_method
=
getattr
(
self
,
rounding_method_id
,
None
)
if
rounding_method
is
None
:
raise
ValueError
(
'Rounding method (%s) was not found.'
\
%
(
rounding_method_id
,))
return
rounding_method
(
value
,
precision
)
else
:
decimal_rounding_option
=
self
.
getDecimalRoundingOption
()
if
decimal_rounding_option
not
in
ROUNDING_OPTION_DICT
:
raise
ValueError
(
'Decimal rounding option must be selected.'
)
def
rounding_method
(
value
,
precision
):
if
precision
is
None
:
precision
=
1
scale
=
int
(
log
(
precision
,
10
))
if
scale
>
0
or
(
scale
==
0
and
precision
>=
1
):
value
=
Decimal
(
str
(
value
))
scale
=
Decimal
(
str
(
int
(
precision
))).
quantize
(
value
)
precision
=
Decimal
(
'1'
)
value
/=
scale
value
=
value
.
quantize
(
precision
,
rounding
=
decimal_rounding_option
)
value
*=
scale
result
=
float
(
value
.
quantize
(
precision
))
ndigits
=
0
else
:
result
=
float
(
Decimal
(
str
(
value
)).
quantize
(
Decimal
(
str
(
precision
)),
rounding
=
decimal_rounding_option
))
return
result
return
rounding_method
(
value
,
self
.
getPrecision
())
ndigits
=
-
int
(
round
(
log
(
precision
,
10
)))
return
round_
(
value
,
ndigits
,
decimal_rounding_option
)
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getRoundingProxy'
)
def
getRoundingProxy
(
self
,
document
):
...
...
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