Odoo Python 函数 TypeError: EventBooth.check_app_installed() 缺少 1 个必需的位置参数: 'self'

Odoo Python Function TypeError: EventBooth.check_app_installed() missing 1 required positional argument: 'self'

提问人:Perino 提问时间:5/27/2023 更新时间:5/28/2023 访问量:39

问:

要使这种代码和平发挥作用,需要什么? 我总是收到错误“Function TypeError: EventBooth.check_app_installed() missing 1 required positional argument: 'self'”。同时,我尝试了很多不同的方法,但没有任何效果。

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')
python 函数 odoo self

评论

1赞 Waleed Mohsen 5/28/2023
由于代码中的此行而引发的错误。你到底想做什么?if check_app_installed():

答:

0赞 Kenly 5/28/2023 #1

为确保Odoo先于您加载模块,请将其添加到清单依赖项中。event

来自Odoo文档:

Odoo模块,必须在此模块之前加载,因为该模块使用它们创建的功能,或者因为它改变了它们定义的资源。

安装模块时,其所有依赖项都将在该模块之前安装。同样,依赖项在加载模块之前加载。

要创建可选依赖项,请查看 Odoo 14 CE 答案中的可选依赖项