[IMP] orm/inherits: check that m2o fields implementing _inherits are marked required with ondelete cascade

Fix the issue if one is detected, either adding the missing field or forcing the attributes

bzr revid: odo@openerp.com-20100812200848-l8q72d44237gn5uk
This commit is contained in:
Olivier Dony
2010-08-12 22:08:48 +02:00
parent fe313162b6
commit 57191c139d
+12 -1
View File
@@ -2616,7 +2616,7 @@ class orm(orm_template):
self._columns[field['name']] = getattr(fields, field['ttype'])(field['relation'], _rel_name, 'id1', 'id2', **attrs)
else:
self._columns[field['name']] = getattr(fields, field['ttype'])(**attrs)
self._inherits_check()
self._inherits_reload()
if not self._sequence:
self._sequence = self._table+'_id_seq'
@@ -2734,6 +2734,17 @@ class orm(orm_template):
self._inherit_fields = res
self._inherits_reload_src()
def _inherits_check(self):
for table, field_name in self._inherits.items():
if field_name not in self._columns:
logging.getLogger('init').info('Missing many2one field definition for _inherits reference "%s" in "%s", using default one.' % (field_name, self._name))
self._columns[field_name] = fields.many2one(table, string="Automatically created field to link to parent %s" % table,
required=True, ondelete="cascade")
elif not self._columns[field_name].required or self._columns[field_name].ondelete.lower() != "cascade":
logging.getLogger('init').warning('Field definition for _inherits reference "%s" in "%s" must be marked as "required" with ondelete="cascade", forcing it.' % (field_name, self._name))
self._columns[field_name].required = True
self._columns[field_name].ondelete = "cascade"
#def __getattr__(self, name):
# """
# Proxies attribute accesses to the `inherits` parent so we can call methods defined on the inherited parent