From 03d2e3fa9a87e57087f64aa9b14182b53ca295e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Tue, 7 Jul 2015 12:48:28 +0200 Subject: [PATCH] Add reversed operators to PYSON expressions review8201002 issue4856 --- CHANGELOG | 1 + trytond/pyson.py | 4 ++++ trytond/tests/test_pyson.py | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 7bb1bf8ad3..af5691ca61 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add reversed operators to PYSON expressions * Use CURRENT_TIMESTAMP instead of now * Use Constraint instance in ModelSQL._sql_constraints * Only return default record if no domain supplied on ModelSingleton search diff --git a/trytond/pyson.py b/trytond/pyson.py index c455588eaf..bc6a13b316 100644 --- a/trytond/pyson.py +++ b/trytond/pyson.py @@ -56,6 +56,8 @@ class PYSON(object): else: return And(self, other) + __rand__ = __and__ + def __or__(self, other): if (isinstance(other, PYSON) and other.types() != set([bool])): @@ -68,6 +70,8 @@ class PYSON(object): else: return Or(self, other) + __ror__ = __or__ + def __eq__(self, other): return Equal(self, other) diff --git a/trytond/tests/test_pyson.py b/trytond/tests/test_pyson.py index 5cf65c2a35..99cfe37d04 100644 --- a/trytond/tests/test_pyson.py +++ b/trytond/tests/test_pyson.py @@ -33,6 +33,12 @@ class PYSONTestCase(unittest.TestCase): self.assertEqual(repr(pyson.Eval('test', 'foo')), "Eval('test', 'foo')") + self.assertIsInstance(~pyson.Eval('test', False), pyson.Not) + self.assertIsInstance(pyson.Eval('test', False) & True, pyson.And) + self.assertIsInstance(True & pyson.Eval('test', False), pyson.And) + self.assertIsInstance(pyson.Eval('test', False) | False, pyson.Or) + self.assertIsInstance(False | pyson.Eval('test', False), pyson.Or) + def test0020Not(self): 'Test pyson.Not' self.assertEqual(pyson.Not(True).pyson(), {