1

我正在学习 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>
4

2 回答 2

2

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

于 2021-04-22T10:12:40.187 回答
-2

先放type="object"

<button type="object" name="button_custom_method" string="Please click me"/>
于 2021-05-17T08:14:40.573 回答