diff --git a/addons/base_import_module/models/ir_module.py b/addons/base_import_module/models/ir_module.py index 03c6147cdcc..aa999832217 100644 --- a/addons/base_import_module/models/ir_module.py +++ b/addons/base_import_module/models/ir_module.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import ast import base64 +import json import logging import lxml import os @@ -25,8 +26,6 @@ _logger = logging.getLogger(__name__) APPS_URL = "https://apps.odoo.com" MAX_FILE_SIZE = 100 * 1024 * 1024 # in megabytes -def to_tuple(t): - return tuple(map(to_tuple, t)) if isinstance(t, (list, tuple)) else t class IrModule(models.Model): _inherit = "ir.module.module" @@ -287,9 +286,8 @@ class IrModule(models.Model): @api.model def web_search_read(self, domain, specification, offset=0, limit=None, order=None, count_limit=None): if _domain_asks_for_industries(domain): - fields_name = tuple(specification.keys()) - domain_tuple = to_tuple(domain or []) - modules_list = self._get_modules_from_apps(fields_name, 'industries', False, domain_tuple, offset=offset, limit=limit) + fields_name = list(specification.keys()) + modules_list = self._get_modules_from_apps(fields_name, 'industries', False, domain, offset=offset, limit=limit) return { 'length': len(modules_list), 'records': modules_list, @@ -308,7 +306,7 @@ class IrModule(models.Model): } def web_read(self, specification): - fields = tuple(specification.keys()) + fields = list(specification.keys()) module_type = self.env.context.get('module_type', 'official') if module_type != 'official': modules_list = self._get_modules_from_apps(fields, module_type, self.env.context.get('module_name')) @@ -317,23 +315,20 @@ class IrModule(models.Model): return super().web_read(specification) @api.model - @ormcache('fields', 'module_type', 'module_name', 'domain', 'limit', 'offset') def _get_modules_from_apps(self, fields, module_type, module_name, domain=None, limit=None, offset=None): payload = { - 'series': major_version, - 'module_fields': fields, - 'module_type': module_type, - 'module_name': module_name, - 'domain': domain, - 'limit': limit, - 'offset': offset, + 'params': { + 'series': major_version, + 'module_fields': fields, + 'module_type': module_type, + 'module_name': module_name, + 'domain': domain, + 'limit': limit, + 'offset': offset, + } } try: - resp = requests.post( - f"{APPS_URL}/loempia/listdatamodules", - json={'params': payload}, - timeout=5.0, - ) + resp = self._call_apps(json.dumps(payload)) resp.raise_for_status() modules_list = resp.json().get('result', []) for mod in modules_list: @@ -357,6 +352,17 @@ class IrModule(models.Model): except requests.exceptions.ConnectionError: raise UserError(_('Connection to %s failed The list of industry modules cannot be fetched') % APPS_URL) + @api.model + @ormcache('payload') + def _call_apps(self, payload): + headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} + return requests.post( + f"{APPS_URL}/loempia/listdatamodules", + data=payload, + headers=headers, + timeout=5.0, + ) + @api.model @ormcache() def _get_industry_categories_from_apps(self):