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

Odoo用户偏好通知模块Handle的移除/禁用/重命名需求

Odoo「用户-偏好-通知」中Handle选项的修改方案

针对你需要移除、禁用或重命名「用户-偏好-通知」路径下Handle选项的需求,以下是具体实现方案,同时解决无法编辑的问题:

核心前提说明

你遇到的无法直接编辑问题,大概率是因为该选项属于系统视图/模型的默认配置,无法直接在界面修改,必须通过自定义模块继承扩展的方式处理(开发者模式是必要前提)。


方案1:移除/隐藏Handle选项

方式1:视图层面隐藏(推荐,不修改模型数据)

找到用户偏好通知对应的视图(通常为base.res_users_view_form_preferences),通过视图继承隐藏目标选项:

<odoo>
    <record id="res_users_view_form_preferences_custom" model="ir.ui.view">
        <field name="name">res.users.view.form.preferences.custom</field>
        <field name="model">res.users</field>
        <field name="inherit_id" ref="base.res_users_view_form_preferences"/>
        <field name="arch" type="xml">
            <!-- 定位Handle对应的选项,根据实际字段调整xpath -->
            <xpath expr="//field[@name='notification_type']/option[@value='handle']" position="attributes">
                <attribute name="invisible">1</attribute>
            </xpath>
        </field>
    </record>
</odoo>

方式2:模型层面移除选项

继承res.users模型,重写对应的selection字段,直接剔除Handle选项:

from odoo import models, fields

class ResUsers(models.Model):
    _inherit = 'res.users'

    notification_type = fields.Selection(
        selection=[
            ('email', '邮件'),
            ('inbox', '收件箱'),
            # 移除('handle', 'Handle')条目
        ],
        string='通知类型',
        default='inbox',
    )

方案2:重命名Handle选项

方式1:视图层面修改显示名称

<xpath expr="//field[@name='notification_type']/option[@value='handle']" position="attributes">
    <attribute name="string">你的新名称</attribute>
</xpath>

方式2:模型层面修改标签

notification_type = fields.Selection(
    selection=[
        ('email', '邮件'),
        ('inbox', '收件箱'),
        ('handle', '你的新名称'),
    ],
    string='通知类型',
    default='inbox',
)

方案3:禁用Handle选项(不可选)

方式1:视图层面设置禁用

<xpath expr="//field[@name='notification_type']/option[@value='handle']" position="attributes">
    <attribute name="disabled">1</attribute>
</xpath>

方式2:模型层面添加约束限制

from odoo import models, api
from odoo.exceptions import ValidationError

class ResUsers(models.Model):
    _inherit = 'res.users'

    @api.constrains('notification_type')
    def _check_notification_type(self):
        for record in self:
            if record.notification_type == 'handle':
                raise ValidationError("该通知选项不可使用")

操作步骤总结

  1. 开启Odoo开发者模式,确认目标字段、视图的具体ID(可通过「设置-技术-视图-视图」搜索res.users相关偏好视图)。
  2. 创建自定义模块,将上述代码放入对应文件(视图代码放views/目录,模型代码放models/目录)。
  3. 安装并升级自定义模块,验证效果。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 22:05:07