Skip to content

Commit

Permalink
[FIX] web_favicon: Ensure web favicon is displayed on the website
Browse files Browse the repository at this point in the history
  • Loading branch information
rov-adhoc committed Jul 9, 2024
1 parent e2d9b8e commit e836b6b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions web_favicon/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def create(self, vals_list):
@api.model
def _get_favicon(self):
"""Returns a local url that points to the image field of a given record."""
if self.env.context.get("website_id"):
website = self.env["website"].browse(self.env.context.get("website_id"))
return website.image_url(website, "favicon")
company_id = (
request.httprequest.cookies.get("cids")
if request.httprequest.cookies.get("cids")
Expand Down
26 changes: 26 additions & 0 deletions web_favicon/tests/test_web_favicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,29 @@ def test_02_default_favicon_creation(self):
Company = self.env["res.company"]
company = Company.create({"name": "Test Company"})
self.assertTrue(company.favicon, "Default favicon not set on company creation.")

def test_03_website_favicon(self):
"""Test if favicon URL is correctly returned when website_id is in context."""
if self.env["ir.module.module"].search(
[("name", "=", "website"), ("state", "=", "installed")]
):
company = self.env["res.company"].create(
{
"name": "Test Company with Website",
}
)
website = self.env["website"].create(
{
"name": "Test Website",
"domain": "www.test.com",
"company_id": company.id,
}
)
website.favicon = website._default_favicon()
favicon_url = company.with_context(website_id=website.id)._get_favicon()
expected_favicon_url = website.image_url(website, "favicon")
self.assertEqual(
favicon_url,
expected_favicon_url,
"The favicon URL should match the expected value.",
)

0 comments on commit e836b6b

Please sign in to comment.