如何解决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>
任何帮助将不胜感激
解决方法
我遇到了同样的问题,我意识到我忘记在“__init__.py”文件中导入文件。
,将 type="object"
放在首位:
<button type="object" name="button_custom_method" string="Please click me"/>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。