changeset ae4b19bca2f7 in proteus:4.4
details: https://hg.tryton.org/proteus?cmd=changeset;node=ae4b19bca2f7
description:
Allow id equals to zero
issue8680
review277921002
(grafted from 28e3d55d7b334be0cda12d4cf44a08d1aae76719)
diffstat:
proteus/__init__.py | 10 +++++-----
proteus/tests/test_model.py | 5 +++++
2 files changed, 10 insertions(+), 5 deletions(-)
diffs (54 lines):
diff -r 710bc0b9ae4f -r ae4b19bca2f7 proteus/__init__.py
--- a/proteus/__init__.py Sun Sep 15 14:28:25 2019 +0200
+++ b/proteus/__init__.py Tue Oct 01 22:54:31 2019 +0200
@@ -114,12 +114,12 @@
self.__doc__ = definition['string']
def __get__(self, instance, owner):
- if instance.id > 0:
+ if instance.id >= 0:
instance._read(self.name)
return instance._values.get(self.name, self.default)
def __set__(self, instance, value):
- if instance.id > 0:
+ if instance.id >= 0:
instance._read(self.name)
previous = getattr(instance, self.name)
instance._values[self.name] = value
@@ -630,9 +630,9 @@
def __init__(self, id=None, _default=True, **kwargs):
super(Model, self).__init__()
- if id:
+ if id is not None:
assert not kwargs
- self.__id = id or Model.__counter
+ self.__id = id if id is not None else Model.__counter
if self.__id < 0:
Model.__counter -= 1
self._values = {} # store the values of fields
@@ -785,7 +785,7 @@
for record in records:
assert proxy == record._proxy
assert config == record._config
- if record.id > 0:
+ if record.id >= 0:
context['_timestamp'].update(record._get_timestamp())
delete.append(record.id)
if delete:
diff -r 710bc0b9ae4f -r ae4b19bca2f7 proteus/tests/test_model.py
--- a/proteus/tests/test_model.py Sun Sep 15 14:28:25 2019 +0200
+++ b/proteus/tests/test_model.py Tue Oct 01 22:54:31 2019 +0200
@@ -19,6 +19,11 @@
User = Model.get('res.user')
self.assert_(len(User.search([('login', '=', 'admin')], {})))
+ def test_id_zero(self):
+ User = Model.get('res.user')
+ root = User(0)
+ self.assertEqual(root.login, 'root')
+
def test_find(self):
User = Model.get('res.user')
admin = User.find([('login', '=', 'admin')])[0]