Skip to content

Commit

Permalink
fixup! fixup! optimizegit stgit stgit stgit stgit st
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Torres committed Jul 20, 2018
1 parent 6201963 commit 2bce2a3
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions odoo/addons/base/ir/ir_model.py
Expand Up @@ -547,25 +547,22 @@ def _prepare_update(self):
that have an inverse one2many, for instance.
"""
failed_dependencies = []
# for candidate in candidates:
for rec in self:
model = self.env[rec.model]
field = model._fields[rec.name]
for dependant, path in model._field_triggers.get(field, ()):
if dependant.manual:
failed_dependencies.append((self._get(dependant.model_name, dependant.name),
rec))
failed_dependencies.append((field, dependant))
for inverse in model._field_inverses.get(field, ()):
if inverse.manual and inverse.type == 'one2many':
failed_dependencies.append((self._get(inverse.model_name, inverse.name), rec))
failed_dependencies.append((field, dependant))

if not self._context.get(MODULE_UNINSTALL_FLAG) and failed_dependencies:
# do not unlink candidate if not in uninstall mode
msg = _("The field '%s' cannot be removed because the field '%s' depends on it.")
raise UserError(msg % failed_dependencies[0])
elif failed_dependencies:
candidates_to_delete = [rel[0] for rel in failed_dependencies]
self.browse().union(*candidates_to_delete).unlink()
to_unlink = [self._get(rel[1].model_name, rel[1].name) for rel in failed_dependencies]
self.browse().union(*to_unlink).unlink()

self = self.filtered(lambda record: record.state == 'manual')
if not self:
Expand Down

0 comments on commit 2bce2a3

Please sign in to comment.