Skip to content

Commit

Permalink
3fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dc-oerp committed Mar 28, 2024
1 parent 51438be commit d89d49e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
14 changes: 9 additions & 5 deletions web_favicon/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,15 @@ def _get_favicon(self):
if request.httprequest.cookies.get("cids")
else False
)
if company_id and self.browse(int(company_id)).sudo().favicon:
sudo_record = self.env.company.sudo()
sha = hashlib.sha512(
str(sudo_record.write_date).encode("utf-8")
).hexdigest()[:7]
company = (
self.browse(int(company_id.split(",")[0])).sudo()
if company_id and self.browse(int(company_id.split(",")[0])).sudo().favicon
else False
)
if company:
sha = hashlib.sha512(str(company.write_date).encode("utf-8")).hexdigest()[
:7
]
return f"/web/image/{self._name}/{company_id}/favicon?unique={sha}"
else:
return False
13 changes: 3 additions & 10 deletions web_favicon/tests/test_web_favicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,12 @@ def test_01_web_favicon(self):
self.assertEqual(image.format, "JPEG")
self.assertEqual(image.size, (1920, 1080))
self.assertEqual(image.getpixel((0, 0)), bg_color)
with MockRequest(self.env) as mock_request:
mock_request.httprequest.cookies = {"cids": str(company.id)}
self.assertTrue(Company._get_favicon())

def test_02_default_favicon_creation(self):
"""Test if default favicon is set when creating a company without specifying a favicon."""
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_get_favicon_returns_false(self):
"""Test if _get_favicon() returns False when certain conditions are not met."""
Company = self.env["res.company"].create({"name": "Company for Testing"})
with MockRequest(self.env):
# Call _get_favicon() without company id to trigger the condition
self.assertFalse(
Company._get_favicon(),
"_get_favicon() should return False when company id is not present.",
)

0 comments on commit d89d49e

Please sign in to comment.