Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade

from odoo import api, models
from odoo import api, models, tools
from odoo.tools import mute_logger

from odoo.addons.base.models.ir_model import (
Expand All @@ -17,7 +17,11 @@
def _drop_table(self):
"""Never drop tables"""
for model in self:
if self.env.get(model.model) is not None:
current_model = self.env.get(model.model)
if current_model is not None:
table = current_model._table
if tools.table_kind(self._cr, table) == "r":
openupgrade.remove_tables_fks(self.env.cr, [table])
openupgrade.message(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can mention on the message that only removing FKs, but it's optional.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MiquelRForgeFlow let's finish this putting that message.

self.env.cr,
"Unknown",
Expand All @@ -36,6 +40,15 @@ def _drop_column(self):
for field in self:
if field.name in models.MAGIC_COLUMNS:
continue
model = self.env.get(field.model)
if (
field.store
and field.ttype == "many2one"
and model is not None
and tools.column_exists(self._cr, model._table, field.name)
and tools.table_kind(self._cr, model._table) == "r"
):
openupgrade.lift_constraints(self.env.cr, model._table, field.name)
openupgrade.message(
self.env.cr,
"Unknown",
Expand Down