Skip to content
Snippets Groups Projects
Commit 77939849 authored by Denis Ledoux's avatar Denis Ledoux
Browse files

[FIX] base_import_module: restore module icon


The revision dd3f918c
introduced a regression:
it was no longer possible to set an icon in the import module,
and if no icon is provided,
the icon should fall back to the base module icon,
which wasn't the case either.

In this last case, it even leaded to a crash:
```
File "/home/odoo/src/14.0/odoo/odoo/addons/base/models/ir_module.py", line 251, in _get_icon_image
    with tools.file_open(path, 'rb') as image_file:
  File "/home/odoo/src/14.0/odoo/odoo/tools/misc.py", line 176, in file_open
    return _fileopen(name, mode=mode, basedir=base, pathinfo=pathinfo, basename=basename, filter_ext=filter_ext)
  File "/home/odoo/src/14.0/odoo/odoo/tools/misc.py", line 211, in _fileopen
    raise ValueError("Unknown path: %s" % name)
Exception
ValueError: Unknown path: /base/static/description/icon.png
```

opw-3340652

closes odoo/odoo#124307

Signed-off-by: default avatarDenis Ledoux (dle) <dle@odoo.com>
parent e056bc44
No related branches found
No related tags found
No related merge requests found
......@@ -58,6 +58,10 @@ class IrModule(models.Model):
terp.update(ast.literal_eval(f.read().decode()))
if not terp:
return False
if not terp.get('icon'):
icon_path = 'static/description/icon.png'
module_icon = module if os.path.exists(opj(path, icon_path)) else 'base'
terp['icon'] = opj('/', module_icon, icon_path)
values = self.get_values_from_terp(terp)
if 'version' in terp:
values['latest_version'] = terp['version']
......
......@@ -10,7 +10,7 @@ from unittest.mock import patch
from odoo.addons import __path__ as __addons_path__
from odoo.tools import mute_logger
from odoo.tests.common import TransactionCase
from odoo.tests.common import TransactionCase, HttpCase
class TestImportModule(TransactionCase):
def import_zipfile(self, files):
......@@ -189,3 +189,20 @@ class TestImportModule(TransactionCase):
static_attachment = self.env['ir.attachment'].search([('url', '=', '/%s' % static_path)])
self.assertEqual(static_attachment.name, os.path.basename(static_path))
self.assertEqual(static_attachment.datas, base64.b64encode(static_data))
class TestImportModuleHttp(TestImportModule, HttpCase):
def test_import_module_icon(self):
"""Assert import a module with an icon result in the module displaying the icon in the apps menu,
and with the base module icon if module without icon"""
files = [
('foo/__manifest__.py', b"{'name': 'foo'}"),
('foo/static/description/icon.png', b"foo_icon"),
('bar/__manifest__.py', b"{'name': 'bar'}"),
]
self.import_zipfile(files)
foo_icon_path, foo_icon_data = files[1]
# Assert icon of module foo, which must be the icon provided in the zip
self.assertEqual(self.url_open('/' + foo_icon_path).content, foo_icon_data)
# Assert icon of module bar, which must be the icon of the base module as none was provided
self.assertEqual(self.env.ref('base.module_bar').icon_image, self.env.ref('base.module_base').icon_image)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment