You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Odoo 18模块列表视图头部自定义按钮不显示求助

问题排查与修复方案

1. Python方法缩进错误(核心问题)

你的import_action方法未正确缩进,导致它不属于ProductProduct类,Odoo无法识别到该方法,因此按钮不会显示。

修复后的模型代码:

from odoo import models, fields, api

class ProductProduct(models.Model):
    _inherit = 'product.product' # Correct inheritance
    x_link = fields.Char(
        string='Product Link',
        help='URL of the product',
        default='',
        tracking=True # Shows changes in chatter
    )
    
    def import_action(self):
        # 列表视图中self为记录集合,原代码self.id会报错,需调整context逻辑
        return {
            'name': 'Import Products',
            'type': 'ir.actions.act_window',
            'res_model': 'product.import.wizard',
            'view_mode': 'form',
            'target': 'new',
            'context': {'default_product_ids': self.ids},
        }

2. XML视图name字段冗余引号

视图的name字段被额外双引号包裹,可能导致视图识别异常:
原代码:

<field name='name'>"electronic.product.list"</field>

修复为:

<field name="name">electronic.product.list</field>

3. 额外注意事项

  • 确保product.import.wizard模型已正确定义,否则点击按钮会触发报错
  • 列表视图按钮触发的方法默认接收多条记录,需在向导中适配多记录处理逻辑

4. 验证视图有效性

可通过以下步骤确认视图是否正常加载:

  • 进入设置 > 技术 > 用户界面 > 视图,搜索electronic.product.list,检查状态是否为有效
  • 清除浏览器缓存并重新加载页面,避免旧视图缓存干扰

内容的提问来源于stack exchange,提问作者user1929418

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 04:52:06