|
12 | 12 | from psycopg2.extras import Json, execute_values
|
13 | 13 |
|
14 | 14 | try:
|
15 |
| - from odoo import release |
| 15 | + from odoo import modules, release |
16 | 16 | from odoo.tools.convert import xml_import
|
17 | 17 | from odoo.tools.misc import file_open
|
18 | 18 | from odoo.tools.translate import xml_translate
|
19 | 19 | except ImportError:
|
20 |
| - from openerp import release |
| 20 | + from openerp import modules, release |
21 | 21 | from openerp.tools.convert import xml_import
|
22 | 22 | from openerp.tools.misc import file_open
|
23 | 23 |
|
@@ -106,6 +106,16 @@ def remove_view(cr, xml_id=None, view_id=None, silent=False, key=None):
|
106 | 106 | for [v_id] in cr.fetchall():
|
107 | 107 | remove_view(cr, view_id=v_id, silent=silent, key=xml_id)
|
108 | 108 |
|
| 109 | + if not key and column_exists(cr, "ir_ui_view", "key"): |
| 110 | + cr.execute("SELECT key FROM ir_ui_view WHERE id = %s and key != %s", [view_id, xml_id]) |
| 111 | + [key] = cr.fetchone() or [None] |
| 112 | + |
| 113 | + # Occurrences of xml_id and key in the t-call of views are to be found and removed. |
| 114 | + if xml_id != "?": |
| 115 | + _remove_redundant_tcalls(cr, xml_id) |
| 116 | + if key and key != xml_id: |
| 117 | + _remove_redundant_tcalls(cr, key) |
| 118 | + |
109 | 119 | if not view_id:
|
110 | 120 | return
|
111 | 121 |
|
@@ -1784,3 +1794,47 @@ def remove_act_window_view_mode(cr, model, view_mode):
|
1784 | 1794 | """,
|
1785 | 1795 | [view_mode, default, model, view_mode, view_mode],
|
1786 | 1796 | )
|
| 1797 | + |
| 1798 | + |
| 1799 | +def _remove_redundant_tcalls(cr, match): |
| 1800 | + """ |
| 1801 | + Remove t-calls of the removed view. |
| 1802 | +
|
| 1803 | + This function removes the t-calls to `match`. |
| 1804 | +
|
| 1805 | + :param str match: t-calls value to remove, typically it would be a view's xml_id or key |
| 1806 | + """ |
| 1807 | + arch_col = ( |
| 1808 | + get_value_or_en_translation(cr, "ir_ui_view", "arch_db") |
| 1809 | + if column_exists(cr, "ir_ui_view", "arch_db") |
| 1810 | + else "arch" |
| 1811 | + ) |
| 1812 | + cr.execute( |
| 1813 | + format_query( |
| 1814 | + cr, |
| 1815 | + """ |
| 1816 | + SELECT iv.id, |
| 1817 | + imd.module, |
| 1818 | + imd.name |
| 1819 | + FROM ir_ui_view iv |
| 1820 | + LEFT JOIN ir_model_data imd |
| 1821 | + ON iv.id = imd.res_id |
| 1822 | + AND imd.model = 'ir.ui.view' |
| 1823 | + WHERE {} ~ %s |
| 1824 | + """, |
| 1825 | + sql.SQL(arch_col), |
| 1826 | + ), |
| 1827 | + [r"""\yt-call=(["']){}\1""".format(re.escape(match))], |
| 1828 | + ) |
| 1829 | + standard_modules = set(modules.get_modules()) - {"studio_customization"} |
| 1830 | + for vid, module, name in cr.fetchall(): |
| 1831 | + with edit_view(cr, view_id=vid) as arch: |
| 1832 | + for node in arch.findall(".//t[@t-call='{}']".format(match)): |
| 1833 | + node.getparent().remove(node) |
| 1834 | + if not module or module not in standard_modules: |
| 1835 | + _logger.info( |
| 1836 | + "The view %swith ID: %s has been updated, removed t-calls to deprecated %r", |
| 1837 | + ("`{}.{}` ".format(module, name) if module else ""), |
| 1838 | + vid, |
| 1839 | + match, |
| 1840 | + ) |
0 commit comments