Skip to content

Commit 53a7d14

Browse files
[IMP] openupgrade_framework: remove FKs of obsolete tables/columns
1 parent 34507b3 commit 53a7d14

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

  • openupgrade_framework/odoo_patch/odoo/addons/base/models

openupgrade_framework/odoo_patch/odoo/addons/base/models/ir_model.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33
from openupgradelib import openupgrade
44

5-
from odoo import api, models
5+
from odoo import api, models, tools
66
from odoo.tools import mute_logger
77

88
from odoo.addons.base.models.ir_model import (
@@ -17,7 +17,11 @@
1717
def _drop_table(self):
1818
"""Never drop tables"""
1919
for model in self:
20-
if self.env.get(model.model) is not None:
20+
current_model = self.env.get(model.model)
21+
if current_model is not None:
22+
table = current_model._table
23+
if tools.table_kind(self._cr, table) == "r":
24+
openupgrade.remove_tables_fks(self.env.cr, [table])
2125
openupgrade.message(
2226
self.env.cr,
2327
"Unknown",
@@ -36,6 +40,15 @@ def _drop_column(self):
3640
for field in self:
3741
if field.name in models.MAGIC_COLUMNS:
3842
continue
43+
model = self.env.get(field.model)
44+
if (
45+
field.store
46+
and field.ttype == "many2one"
47+
and model is not None
48+
and tools.column_exists(self._cr, model._table, field.name)
49+
and tools.table_kind(self._cr, model._table) == "r"
50+
):
51+
openupgrade.lift_constraints(self.env.cr, model._table, field.name)
3952
openupgrade.message(
4053
self.env.cr,
4154
"Unknown",

0 commit comments

Comments
 (0)