Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

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

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
moduleinstallOdoores.config.settingsodoo16features
3 Răspunsuri
4071 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Imagine profil
Cybrosys Techno Solutions Pvt.Ltd
Cel mai bun răspuns

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
Imagine profil
Abandonează
Imagine profil
Kathiresan
Cel mai bun răspuns

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
Imagine profil
Abandonează
Imagine profil
Niyas Raphy (Walnut Software Solutions)
Cel mai bun răspuns

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
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Odoo Windows Installation Assistance
install odoo16features
Imagine profil
Imagine profil
Imagine profil
2
iul. 24
2584
Knock off Issue - Payments - Odoo 16.0 E
Odoo odoo16features
Imagine profil
0
feb. 24
2171
How to trigger payment reminder on all outstanding invoices? Odoo 16
Odoo odoo16features
Imagine profil
0
mai 23
3444
odoo-14: I get an error when I try to install a module in Digital Ocean Rezolvat
module install
Imagine profil
Imagine profil
1
apr. 21
6622
Unable to install module Rezolvat
module install
Imagine profil
Imagine profil
2
apr. 15
5410
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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