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

Odoo v13自定义Web编辑器顶部菜单报服务已定义错误解决方法

Odoo13 自定义Summernote字号报重复服务错误解决方案

报错原因

  • 自定义JS模块使用官方web_editor命名空间,违反Odoo JS模块命名规范,触发重名冲突
  • 原资产挂载目标为summernote基础组件模板,通过last()规则插入脚本会导致脚本在多个资产包中重复加载,触发框架重复注册校验
  • 原逻辑仅修改全局Summernote配置,会被Odoo HTML字段的初始化配置覆盖,即使解决报错也无法正常生效

修正后代码

1. manifest.py

原配置逻辑正确,确认文件路径无误即可:

{
    "name": "Web editor custom",
    "summary": "Add font-sizes to the top-menu of the web editor",
    "version": "13.0.2.0.1",
    "installable": True,
    "depends": ["web_editor"],
    "data": ["templates/assets.xml"],
}

2. templates/assets.xml

改为直接挂载到前后端全局资产包,避免脚本重复插入:

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <template id="summernote_cust_backend" name="Custom summernote backend assets" inherit_id="web.assets_backend">
        <xpath expr="." position="inside">
            <script type="text/javascript" src="/webeditor_custom/static/src/js/summernote_cust.js"></script>
        </xpath>
    </template>
    <!-- 仅需后台编辑器生效可删除以下前台资产配置 -->
    <template id="summernote_cust_frontend" name="Custom summernote frontend assets" inherit_id="web.assets_frontend">
        <xpath expr="." position="inside">
            <script type="text/javascript" src="/webeditor_custom/static/src/js/summernote_cust.js"></script>
        </xpath>
    </template>
</odoo>

3. static/src/js/summernote_cust.js

修正模块命名,同时覆盖Odoo HTML字段的配置生成逻辑,保证字号配置生效:

odoo.define('webeditor_custom.summernote_cust', function (require) {
'use strict';

var core = require('web.core');
// 加载依赖
require('web_editor.summernote');
require('summernote/summernote');

var _t = core._t;
// 覆盖Summernote全局默认字号
$.summernote.options.fontSizes = [_t('Default'), 8, 9, 10, 11, 12, 13, 14, 16, 18, 21, 24, 28, 32, 36, 42, 49, 56, 63];

// 覆盖Odoo富文本字段的配置生成方法,避免全局配置被框架默认值覆盖
var FieldHtml = require('web_editor.field.html');
FieldHtml.include({
    _getSummernoteConfig: function () {
        var config = this._super.apply(this, arguments);
        config.fontSizes = [_t('Default'), 8, 9, 10, 11, 12, 13, 14, 16, 18, 21, 24, 28, 32, 36, 42, 49, 56, 63];
        return config;
    }
});
});

部署操作

  • 替换所有文件后重启Odoo服务,启动参数添加-u webeditor_custom升级模块
  • 进入开发者模式,清除浏览器缓存,删除系统中旧的资产缓存文件
  • 刷新页面即可看到编辑器字号菜单加载自定义选项,重复定义错误消失

效果参考:
编辑器自定义字号选项截图

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.29 22:42:15