[MERGE] 'My Second Not-Chatter Merge of the Day': add a deprecated attribute on fields.
This revision adds a string 'deprecated' attribute on fields. If not False, the ORM makes a warning when attempting to read the read, or write on it. Use: 'my_field': fields.char('Old field', size=64, deprecated="This field will be removed with version 42 of OpenERP. Please yse 'my_new_field' instead.") bzr revid: tde@openerp.com-20120814111143-9qha588hah5380fx
This commit is contained in:
commit
149c6f793f
|
@ -109,6 +109,7 @@ class _column(object):
|
|||
self.selectable = True
|
||||
self.group_operator = args.get('group_operator', False)
|
||||
self.groups = False # CSV list of ext IDs of groups that can access this field
|
||||
self.deprecated = False # Optional deprecation warning
|
||||
for a in args:
|
||||
if args[a]:
|
||||
setattr(self, a, args[a])
|
||||
|
|
|
@ -3596,6 +3596,14 @@ class BaseModel(object):
|
|||
record[f] = res2[record['id']]
|
||||
else:
|
||||
record[f] = []
|
||||
|
||||
# Warn about deprecated fields now that fields_pre and fields_post are computed
|
||||
# Explicitly use list() because we may receive tuples
|
||||
for f in list(fields_pre) + list(fields_post):
|
||||
field_column = self._all_columns.get(f) and self._all_columns.get(f).column
|
||||
if field_column and field_column.deprecated:
|
||||
_logger.warning('Field %s.%s is deprecated: %s', self._name, f, field_column.deprecated)
|
||||
|
||||
readonly = None
|
||||
for vals in res:
|
||||
for field in vals.copy():
|
||||
|
@ -3973,6 +3981,9 @@ class BaseModel(object):
|
|||
direct = []
|
||||
totranslate = context.get('lang', False) and (context['lang'] != 'en_US')
|
||||
for field in vals:
|
||||
field_column = self._all_columns.get(field) and self._all_columns.get(field).column
|
||||
if field_column and field_column.deprecated:
|
||||
_logger.warning('Field %s.%s is deprecated: %s', self._name, field, field_column.deprecated)
|
||||
if field in self._columns:
|
||||
if self._columns[field]._classic_write and not (hasattr(self._columns[field], '_fnct_inv')):
|
||||
if (not totranslate) or not self._columns[field].translate:
|
||||
|
|
Loading…
Reference in New Issue