When we declare any field with a "module_" prefix and add a module name after that in the res.config.settings model as a boolean field, on making it True or False, it will install or uninstall the module. I am trying to find out which function or method is being called from the back-end side to install or uninstall the module. Can anyone tell me? I am using Odoo 16.
Thank you.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
Hi,
path of function : addons/base/models/res_config.py
You can check the following function
def execute(self):
"""
Called when settings are saved.
This method will call `set_values` and will install/uninstall any modules defined by
`module_` Boolean fields and then trigger a web client reload.
.. warning::
This method **SHOULD NOT** be overridden, in most cases what you want to override is
`~set_values()` since `~execute()` does little more than simply call `~set_values()`.
The part that installs/uninstalls modules **MUST ALWAYS** be at the end of the
transaction, otherwise there's a big risk of registry database desynchronisation.
"""
self.ensure_one()
if not self.env.is_admin():
raise AccessError(_("Only administrators can change the settings"))
self = self.with_context(active_test=False)
classified = self._get_classified_fields()
self.set_values()
# module fields: install/uninstall the selected modules
to_install = classified['module'].filtered(
lambda m: self[f'module_{m.name}'] and m.state != 'installed')
to_uninstall = classified['module'].filtered(
lambda m: not self[f'module_{m.name}'] and m.state in ('installed', 'to upgrade'))
if to_install or to_uninstall:
self.env.flush_all()
if to_uninstall:
to_uninstall.button_immediate_uninstall()
installation_status = self._install_modules(to_install)
if installation_status or to_uninstall:
# After the uninstall/install calls, the registry and environments
# are no longer valid. So we reset the environment.
self.env.reset()
self = self.env()[self._name]
# pylint: disable=next-method-called
config = self.env['res.config'].next() or {}
if config.get('type') not in ('ir.actions.act_window_close',):
return config
# force client-side reload (update user menu and current view)
return {
'type': 'ir.actions.client',
'tag': 'reload',
}
Regards
I employ the 'pre_init_hook' method during installation, and automatically uninstall and install certain modules. Give this approach a try.
#uninstall module
def _pre_init_uninstall_modules(cr):
env = api.Environment(cr, SUPERUSER_ID, {})
modules = env['ir.module.module'].search([('name', 'in', ['your_module_name']),('state','=','installed')])
if modules:
[module.sudo().module_uninstall() for module in modules]
#install module
from odoo import api, SUPERUSER_ID
def _pre_init_install_modules(cr):
env = api.Environment(cr, SUPERUSER_ID, {})
modules = env['ir.module.module'].search([('name', 'in', ['your_module_name',
]),('state','=','uninstalled')])
if modules:
[module.sudo().button_install() for module in modules]
Hi,
You can check out def execute(self): function in res.config.settings model.
Relevant code lines:
# module fields: install/uninstall the selected modules
to_install = classified['module'].filtered(
lambda m: self[f'module_{m.name}'] and m.state != 'installed')
to_uninstall = classified['module'].filtered(
lambda m: not self[f'module_{m.name}'] and m.state in ('installed', 'to upgrade'))
if to_install or to_uninstall:
self.env.flush_all()
if to_uninstall:
to_uninstall.button_immediate_uninstall()
installation_status = self._install_modules(to_install)
Thanks
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
2
thg 7 24
|
1971 | ||
|
0
thg 2 24
|
1415 | ||
|
0
thg 5 23
|
2388 | ||
|
1
thg 4 21
|
5923 | ||
Unable to install module
Đã xử lý
|
|
2
thg 4 15
|
4732 |