[FIX] models: `_convert_to_write()` shall not return `NewId`

The result of _convert_to_write() is intended to be pass directly to
`write()` or returned to the client (`onchange()` and `default_get()`.
`NewId` is as special value that must not be stored into the database
or exposed to the client.
This commit is contained in:
Christophe Simonis 2014-08-14 21:43:16 +02:00
parent d68537022f
commit 25e11113b5
1 changed files with 3 additions and 5 deletions

View File

@ -1304,10 +1304,6 @@ class BaseModel(object):
# convert default values to the expected format
result = self._convert_to_write(result)
for key, val in result.items():
if isinstance(val, NewId):
del result[key] # ignore new records in defaults
return result
def add_default_value(self, field):
@ -5140,9 +5136,11 @@ class BaseModel(object):
""" Convert the `values` dictionary into the format of :meth:`write`. """
fields = self._fields
return dict(
(name, fields[name].convert_to_write(value))
(name, write_value)
for name, value in values.iteritems()
if name in self._fields
for write_value in [fields[name].convert_to_write(value)]
if not isinstance(write_value, NewId)
)
#