简体   繁体   English

Odoo:如何检查模块是否已安装?

[英]Odoo: How to check Module has been installed or not?

I want to inherit form view in XML to set invisible some fields but sometime I will not install that module. 我想继承XML中的表单视图以设置某些字段不可见,但有时我不会安装该模块。

How to solve this? 如何解决呢?

You can add this code to the model of the view you want to modify: 您可以将此代码添加到要修改的视图的模型中:

@api.depends()
def _compute_module_x_installed(self):
    for record in self:
        module = self.env['ir.module.module'].search([
            ('name', '=', 'the_module_name')
        ])
        if module and module.state == 'installed':
            record.update({
                'module_x_installed': True,
            })

module_x_installed = fields.Boolean(
    compute='_compute_module_x_installed',
    string='Is X installed?',
)

That way you'll have a field which will indicate you whether the module is installed or not. 这样,您将拥有一个字段,该字段将指示您是否已安装模块。

You can also achieve the current status of the module with the help of ir_module_module database table. 您还可以借助ir_module_module数据库表来获取模块的当前状态。

ir.module.module model Odoo create a new database table which named is ir_module_module where we can search the status of our module through SQL Query using Pgadmin Tools ir.module.module模型Odoo创建一个名为ir_module_module的新数据库表,在此我们可以使用Pgadmin工具通过SQL查询来搜索模块的状态

select state from ir_module_module where name='Your_module_name(technical_name)';

If we get the result is ' installed ' in out query it means our module is installed in our database. 如果我们得到的结果是“安装”在外查询中,则意味着我们的模块已安装在数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Odoo:检查是否安装了模块 - Odoo: Check if a module is installed 如何检查python模块是否已导入? - How to check if a python module has been imported? ModuleNotFound 错误,但模块刚刚安装 - ModuleNotFound error but module has just been installed 如何修复模块未找到错误:当模块绝对安装时,没有名为'keras'的模块 - How to fix Module Not Found Error: No module named 'keras'when the module absolutly has been installed 如何检查是否已导入python模块? - How do I check if a python module has been imported? Python在安装的时候说一个模块没有安装 - Python is saying that a module has not been installed when it is installed 如何检查是否已为 VIRTUALENVWRAPPER_PYTHON=/usr/bin/python 等安装了 virtualenvwrapper - How to check that virtualenvwrapper has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/bin/python etc 该模块已成功安装,但导入时未找到? - Python - The module has been successfully installed but then it's not found when imported? - Python 尽管已正确安装,但导入请求模块无法正常工作 - Import requests module not working although it has already been installed properly 如何检查 class 是否已在同一模块内的另一个 class 中使用? - How do I check if a class has been used in another class within the same module?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM