mirror of https://github.com/OCA/web.git
commit
f580c11dbd
|
@ -68,6 +68,9 @@ class ResCompany(models.Model):
|
||||||
@api.model
|
@api.model
|
||||||
def _get_favicon(self):
|
def _get_favicon(self):
|
||||||
"""Returns a local url that points to the image field of a given record."""
|
"""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 = (
|
company_id = (
|
||||||
request.httprequest.cookies.get("cids")
|
request.httprequest.cookies.get("cids")
|
||||||
if request.httprequest.cookies.get("cids")
|
if request.httprequest.cookies.get("cids")
|
||||||
|
|
|
@ -46,3 +46,29 @@ class TestWebFavicon(TransactionCase):
|
||||||
Company = self.env["res.company"]
|
Company = self.env["res.company"]
|
||||||
company = Company.create({"name": "Test Company"})
|
company = Company.create({"name": "Test Company"})
|
||||||
self.assertTrue(company.favicon, "Default favicon not set on company creation.")
|
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.",
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue