@@ -1,3 +1,4 @@
|
||||
* Add total ordering on Model
|
||||
|
||||
Version 7.6.0 - 2025-04-28
|
||||
--------------------------
|
||||
|
||||
@@ -7,6 +7,7 @@ import datetime
|
||||
import functools
|
||||
import threading
|
||||
from decimal import Decimal
|
||||
from functools import total_ordering
|
||||
|
||||
import proteus.config
|
||||
|
||||
@@ -688,6 +689,7 @@ class ModelList(list):
|
||||
self._changed()
|
||||
|
||||
|
||||
@total_ordering
|
||||
class Model(object):
|
||||
'Model class for Tryton records'
|
||||
__slots__ = ('__id', '_values', '_changed', '_group', '__context')
|
||||
@@ -797,8 +799,10 @@ class Model(object):
|
||||
== (other.__class__.__name__, other.id))
|
||||
return NotImplemented
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self == other
|
||||
def __lt__(self, other):
|
||||
if not isinstance(other, Model) or self.__class__ != other.__class__:
|
||||
return NotImplemented
|
||||
return self.id < other.id
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.__class__.__name__) ^ hash(self.id)
|
||||
|
||||
@@ -286,6 +286,24 @@ class TestModel(ProteusTestCase):
|
||||
self.assertNotEqual(admin1, False)
|
||||
self.assertNotEqual(admin1, 1)
|
||||
|
||||
def test_lt(self):
|
||||
User = Model.get('res.user')
|
||||
|
||||
user1 = User(1)
|
||||
user2 = User(2)
|
||||
|
||||
self.assertLess(user1, user2)
|
||||
|
||||
def test_lt_other_model(self):
|
||||
User = Model.get('res.user')
|
||||
Group = Model.get('res.group')
|
||||
|
||||
user1 = User(1)
|
||||
group2 = Group(2)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
user1 < group2
|
||||
|
||||
def test_default_set(self):
|
||||
User = Model.get('res.user')
|
||||
Group = Model.get('res.group')
|
||||
|
||||
Reference in New Issue
Block a user