Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Kov
    • Nábytek
    • Jídlo
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • IT hardware a podpora
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Function or Method to Install or Uninstall a module in the res.config.settings model with "module_" Prefix

Odebírat

Get notified when there's activity on this post

This question has been flagged
moduleinstallOdoores.config.settingsodoo16features
3 Odpovědi
4070 Zobrazení
Avatar
Golam Mostafa

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.

0
Avatar
Zrušit
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Nejlepší odpověď

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

0
Avatar
Zrušit
Avatar
Kathiresan
Nejlepší odpověď

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]


0
Avatar
Zrušit
Avatar
Niyas Raphy (Walnut Software Solutions)
Nejlepší odpověď

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

0
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Odoo Windows Installation Assistance
install odoo16features
Avatar
Avatar
Avatar
2
čvc 24
2584
Knock off Issue - Payments - Odoo 16.0 E
Odoo odoo16features
Avatar
0
úno 24
2171
How to trigger payment reminder on all outstanding invoices? Odoo 16
Odoo odoo16features
Avatar
0
kvě 23
3444
odoo-14: I get an error when I try to install a module in Digital Ocean Vyřešeno
module install
Avatar
Avatar
1
dub 21
6622
Unable to install module Vyřešeno
module install
Avatar
Avatar
2
dub 15
5410
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now