[IMP] orm: added a deprecated attribute on fields. If not False, is a string, and make the ORM print a warning telling the field is deprecated.

Use: 'my_field': fields.char('Old field', size=64, deprecated="This field will be removed as of version 42 of OpenERP. Please update your module to use 'my_new_field' instead.")

bzr revid: tde@openerp.com-20120809083103-pjc9ynvmtojnfnah
This commit is contained in:
Thibault Delavallée 2012-08-09 10:31:03 +02:00
parent 9c905bace9
commit 616e7a92ec
2 changed files with 11 additions and 0 deletions

View File

@ -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])

View File

@ -3598,6 +3598,13 @@ class BaseModel(object):
record[f] = res2[record['id']]
else:
record[f] = []
# Warn about deprecated fields now that fields_pre and fields_post are computed
for f in fields_pre + fields_post:
field_column = (f != self.CONCURRENCY_CHECK_FIELD 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():
@ -3975,6 +3982,9 @@ class BaseModel(object):
direct = []
totranslate = context.get('lang', False) and (context['lang'] != 'en_US')
for field in vals:
field_column = (f != self.CONCURRENCY_CHECK_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: