changeset c087769ebe2c in proteus:4.6
details: https://hg.tryton.org/proteus?cmd=changeset;node=c087769ebe2c
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 f789bf57c3ca -r c087769ebe2c proteus/__init__.py
--- a/proteus/__init__.py Sun Sep 15 14:27:44 2019 +0200
+++ b/proteus/__init__.py Tue Oct 01 22:54:31 2019 +0200
@@ -115,12 +115,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
@@ -661,9 +661,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
@@ -819,7 +819,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 f789bf57c3ca -r c087769ebe2c proteus/tests/test_model.py
--- a/proteus/tests/test_model.py Sun Sep 15 14:27:44 2019 +0200
+++ b/proteus/tests/test_model.py Tue Oct 01 22:54:31 2019 +0200
@@ -24,6 +24,11 @@
admin = User.find([('login', '=', 'admin')])[0]
self.assertEqual(int(admin), admin.id)
+ 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]