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

Odoo 16从动作启动向导时出现JS Bug问题排查

Odoo 16自定义模块JS错误问题

问题复现步骤

  • 在planned.money树视图中选择一条记录
  • 点击自定义动作按钮「Vérrouiller」,打开携带选中记录的向导
  • 点击向导内的记录行时触发JS错误

问题定位

已排查出问题根源:向导表单视图中,many2many类型的lines字段错误使用了one2many组件,且开启了tree视图的可编辑模式,导致前端JS逻辑冲突。

相关代码

向导模型代码

from odoo import models, fields

class LockPlannedMoney(models.TransientModel):
    _name = 'lock.planned.money'
    _description = 'Verrouillage de ligne de trésorerie'

    lines = fields.Many2many('planned.money', string='Lignes')

    def confirm_date(self):
        for line in self.lines:
            line.lock_button()

表单视图及动作代码

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <!--     ================ view  form  peridique ==============    -->
        <record id="lock_planned_money_form_view" model="ir.ui.view">
            <field name="name">lock.planned.money.view</field>
            <field name="model">lock.planned.money</field>
            <field name="arch" type="xml">
                <form>
                    <field name="lines" widget="one2many" mode="tree" nolabel="1" readonly="0">
                        <tree editable="bottom">
                            <field name="label" readonly="1" />
                            <field name="partner_id" readonly="1" />
                            <field name="type_id" readonly="1" />
                            <field name="date" readonly="1" />
                            <field name="predicted_date" readonly="1" />
                            <field name="due_date" />
                            <field name="lock_status" string=" " />
                        </tree>
                    </field>
                    <footer>
                        <button name="confirm_date" string="Confirmer" type="object" class="oe_highlight" />
                        <button special="cancel" string="Annuler" />
                    </footer>
                </form>
            </field>
        </record>

        <!-- Action de Verrouillage-->
        <record id="lock_button_action_wizard" model="ir.actions.act_window">
            <field name="name">Vérrouiller</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">lock.planned.money</field>
            <field name="view_id" ref="lock_planned_money_form_view" />
            <field name="context">{'default_lines': active_ids}</field>
            <field name="binding_model_id" ref="eloapps_cash_flow_forecast.model_planned_money" />
            <field name="view_mode">form</field>
            <field name="target">new</field>
        </record>
    </data>
</odoo>

解决建议

  1. 修正字段组件类型:移除lines字段的widget="one2many"属性,many2many字段无需指定该组件,Odoo会自动匹配对应前端组件
  2. 关闭tree视图可编辑模式:由于many2many关联的是已有业务记录,且多数字段已设为只读,将<tree editable="bottom">改为普通tree视图(删除editable="bottom"属性)
  3. 统一字段只读属性:如果无需编辑due_date字段,可将其设为只读,保持视图逻辑一致性

修改后的视图字段部分示例:

<field name="lines" mode="tree" nolabel="1">
    <tree>
        <field name="label" readonly="1" />
        <field name="partner_id" readonly="1" />
        <field name="type_id" readonly="1" />
        <field name="date" readonly="1" />
        <field name="predicted_date" readonly="1" />
        <field name="due_date" readonly="1" />
        <field name="lock_status" string=" " />
    </tree>
</field>

若确实需要编辑due_date字段,建议通过向导的后台逻辑批量处理,而非在many2many的tree视图中直接编辑,避免前端逻辑冲突。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 01:05:19