模块信息存储在ir.module.module 数据表中
平时在开发过程中经常会刷新本地模块列表,例如:新增了模块、更新了模块基础信息、更换了模块图标等等,在点击‘更新’按钮的时候odoo平台到底干了哪些事?
后台代码:
# update the list of available packages@assert_log_admin_access@api.modeldef update_list(self): res = [0, 0] # [update, add] default_version = modules.adapt_version(‘1.0‘) known_mods = self.with_context(lang=None).search([]) known_mods_names = {mod.name: mod for mod in known_mods} # iterate through detected modules and update/create them in db for mod_name in modules.get_modules(): mod = known_mods_names.get(mod_name) terp = self.get_module_info(mod_name) values = self.get_values_from_terp(terp) if mod: updated_values = {} for key in values: old = getattr(mod, key) updated = tools.ustr(values[key]) if isinstance(values[key], pycompat.string_types) else values[key] if (old or updated) and updated != old: updated_values[key] = values[key] if terp.get(‘installable‘, True) and mod.state == ‘uninstallable‘: updated_values[‘state‘] = ‘uninstalled‘ if parse_version(terp.get(‘version‘, default_version)) > parse_version(mod.latest_version or default_version): res[0] += 1 if updated_values: mod.write(updated_values) else: mod_path = modules.get_module_path(mod_name) if not mod_path: continue if not terp or not terp.get(‘installable‘, True): continue mod = self.create(dict(name=mod_name, state=‘uninstalled‘, **values)) res[1] += 1 mod._update_dependencies(terp.get(‘depends‘, [])) mod._update_exclusions(terp.get(‘excludes‘, [])) mod._update_category(terp.get(‘category‘, ‘Uncategorized‘)) return res
注解1:
@assert_log_admin_access:验证是否为administrator用户,其实就是在验证是否具有管理员权限,跟踪了一下后台调用user._is_admin,如果在验证的时候如果不是administrator权限用户就会跳出异常。注解2:
@staticmethoddef get_values_from_terp(terp): return { ‘description‘: terp.get(‘description‘, ‘‘), ‘shortdesc‘: terp.get(‘name‘, ‘‘), ‘author‘: terp.get(‘author‘, ‘Unknown‘), ‘maintainer‘: terp.get(‘maintainer‘, False), ‘contributors‘: ‘, ‘.join(terp.get(‘contributors‘, [])) or False, ‘website‘: terp.get(‘website‘, ‘‘), ‘license‘: terp.get(‘license‘, ‘LGPL-3‘), ‘sequence‘: terp.get(‘sequence‘, 100), ‘application‘: terp.get(‘application‘, False), ‘auto_install‘: terp.get(‘auto_install‘, False), ‘icon‘: terp.get(‘icon‘, False), ‘summary‘: terp.get(‘summary‘, ‘‘), ‘url‘: terp.get(‘url‘) or terp.get(‘live_test_url‘, ‘‘), ‘to_buy‘: False } 在执行update_list方式中条用get_values_from_terp方法,返回应用信息,判断是否与old信息一致,执行更新write方法。在icon字段方面,在模型ir.module.module中还有一个icon_image字段,以base64形式存储icon,在icon更新时触发icon_image的更新写入操作:
@api.depends(‘icon‘)def _get_icon_image(self): for module in self: module.icon_image = ‘‘ if module.icon: path_parts = module.icon.split(‘/‘) path = modules.get_module_resource(path_parts[1], *path_parts[2:]) else: path = modules.module.get_module_icon(module.name) if path: with tools.file_open(path, ‘rb‘) as image_file: module.icon_image = base64.b64encode(image_file.read()) 以上为当前的理解,但仍有一事不明:这两个_name = "ir.module.module"什么关系?
原文地址:https://www.cnblogs.com/yanhuaqiang/p/10631890.html
时间: 2024-11-10 19:09:11