From a911014cd3c2f15a6b543e901b418335041afca1 Mon Sep 17 00:00:00 2001 From: Guillaume-gdi Date: Wed, 27 Mar 2024 10:15:10 +0100 Subject: [PATCH] [FIX] website, test_website: clear menu cache correctly [This commit] fixed an issue with the menu cache. Unfortunately, during the forward port, we missed updating the cache key according to what has been done in [this other commit]. This commit updates the cache key and improves the test. Steps to reproduce the bug fixed by this commit: - Render a website without a record URL in the menu (to the cache) - Edit the website's menu - Add a link to a product page (e.g., customizable-desk) - Add a link to another product (e.g., chair-floor-protection) - Save the menu - Click on the menu link to go to customizable-desk => At this point, the active menu element is correct - Click on the menu link to go to chair-floor-protection => The active menu element does not update This issue does not occur if there is a record like URL in the menu before the first render. [This commit]: https://github.com/odoo/odoo/commit/970c173530e5523d0e3242ad84dae6fe5e332d68 [this other commit]:https://github.com/odoo/odoo/commit/595aa248433246959a5fa9288e477091701c6a35 opw-3694651 opw-3750925 opw-3781668 closes odoo/odoo#159464 X-original-commit: 9b5647f2951cdd7bde214f860b5ea95d42d2a501 Signed-off-by: Romain Derie (rde) Signed-off-by: Guillaume Dieleman (gdi) --- addons/test_website/tests/test_menu.py | 7 +++++++ addons/website/models/website.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/test_website/tests/test_menu.py b/addons/test_website/tests/test_menu.py index bba560dbc0f..da44a37134b 100644 --- a/addons/test_website/tests/test_menu.py +++ b/addons/test_website/tests/test_menu.py @@ -21,6 +21,13 @@ class TestWebsiteMenu(HttpCase): controller_url = '/test_website/model_item/' website = self.env['website'].browse(1) + # First render to fill the cache. + with MockRequest(self.env, website=website, url_root='', path=f"{controller_url}{records[0].id}"): + html.fromstring(self.env['ir.qweb']._render('test_website.model_item', { + 'record': records[0], + 'main_object': records[0], + })) + self.env['website.menu'].create([{ 'name': records[0].name, 'url': f"{controller_url}{records[0].id}", diff --git a/addons/website/models/website.py b/addons/website/models/website.py index e4a07f98dfe..c20970801b4 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -189,7 +189,7 @@ class Website(models.Model): def _get_menu_ids(self): return self.env['website.menu'].search([('website_id', '=', self.id)]).ids - @tools.ormcache('self.env.uid', 'self.id') + @tools.ormcache('self.env.uid', 'self.id', cache='templates') def is_menu_cache_disabled(self): """ Checks if the website menu contains a record like url.