diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 6d64b0f54d9..59aeeaeba4a 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -817,7 +817,7 @@ class Website(models.Model): website_id = self.env.context.get('website_id', False) if website_id: domain_static = [('website_id', 'in', (False, website_id))] - while self.env['website.page'].with_context(active_test=False).sudo().search([('key', '=', key_copy)] + domain_static): + while self.env['ir.ui.view'].with_context(active_test=False).sudo().search([('key', '=', key_copy)] + domain_static): inc += 1 key_copy = string + (inc and "-%s" % inc or "") return key_copy diff --git a/addons/website/tests/test_page.py b/addons/website/tests/test_page.py index fdb121489ae..f967d44be5e 100644 --- a/addons/website/tests/test_page.py +++ b/addons/website/tests/test_page.py @@ -1,14 +1,15 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. -from unittest.mock import patch -from odoo.http import root from lxml import html +from unittest.mock import patch +from odoo.addons.website.controllers.main import Website +from odoo.addons.website.tools import MockRequest +from odoo.fields import Command +from odoo.http import root from odoo.tests import common, HttpCase, tagged from odoo.tests.common import HOST from odoo.tools import config, mute_logger -from odoo.addons.website.tools import MockRequest -from odoo.fields import Command @tagged('-at_install', 'post_install') @@ -490,3 +491,14 @@ class WithContext(HttpCase): r2 = self.url_open('/Page_1', allow_redirects=False) self.assertEqual(r2.status_code, 303, "URL exists only in different casing, should redirect to it") self.assertTrue(r2.headers.get('Location').endswith('/page_1'), "Should redirect /Page_1 to /page_1") + +@tagged('-at_install', 'post_install') +class TestNewPage(common.TransactionCase): + def test_new_page_used_key(self): + website = self.env.ref('website.default_website') + controller = Website() + with MockRequest(self.env, website=website): + controller.pagenew(path="snippets") + pages = self.env['website.page'].search([('url', '=', '/snippets')]) + self.assertEqual(len(pages), 1, "Exactly one page should be at /snippets.") + self.assertNotEqual(pages.key, "website.snippets", "Page's key cannot be website.snippets.")