Skip to content
Draft
Show file tree
Hide file tree
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
38 changes: 38 additions & 0 deletions openupgrade_scripts/scripts/base/19.0.1.3/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,41 @@ def migrate(env, version):
openupgrade.rename_xmlids(env.cr, _renamed_xmlids)
openupgrade.rename_xmlids(env.cr, _merged_xmlids, allow_merge=True)
openupgrade.rename_fields(env, _renamed_fields)
_strip_removed_search_view_attrs(env)


def _strip_removed_search_view_attrs(env):
"""Strip 19.0 RNG-removed attrs (`expand=` on <group>/<field>,
`string="Group By"` on <group>) from stored search-view arch_db.
"""
openupgrade.logged_query(
env.cr,
r"""
UPDATE ir_ui_view v
SET arch_db = sub.new_arch
FROM (
SELECT id,
jsonb_object_agg(
lang,
to_jsonb(
regexp_replace(
regexp_replace(content,
'(<(?:group|field)[^>]*?)\s+expand="[^"]*"',
'\1', 'g'),
'(<group[^>]*?)\s+string="Group By"',
'\1', 'g'
)
)
) AS new_arch
FROM (
SELECT v2.id, je.key AS lang, je.value #>> '{}' AS content
FROM ir_ui_view v2, jsonb_each(v2.arch_db) je
WHERE v2.type='search'
AND (v2.arch_db::text LIKE '%%expand=%%'
OR v2.arch_db::text LIKE '%%string="Group By"%%')
) flat
GROUP BY id
) sub
WHERE v.id = sub.id
""",
)
38 changes: 38 additions & 0 deletions openupgrade_scripts/scripts/base/tests/data_base_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,42 @@
],
}
)

# Search-view fixtures for the 19.0 RNG attribute strip helper.
# `expand=` on <group>/<field> and `string="Group By"` on <group>
# were valid in 18.0 but rejected by 19.0's stricter RelaxNG schema.
env["ir.ui.view"].create(
{
"name": "test search group_expand",
"model": "res.partner",
"type": "search",
"arch": """
<search>
<field name="name"/>
<group expand="0" string="Group By">
<filter
string="Country"
name="country"
context="{'group_by': 'country_id'}"
/>
</group>
</search>
""",
}
)
env["ir.ui.view"].create(
{
"name": "test search field_expand",
"model": "res.partner",
"type": "search",
"arch": """
<search>
<field name="name"/>
<searchpanel>
<field name="country_id" expand="1" select="multi"/>
</searchpanel>
</search>
""",
}
)
env.cr.commit()
38 changes: 38 additions & 0 deletions openupgrade_scripts/scripts/base/tests/test_base_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,41 @@ def test_server_action_child_ids(self):
action2.child_ids.mapped("name"),
("child action 1", "child action 2", "child action 3"),
)

def test_strip_removed_search_view_attrs(self):
"""19.0 RNG-removed attrs (`expand=` on <group>/<field>,
`string="Group By"` on <group>) are stripped from arch_db
on search views; legitimate attrs are preserved.
"""
view_group = self.env["ir.ui.view"].search(
[("name", "=", "test search group_expand")]
)
self.assertTrue(view_group)
arch_group = view_group.arch_db
self.assertNotIn(
'expand="0"',
arch_group,
"expand= should be stripped from <group> in search arch",
)
self.assertNotIn(
'string="Group By"',
arch_group,
'string="Group By" should be stripped from <group>',
)
# Legit attrs preserved
self.assertIn('name="country"', arch_group)
self.assertIn('string="Country"', arch_group)

view_field = self.env["ir.ui.view"].search(
[("name", "=", "test search field_expand")]
)
self.assertTrue(view_field)
arch_field = view_field.arch_db
self.assertNotIn(
'expand="1"',
arch_field,
"expand= should be stripped from <field> in searchpanel",
)
# Legit attrs preserved
self.assertIn('select="multi"', arch_field)
self.assertIn('name="country_id"', arch_field)
Loading