Add patch for issue4273 (required for commission module

This commit is contained in:
Sergi Almacellas Abellana 2014-10-28 10:21:07 +01:00
parent 0a350f0871
commit ac2e62a14d
2 changed files with 86 additions and 0 deletions

85
issue9801002_40001.diff Normal file
View File

@ -0,0 +1,85 @@
Index: trytond/trytond/tests/test_tools.py
===================================================================
--- a/trytond/trytond/tests/test_tools.py
+++ b/trytond/tests/test_tools.py
@@ -3,12 +3,13 @@
#this repository contains the full copyright notices and license terms.
import unittest
+import doctest
import datetime
import sql
import sql.operators
from trytond.tools import reduce_ids, safe_eval, datetime_strftime, \
- reduce_domain
+ reduce_domain, decimal_
class ToolsTestCase(unittest.TestCase):
@@ -117,4 +118,5 @@
suite = unittest.TestSuite()
for testcase in (ToolsTestCase,):
suite.addTests(func(testcase))
+ suite.addTest(doctest.DocTestSuite(decimal_))
return suite
Index: trytond/trytond/tools/__init__.py
===================================================================
--- a/trytond/trytond/tools/__init__.py
+++ b/trytond/trytond/tools/__init__.py
@@ -2,6 +2,7 @@
#this repository contains the full copyright notices and license terms.
from .misc import *
from .datetime_strftime import *
+from .decimal_ import *
class ClassProperty(property):
Index: trytond/trytond/tools/decimal_.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/trytond/trytond/tools/decimal_.py
@@ -0,0 +1,36 @@
+# This file is part of Tryton. The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+import tokenize
+from io import StringIO
+
+# code snippet taken from http://docs.python.org/library/tokenize.html
+
+
+def decistmt(s):
+ """Substitute Decimals for floats in a string of statements.
+
+ >>> from decimal import Decimal
+ >>> s = 'print +21.3e-5*-.1234/81.7'
+ >>> decistmt(s)
+ u"print +Decimal (u'21.3e-5')*-Decimal (u'.1234')/Decimal (u'81.7')"
+
+ >>> exec(s)
+ -3.21716034272e-07
+ >>> exec(decistmt(s))
+ -3.217160342717258261933904529E-7
+ """
+ result = []
+ # tokenize the string
+ g = tokenize.generate_tokens(StringIO(s.decode('utf-8')).readline)
+ for toknum, tokval, _, _, _ in g:
+ # replace NUMBER tokens
+ if toknum == tokenize.NUMBER and '.' in tokval:
+ result.extend([
+ (tokenize.NAME, 'Decimal'),
+ (tokenize.OP, '('),
+ (tokenize.STRING, repr(tokval)),
+ (tokenize.OP, ')')
+ ])
+ else:
+ result.append((toknum, tokval))
+ return tokenize.untokenize(result)

1
series
View File

@ -31,3 +31,4 @@ issue6451002_60001.diff
issue3991003_40001.diff
issue4011003_200001.diff
nan_tic_sao.diff
issue9801002_40001.diff