0

What is necessary to make this peace of code working? I always get the error "Function TypeError: EventBooth.check_app_installed() missing 1 required positional argument: 'self'". Meanwhile I tried a lot of different approaches, but nothing worked.

from odoo import models, fields, api

class EventBooth(models.Model):
    _name = 'event.booth'

    @api.model
    def check_app_installed(self):
        # Check if the 'event' app is installed
        event_app_installed = self.env['ir.module.module'].search([('name', '=', 'event'), ('state', '=', 'installed')])
        
        return event_app_installed

    @api.model
    def create(self, vals):
        app_installed = self.check_app_installed()
        if not app_installed:
            # Install the 'event' app if it is not installed
            event_app = self.env['ir.module.module'].search([('name', '=', 'event')])
            event_app.button_immediate_install()

        # Continue with the creation of the record
        return super(EventBooth, self).create(vals)

    if check_app_installed():
        _inherit = 'event.booth'
        price = fields.Float(string='Price')
Perino
  • 608
  • 9
  • 30

1 Answers1

0

To ensure Odoo loads the event module before yours, add it to the manifest depends entry.

From Odoo documentation:

Odoo modules which must be loaded before this one, either because this module uses features they create or because it alters resources they define.

When a module is installed, all of its dependencies are installed before it. Likewise dependencies are loaded before a module is loaded.

To make optional dependencies, check Optional Dependencies in Odoo 14 CE answer

Kenly
  • 24,317
  • 7
  • 44
  • 60