changeset 74ee9775bca8 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=74ee9775bca8
description:
Add sql_pairing tool
issue9606
review328091002
diffstat:
CHANGELOG | 1 +
doc/ref/tools/misc.rst | 4 ++++
trytond/tools/__init__.py | 4 ++--
trytond/tools/misc.py | 9 +++++++++
4 files changed, 16 insertions(+), 2 deletions(-)
diffs (62 lines):
diff -r 4bcf69601d9d -r 74ee9775bca8 CHANGELOG
--- a/CHANGELOG Thu Oct 08 21:31:49 2020 +0200
+++ b/CHANGELOG Thu Oct 08 21:34:15 2020 +0200
@@ -1,3 +1,4 @@
+* Add sql_pairing tool
* Add format_datetime to Report
* Allow sharing view searches
* Allow overriding digits in Lang.currency and Report.format_currency
diff -r 4bcf69601d9d -r 74ee9775bca8 doc/ref/tools/misc.rst
--- a/doc/ref/tools/misc.rst Thu Oct 08 21:31:49 2020 +0200
+++ b/doc/ref/tools/misc.rst Thu Oct 08 21:34:15 2020 +0200
@@ -8,3 +8,7 @@
.. method:: resolve(name)
Resolve a dotted name to a global object.
+
+.. method:: sql_pairing(x, y)
+
+Return an SQL expression that pairs SQL integers x and y.
diff -r 4bcf69601d9d -r 74ee9775bca8 trytond/tools/__init__.py
--- a/trytond/tools/__init__.py Thu Oct 08 21:31:49 2020 +0200
+++ b/trytond/tools/__init__.py Thu Oct 08 21:34:15 2020 +0200
@@ -9,14 +9,14 @@
file_open, get_smtp_server, reduce_ids, reduce_domain,
grouped_slice, is_instance_method, resolve, strip_wildcard,
lstrip_wildcard, rstrip_wildcard, slugify, sortable_values,
- escape_wildcard)
+ escape_wildcard, sql_pairing)
from .decimal_ import decistmt
__all__ = ['file_open', 'get_smtp_server', 'reduce_ids',
'reduce_domain', 'grouped_slice', 'is_instance_method', 'resolve',
'strip_wildcard', 'lstrip_wildcard', 'rstrip_wildcard', 'slugify',
'decistmt', 'ClassProperty', 'cursor_dict', 'cached_property',
- 'sortable_values', 'escape_wildcard']
+ 'sortable_values', 'escape_wildcard', 'sql_pairing']
class ClassProperty(property):
diff -r 4bcf69601d9d -r 74ee9775bca8 trytond/tools/misc.py
--- a/trytond/tools/misc.py Thu Oct 08 21:31:49 2020 +0200
+++ b/trytond/tools/misc.py Thu Oct 08 21:34:15 2020 +0200
@@ -17,6 +17,7 @@
from itertools import islice
from sql import Literal
+from sql.conditionals import Case
from sql.operators import Or
from trytond.const import OPERATORS
@@ -241,3 +242,11 @@
result[i] = (name, value is None, value)
return result
return wrapper
+
+
+def sql_pairing(x, y):
+ """Return SQL expression to pair x and y
+ Pairing function from http://szudzik.com/ElegantPairing.pdf"""
+ return Case(
+ (x < y, (y * y) + x),
+ else_=(x * x) + x + y)