[IMP] fields: split multi-purpose '_origin' into 'column' and 'inherited'

This makes it easier to determine when a field interfaces a column, and when it
implements an inherited field (with _inherits).
This commit is contained in:
Raphael Collet 2014-10-01 10:02:10 +02:00
parent e7422b2f3a
commit a69996b50c
4 changed files with 9 additions and 9 deletions

View File

@ -190,8 +190,8 @@ class res_users(osv.osv):
# overridden inherited fields to bypass access rights, in case you have
# access to the user but not its corresponding partner
name = openerp.fields.Char(related='partner_id.name')
email = openerp.fields.Char(related='partner_id.email')
name = openerp.fields.Char(related='partner_id.name', inherited=True)
email = openerp.fields.Char(related='partner_id.email', inherited=True)
def on_change_login(self, cr, uid, ids, login, context=None):
if login and tools.single_email_re.match(login):

View File

@ -249,7 +249,8 @@ class Field(object):
_free_attrs = None # list of semantic-free attribute names
automatic = False # whether the field is automatically created ("magic" field)
_origin = None # the column or field interfaced by self, if any
inherited = False # whether the field is inherited (_inherits)
column = None # the column interfaced by the field
name = None # name of the field
type = None # type of the field (string)
@ -580,11 +581,10 @@ class Field(object):
def to_column(self):
""" return a low-level field object corresponding to `self` """
assert self.store
if self._origin:
assert isinstance(self._origin, fields._column)
if self.column:
# some columns are registry-dependent, like float fields (digits);
# duplicate them to avoid sharing between registries
return copy(self._origin)
return copy(self.column)
_logger.debug("Create fields._column for Field %s", self)
args = {}

View File

@ -813,7 +813,7 @@ class BaseModel(object):
# inheritance between different models)
cls._fields = {}
for attr, field in getmembers(cls, Field.__instancecheck__):
if not field._origin:
if not field.inherited:
cls._add_field(attr, field.copy())
# introduce magic fields
@ -2950,9 +2950,9 @@ class BaseModel(object):
for attr, field in cls.pool[parent_model]._fields.iteritems():
if attr not in cls._fields:
cls._add_field(attr, field.copy(
inherited=True,
related=(parent_field, attr),
related_sudo=False,
_origin=field,
))
cls._inherits_reload_src()

View File

@ -131,7 +131,7 @@ class _column(object):
def to_field_args(self):
""" return a dictionary with all the arguments to pass to the field """
items = [
('_origin', self), # field interfaces self
('column', self), # field interfaces self
('copy', self.copy),
('index', self.select),
('manual', self.manual),