File tree Expand file tree Collapse file tree
openupgrade_framework/odoo_patch/odoo/addons/base/models Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33from openupgradelib import openupgrade
44
5- from odoo import api , models
5+ from odoo import api , models , tools
66from odoo .tools import mute_logger
77
88from odoo .addons .base .models .ir_model import (
1717def _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" ,
You can’t perform that action at this time.
0 commit comments