diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index f55e4b9c027..eb4a073e3b2 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -1169,5 +1169,24 @@ def field_to_dict(self, cr, user, context, field): return res + +class column_info(object): + """Struct containing details about an osv column, either one local to + its model, or one inherited via _inherits. + + :attr name: name of the column + :attr column: column instance, subclass of osv.fields._column + :attr parent_model: if the column is inherited, name of the model + that contains it, None for local columns. + :attr parent_column: the name of the column containing the m2o + relationship to the parent model that contains + this column, None for local columns. + """ + def __init__(self, name, column, parent_model=None, parent_column=None): + self.name = name + self.column = column + self.parent_model = parent_model + self.parent_column = parent_column + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 3212c09410e..9a1fc307b12 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -477,6 +477,11 @@ class orm_template(object): # r is the (local) field towards m, # and f is the _column object itself. _inherit_fields = {} + # Mapping field name/column_info object + # This is similar to _inherit_fields but: + # 1. includes self fields, + # 2. uses column_info instead of a triple. + _all_columns = {} _table = None _invalids = set() _log_create = False @@ -1263,7 +1268,7 @@ class orm_template(object): def fields_get(self, cr, user, allfields=None, context=None, write_access=True): - """ Returns the definition of each field. + """ Return the definition of each field. The returned value is a dictionary (indiced by field name) of dictionaries. The _inherits'd fields are included. The string, @@ -3141,6 +3146,7 @@ class orm(orm_template): if self._name in obj._inherits: obj._inherits_reload() + def _inherits_reload(self): """ Recompute the _inherit_fields mapping. @@ -3155,8 +3161,22 @@ class orm(orm_template): for col in other._inherit_fields.keys(): res[col] = (table, self._inherits[table], other._inherit_fields[col][2]) self._inherit_fields = res + self._all_columns = self._get_column_infos() self._inherits_reload_src() + + def _get_column_infos(self): + """Returns a dict mapping all fields names (direct fields and + inherited field via _inherits) to a ``column_info`` struct + giving detailed columns """ + result = {} + for k, (parent, m2o, col) in self._inherit_fields.iteritems(): + result[k] = fields.column_info(k, col, parent, m2o) + for k, col in self._columns.iteritems(): + result[k] = fields.column_info(k, col) + return result + + def _inherits_check(self): for table, field_name in self._inherits.items(): if field_name not in self._columns: