[FIX] base: allow browsing form view of missing module
Before this patch, if you once had one module available and, later, remove it, you'd be getting an exception when browsing its form view and trying to get its icon image. Now it gets the base module icon image, just like it should. @moduon MT-1524 closes odoo/odoo#151870 X-original-commit: 4543f45e0066814d5722acfcac3c8bc8d09b8cb1 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com> Co-authored-by: xmo-odoo <xmo@odoo.com>
This commit is contained in:
committed by
Xavier Morel
co-authored by
xmo-odoo
parent
5047377ff6
commit
18b4902a19
@@ -248,15 +248,14 @@ class Module(models.Model):
|
||||
|
||||
@api.depends('icon')
|
||||
def _get_icon_image(self):
|
||||
self.icon_image = ''
|
||||
for module in self:
|
||||
module.icon_image = ''
|
||||
if not module.id:
|
||||
continue
|
||||
if module.icon:
|
||||
path_parts = module.icon.split('/')
|
||||
path = os.path.join(path_parts[1], *path_parts[2:])
|
||||
elif module.id:
|
||||
path = modules.module.get_module_icon_path(module)
|
||||
path = os.path.join(module.icon.lstrip("/"))
|
||||
else:
|
||||
path = ''
|
||||
path = modules.module.get_module_icon_path(module)
|
||||
if path:
|
||||
try:
|
||||
with tools.file_open(path, 'rb') as image_file:
|
||||
|
||||
@@ -24,6 +24,7 @@ from . import test_ir_filters
|
||||
from . import test_ir_http
|
||||
from . import test_ir_mail_server
|
||||
from . import test_ir_model
|
||||
from . import test_ir_module
|
||||
from . import test_ir_sequence
|
||||
from . import test_ir_sequence_date_range
|
||||
from . import test_ir_default
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
class IrModuleCase(TransactionCase):
|
||||
@mute_logger("odoo.modules.module")
|
||||
def test_missing_module_icon(self):
|
||||
module = self.env["ir.module.module"].create({"name": "missing"})
|
||||
base = self.env["ir.module.module"].search([("name", "=", "base")])
|
||||
self.assertEqual(base.icon_image, module.icon_image)
|
||||
|
||||
@mute_logger("odoo.modules.module")
|
||||
def test_new_module_icon(self):
|
||||
module = self.env["ir.module.module"].new({"name": "missing"})
|
||||
self.assertFalse(module.icon_image)
|
||||
|
||||
@mute_logger("odoo.modules.module")
|
||||
def test_module_wrong_icon(self):
|
||||
module = self.env["ir.module.module"].create(
|
||||
{"name": "wrong_icon", "icon": "/not/valid.png"}
|
||||
)
|
||||
self.assertFalse(module.icon_image)
|
||||
Reference in New Issue
Block a user