[FIX] base_import_module: set actual ID for installed industries

Currently, when you attempt to uninstall an industry module, you are met
with a 'record not found' error.

Cause
-----
The list of industry modules is fetched from `odoo.com`. Since they do not
exist in the database, they are all assigned an ID of `-1`.
This ends up causing an issue in case of uninstall because no record
with and ID of `-1` can be found.

Fix
---
When a module is installed, it gets a record in the database (and ID).
The fix simply uses that ID if it exists, instead of `-1`.

opw-3662239

closes odoo/odoo#148456

Signed-off-by: Séna Serge Nshimiyimana (sesn) <sesn@odoo.com>
This commit is contained in:
sesn-odoo
2024-01-10 10:28:11 +00:00
parent 236b0944ed
commit 69f6fcccd9
@@ -335,12 +335,12 @@ class IrModule(models.Model):
resp.raise_for_status()
modules_list = resp.json().get('result', [])
for mod in modules_list:
mod['id'] = -1
module_name = mod.get('name', module_name)
existing_mod = self.search([('name', '=', module_name), ('state', '=', 'installed')])
mod['id'] = existing_mod.id if existing_mod else -1
if 'icon' in fields:
mod['icon'] = f"{APPS_URL}{mod['icon']}"
if 'state' in fields:
existing_mod = self.search([('name', '=', module_name), ('state', '=', 'installed')])
if existing_mod:
mod['state'] = 'installed'
else: