From bdc76207ca2981490a2a1e8c8467f2f7ef01c5e8 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Wed, 24 Jul 2019 10:12:48 +0000 Subject: [PATCH] [FIX] website: fix primary inherit view validation when tree is COW'd Before this commit, it was not possible to install website_forum if the 'Main Frontent Layout' had been COW'd. When loading Forum Layout view which is a primary child view, it would crash during view validation, not finding the element to xpath. Triggering COW instead of copying fix the issue. opw-2036119 closes odoo/odoo#35138 Signed-off-by: Quentin Smetz (qsm) --- addons/website/models/ir_ui_view.py | 6 +---- addons/website/tests/test_views.py | 37 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index 93c5fb373b2..2f1b4c8d17e 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -134,12 +134,8 @@ class View(models.Model): ('website_id', '!=', None), ]) for specific_parent_view in specific_parent_views: - record.copy({ - # Set key to avoid copy() to generate an unique key as - # we want the specific view to have the same key - 'key': record.key, + record.with_context(website_id=specific_parent_view.website_id.id).write({ 'inherit_id': specific_parent_view.id, - 'website_id': specific_parent_view.website_id.id, }) return records diff --git a/addons/website/tests/test_views.py b/addons/website/tests/test_views.py index b8262bb11b8..38b3311ecbd 100644 --- a/addons/website/tests/test_views.py +++ b/addons/website/tests/test_views.py @@ -811,6 +811,43 @@ class TestCowViewSaving(common.TransactionCase): all_title_updated = specific_view.website_meta_title == self.base_view.website_meta_title == "A bug got fixed by updating this field" self.assertEqual(all_title_updated, True, "Update on top level generic views should also be applied on specific views") + def test_module_new_inherit_view_on_parent_already_forked_xpath_replace(self): + """ Deeper, more specific test of above behavior. + A module install should add/update the COW view (if allowed fields, + eg not modified or prohibited (website_id, inherit_id..)). + This test ensure it does not crash if the child view is a primary view. + """ + View = self.env['ir.ui.view'] + + # Simulate layout views + base_view = View.create({ + 'name': 'Main Frontend Layout', + 'type': 'qweb', + 'arch': '', + 'key': '_portal.frontend_layout', + }).with_context(load_all_views=True) + + inherit_view = View.create({ + 'name': 'Main layout', + 'mode': 'extension', + 'inherit_id': base_view.id, + 'arch': '', + 'key': '_website.layout', + }) + + # Trigger cow on website_sale hierarchy for website 1 + base_view.with_context(website_id=1).write({'name': 'Main Frontend Layout (W1)'}) + + # Simulate website_sale_comparison install, that's the real test, it + # should not crash. + View._load_records([dict(xml_id='_website_forum.layout', values={ + 'name': 'Forum Layout', + 'mode': 'primary', + 'inherit_id': inherit_view.id, + 'arch': '', + 'key': '_website_forum.layout', + })]) + def test_multiple_inherit_level(self): """ Test multi-level inheritance: Base