3636from psycopg2 .extras import Json
3737
3838try :
39+ from odoo .modules import get_modules
3940 from odoo .modules import module as odoo_module
4041 from odoo .sql_db import db_connect
4142except ImportError :
43+ from openerp .modules import get_modules
4244 from openerp .sql_db import db_connect
4345
4446 odoo_module = None
@@ -1462,6 +1464,7 @@ def update_m2m_tables(cr, old_table, new_table, ignored_m2ms=()):
14621464 if old_table == new_table or not version_gte ("10.0" ):
14631465 return
14641466 ignored_m2ms = set (ignored_m2ms )
1467+ standard_modules = set (get_modules ()) - {"studio_customization" , "__cloc_exclude__" }
14651468 for orig_m2m_table in get_m2m_tables (cr , new_table ):
14661469 if orig_m2m_table in ignored_m2ms :
14671470 continue
@@ -1474,12 +1477,18 @@ def update_m2m_tables(cr, old_table, new_table, ignored_m2ms=()):
14741477 rename_table (cr , orig_m2m_table , m2m_table , remove_constraints = False )
14751478 cr .execute (
14761479 """
1477- UPDATE ir_model_fields
1480+ UPDATE ir_model_fields f
14781481 SET relation_table = %s
1479- WHERE relation_table = %s
1480- AND state = 'manual'
1482+ FROM ir_model_data d
1483+ WHERE f.relation_table = %s
1484+ AND (
1485+ f.state = 'manual'
1486+ OR d.model = 'ir.model.fields'
1487+ AND d.res_id = f.id
1488+ AND d.module NOT IN %s
1489+ )
14811490 """ ,
1482- [m2m_table , orig_m2m_table ],
1491+ [m2m_table , orig_m2m_table , tuple ( standard_modules ) ],
14831492 )
14841493 _logger .info ("Renamed m2m table %s to %s" , orig_m2m_table , m2m_table )
14851494 else :
@@ -1531,23 +1540,35 @@ def update_m2m_tables(cr, old_table, new_table, ignored_m2ms=()):
15311540
15321541 cr .execute (
15331542 """
1534- UPDATE ir_model_fields
1543+ UPDATE ir_model_fields f
15351544 SET column1 = %s
1536- WHERE relation_table = %s
1537- AND column1 = %s
1538- AND state = 'manual'
1545+ FROM ir_model_data d
1546+ WHERE f.relation_table = %s
1547+ AND f.column1 = %s
1548+ AND (
1549+ f.state = 'manual'
1550+ OR d.model = 'ir.model.fields'
1551+ AND d.res_id = f.id
1552+ AND d.module NOT IN %s
1553+ )
15391554 """ ,
1540- [new_col , m2m_table , old_col ],
1555+ [new_col , m2m_table , old_col , tuple ( standard_modules ) ],
15411556 )
15421557 cr .execute (
15431558 """
1544- UPDATE ir_model_fields
1559+ UPDATE ir_model_fields f
15451560 SET column2 = %s
1546- WHERE relation_table = %s
1547- AND column2 = %s
1548- AND state = 'manual'
1561+ FROM ir_model_data d
1562+ WHERE f.relation_table = %s
1563+ AND f.column2 = %s
1564+ AND (
1565+ f.state = 'manual'
1566+ OR d.model = 'ir.model.fields'
1567+ AND d.res_id = f.id
1568+ AND d.module NOT IN %s
1569+ )
15491570 """ ,
1550- [new_col , m2m_table , old_col ],
1571+ [new_col , m2m_table , old_col , tuple ( standard_modules ) ],
15511572 )
15521573
15531574 _logger .info ("Renamed m2m column of table %s from %s to %s" , m2m_table , old_col , new_col )
0 commit comments