Add sql_pairing tool

issue9606
review328091002
This commit is contained in:
Cédric Krier
2020-10-08 21:34:15 +02:00
parent 321461647e
commit 7f6b94610b
4 changed files with 16 additions and 2 deletions
+1
View File
@@ -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
+4
View File
@@ -8,3 +8,7 @@ Miscellaneous
.. 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.
+2 -2
View File
@@ -9,14 +9,14 @@ from .misc import (
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):
+9
View File
@@ -17,6 +17,7 @@ from functools import wraps
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 @@ def sortable_values(func):
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)