首页 > 解决方案 > Odoo 14“my_method_name”对“my_module_name”无效

问题描述

我正在学习 odoo 14,我正在尝试在我的表单视图中添加一个按钮。不幸的是,每次我尝试升级我的自定义模块时,我都会收到此错误:

odoo.exceptions.ValidationError: Error while validating view:

button_custom_method is not a valid action on library.book

我的自定义模块 python 文件library_book.py

from odoo import models, fields, api

class LibraryBook(models.Model):
    _name = 'library.book'
    _description = 'Library Book'

    name = fields.Char('Title', required=True)
    date_release = fields.Date('Release Date')
    author_ids = fields.Many2many('res.partner', string='Authors')
    
    def button_custom_method(self):
        print("Button custom text")

而我的观点library_book.xml

<odoo>
    <!-- Form View -->
    <record id="library_book_view_form" model="ir.ui.view">
        <field name="name">Library Book Form</field>
        <field name="model">library.book</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <button name="button_custom_method" string="Please click me" type="object"/>
                </header>
                <group>
                    <group>
                        <field name="name"/>
                        <field name="author_ids" widget="many2many_tags"/>
                    </group>
                    <group>
                        <field name="date_release"/>
                    </group>
                </group>
            </form>
        </field>
    </record>
</odoo>

标签: pythonpython-3.xodooodoo-14

解决方案


我遇到的问题与我意识到我忘记将文件导入“__init__.py”文件中的问题相同。


推荐阅读