[FIX]:_inherits for multilevel inheritence

lp bug: https://launchpad.net/bugs/823691 fixed

bzr revid: nch@tinyerp.com-20110826103516-o220jqwqdr3uwjhn
This commit is contained in:
Naresh (OpenERP) 2011-08-26 16:05:16 +05:30
parent eba378a4d6
commit 8d0cf999ac
2 changed files with 35 additions and 29 deletions

View File

@ -1407,12 +1407,16 @@ class column_info(object):
:attr parent_column: the name of the column containing the m2o
relationship to the parent model that contains
this column, None for local columns.
:attr original_parent: if the column is inherited, name of the original
parent model that contains it i.e in case of multilevel
inheritence, None for local columns.
"""
def __init__(self, name, column, parent_model=None, parent_column=None):
def __init__(self, name, column, parent_model=None, parent_column=None, original_parent=None):
self.name = name
self.column = column
self.parent_model = parent_model
self.parent_column = parent_column
self.original_parent = original_parent
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -2609,20 +2609,22 @@ class orm(orm_template):
del d['id']
return data
def _inherits_join_add(self, parent_model_name, query):
def _inherits_join_add(self, current_table, parent_model_name, query):
"""
Add missing table SELECT and JOIN clause to ``query`` for reaching the parent table (no duplicates)
:param current_table: current model object
:param parent_model_name: name of the parent model for which the clauses should be added
:param query: query object on which the JOIN should be added
"""
inherits_field = self._inherits[parent_model_name]
inherits_field = current_table._inherits[parent_model_name]
parent_model = self.pool.get(parent_model_name)
parent_table_name = parent_model._table
quoted_parent_table_name = '"%s"' % parent_table_name
if quoted_parent_table_name not in query.tables:
query.tables.append(quoted_parent_table_name)
query.where_clause.append('("%s".%s = %s.id)' % (self._table, inherits_field, parent_table_name))
query.where_clause.append('(%s.%s = %s.id)' % (current_table._table, inherits_field, parent_table_name))
def _inherits_join_calc(self, field, query):
"""
@ -2637,7 +2639,7 @@ class orm(orm_template):
while field in current_table._inherit_fields and not field in current_table._columns:
parent_model_name = current_table._inherit_fields[field][0]
parent_table = self.pool.get(parent_model_name)
self._inherits_join_add(parent_model_name, query)
self._inherits_join_add(current_table, parent_model_name, query)
current_table = parent_table
return '"%s".%s' % (current_table._table, field)
@ -3328,9 +3330,9 @@ class orm(orm_template):
for table in self._inherits:
other = self.pool.get(table)
for col in other._columns.keys():
res[col] = (table, self._inherits[table], other._columns[col])
res[col] = (table, self._inherits[table], other._columns[col], table)
for col in other._inherit_fields.keys():
res[col] = (table, self._inherits[table], other._inherit_fields[col][2])
res[col] = (table, self._inherits[table], other._inherit_fields[col][2], other._inherit_fields[col][3])
self._inherit_fields = res
self._all_columns = self._get_column_infos()
self._inherits_reload_src()
@ -3341,8 +3343,8 @@ class orm(orm_template):
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, (parent, m2o, col, original_parent) in self._inherit_fields.iteritems():
result[k] = fields.column_info(k, col, parent, m2o, original_parent)
for k, col in self._columns.iteritems():
result[k] = fields.column_info(k, col)
return result
@ -4373,7 +4375,7 @@ class orm(orm_template):
if parent_model and child_object:
# as inherited rules are being applied, we need to add the missing JOIN
# to reach the parent table (if it was not JOINed yet in the query)
child_object._inherits_join_add(parent_model, query)
child_object._inherits_join_add(child_object, parent_model, query)
query.where_clause += added_clause
query.where_clause_params += added_params
for table in added_tables:
@ -4462,7 +4464,7 @@ class orm(orm_template):
else:
continue # ignore non-readable or "non-joinable" fields
elif order_field in self._inherit_fields:
parent_obj = self.pool.get(self._inherit_fields[order_field][0])
parent_obj = self.pool.get(self._inherit_fields[order_field][3])
order_column = parent_obj._columns[order_field]
if order_column._classic_read:
inner_clause = self._inherits_join_calc(order_field, query)