[英]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.