Skip to content

Commit 194b9c5

Browse files
authored
Merge pull request #42 from senaite/fix-smaller-decimals
Fix cannot enter small decimals in breakpoint table
2 parents ee772d9 + 907c9d1 commit 194b9c5

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

docs/changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
1.2.0 (unreleased)
55
------------------
66

7+
- #42 Fix cannot enter small decimals in breakpoint table
78
- #40 Compatibility with core#2537 (Support multi-text on result entry)
89
- #39 Compatibility with core#2584 (SampleType to DX)
910
- #38 Compatibility with core#2595 (Move ARAnalysesField logic to data manager)

src/senaite/ast/configure.zcml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<include package=".adapters" />
2121
<include package=".behaviors" />
2222
<include package=".browser"/>
23+
<include package=".patches"/>
2324
<include package=".subscribers"/>
2425
<include package=".upgrade"/>
2526
<include package=".workflow"/>

src/senaite/ast/patches/__init__.py

Whitespace-only changes.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<configure
2+
xmlns="http://namespaces.zope.org/zope"
3+
xmlns:monkey="http://namespaces.plone.org/monkey"
4+
i18n_domain="senaite.ast">
5+
6+
<monkey:patch
7+
description="Patch `z3c.form.converter.NumberDataConverter` to prevent
8+
the error 'The entered value is not a valid decimal literal`
9+
for small declimal values like '0.0625'"
10+
class="z3c.form.converter.NumberDataConverter"
11+
original="toFieldValue"
12+
replacement=".converter.toFieldValue" />
13+
14+
</configure>

src/senaite/ast/patches/converter.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import zope.i18n.format
4+
from z3c.form.converter import FormatterValidationError
5+
6+
DECIMAL_PATTERN = u'#,##0.######;-#,##0.######'
7+
8+
def toFieldValue(self, value):
9+
"""See interfaces.IDataConverter"""
10+
if value == u'':
11+
return self.field.missing_value
12+
try:
13+
return self.formatter.parse(value, pattern=DECIMAL_PATTERN)
14+
except zope.i18n.format.NumberParseError:
15+
raise FormatterValidationError(self.errorMessage, value)

0 commit comments

Comments
 (0)