[FIX] base_import_module: restore module icon

The revision dd3f918cafebe26e5aa9dff1b2e484b7ed662140
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#124661

X-original-commit: 12ccfcf8d2ee936ec066de81c2dce2dd17348cb6
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
This commit is contained in:
Denis Ledoux
2023-06-12 19:46:23 +02:00
parent 365017a950
commit 67e37aeda6
2 changed files with 21 additions and 0 deletions
@@ -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']
@@ -281,3 +281,20 @@ class TestImportModule(odoo.tests.TransactionCase):
asset_data = self.env['ir.model.data'].search([('model', '=', 'ir.asset'), ('res_id', '=', asset.id)])
self.assertEqual(asset_data.module, 'test_module')
self.assertEqual(asset_data.name, f'{bundle}_/{path}'.replace(".", "_"))
class TestImportModuleHttp(TestImportModule, odoo.tests.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)