1、Odoo框架

Odoo 的前身是 OpenERP,是一个开源的企业 ERP 系统。

Odoo是一套完整的系统,是一个开源框架,针对 ERP
的需求发展而来,适合定制出符合客户各种需求的ERP系统、电子商务系统、CMS、或者是网站。

Odoo系统是一个现代化的商业应用ERP组件,使用的是Python语言开发。它的开发过程都是模块化的。是典型的模型-视图-控制器(MVC)结构。

目前官方规定只支持安装PostgreSQL数据库。

ODOO有两个版本 -
企业版和社区版。社区版是开源的(代码公开),可以简单、自由获得;而企业版是闭源的,需要付费购买。

使用安全版数据库会出现以下问题:

  • psycopg2.OperationalError: connection to server at “192.168.3.5”,
    port 5866 failed: 致命错误: 角色 “odoo” 不存在;

  • psycopg2.OperationalError: connection to server at “192.168.3.5”,
    port 5866 failed: 致命错误: 数据库 “postgres” 不存在;

  • ERROR: 错误: 创建扩展 “pg_trgm” 权限不够;

  • psycopg2.errors.FeatureNotSupported: 错误: 不能更改系统字段
    “seclabel”;

2、适配过程

2.1 环境准备

  • 瀚高数据库安全版V4.5.10

  • Odoo17 社区开源版本

2.2 数据库设置

由于Odoo是不允许用pg自带的管理员角色–postgres,所以得创一个odoo使用数据库的角色。

安全版关闭三权

psql -U syssso
highgo=# select set_secure_param('hg_sepofpowers','off');

创建postgres、odoo用户

create user odoo superuser createdb login password 'Qwer@1234*#';
create user postgres superuser createdb createrole login inherit
password 'Qwer@1234*#';
create database postgres owner postgres;

2.2 odoo框架修改

核心思路:增加一个db_type 参数,使用瀚高数据库时做下特殊处理。

修改odoo.conf(./odoo.conf)

[options]
db_host = 192.168.3.5
db_port = 5866
db_user = odoo
db_password = Qwer@1234*#
db_type = highgo
default_productivity_apps = True
admin_passwd =$pbkdf2-sha512$600000$zBljLKVUytl7j9EagxBCKA$3..2yHoUGXgHHU7RPpivOEh1Tpr57J/IWbbkFIYAYQ3CSLE/Q1KDlicxEplCw1yOw7WMGcEiJJws0kOUMqzvHQ

修改 config.py(./odoo/tools/config.py)

#找到代码段**

class configmanager(object):
def __init__(self, fname=None):

#定位到268行

group.add_option("--db-template", dest="db_template",my_default="template0",help="specify a custom database template to create a new database")

#新增一个数据库类型参数

group.add_option("--db-type", dest="db_type",my_default="highgo",help="specify a database type to create a new database")

#定位到451行

# 新增一个数据库类型参数
# if defined do not take the configfile value even if the defined valueis None
keys = ['gevent_port', 'http_interface', 'http_port','longpolling_port', 'http_enable', 'x_sendfile','db_name', 'db_user', 'db_password', 'db_host', 'db_sslmode','db_port', 'db_template', 'db_type', 'logfile', 'pidfile','smtp_port','email_from', 'smtp_server', 'smtp_user', 'smtp_password','from_filter','smtp_ssl_certificate_filename', 'smtp_ssl_private_key_filename',
'db_maxconn', 'db_maxconn_gevent', 'import_partial','addons_path', 'upgrade_path','syslog', 'without_demo', 'screencasts', 'screenshots','dbfilter', 'log_level', 'log_db','log_db_level', 'geoip_city_db', 'geoip_country_db', 'dev_mode','shell_interface',
]

#定位到792行

# 添加数据库类型**
def get_db_type(self):return self.options.get('db_type', None)

# 添加数据库用户

def get_db_user(self):return self.options.get('db_user', None)

修改sql.py(./odoo/sql.py)

#定位到386行

def drop_not_null(cr, tablename, columnname):
""" Drop the NOT NULL constraint on the given column. """
db_type = odoo.tools.config.get_db_type()
if db_type is None:
cr.execute(SQL(
"ALTER TABLE %s ALTER COLUMN %s DROP NOT NULL",
SQL.identifier(tablename), SQL.identifier(columnname),
))
elif db_type != "highgo":
cr.execute(SQL(
"ALTER TABLE %s ALTER COLUMN %s DROP NOT NULL",
SQL.identifier(tablename), SQL.identifier(columnname),
))
elif db_type == "highgo":
if columnname !="seclabel":
cr.execute(SQL(
"ALTER TABLE %s ALTER COLUMN %s DROP NOT NULL",
SQL.identifier(tablename), SQL.identifier(columnname),
))

_schema.debug("Table %r: column %r: dropped constraint NOT NULL", tablename, columnname)

修改db.py (./odoo/service/db.py)

#定位到121行

db = odoo.sql_db.db_connect(name)
with db.cursor() as cr:
db_type = odoo.tools.config.get_db_type()
db_user = odoo.tools.config.get_db_user()
if db_type == "highgo":
cr.execute("set role sysdba")
cr.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm")
if odoo.tools.config['unaccent']:
cr.execute("CREATE EXTENSION IF NOT EXISTS unaccent")
# From PostgreSQL's point of view, making 'unaccent' immutable is incorrect
# because it depends on external data - see
# https://www.postgresql.org/message-id/flat/201012021544.oB2FiTn1041521@wwwmaster.postgresql.org#201012021544.oB2FiTn1041521@wwwmaster.postgresql.org
# But in the case of Odoo, we consider that those data don't
# change in the lifetime of a database. If they do change, all
# indexes created with this function become corrupted!
cr.execute("ALTER FUNCTION unaccent(text) IMMUTABLE")
if db_type == "highgo":
cr.execute(SQL("set role %s",SQL.identifier(db_user)))
except psycopg2.Error as e:
_logger.warning("Unable to create PostgreSQL extensions : %s", e)

验证

查看运行日志,有以下内容:

2026-03-08 05:18:29,874 8356 INFO ? odoo.service.server: HTTP service
(werkzeug) running on DESKTOP-78EM46I:8069

表明启动成功,浏览器输入地址:http://127.0.0.1:8069

  • Master Password:odoo.conf 配置的用户密码

  • Database Name:数据库名

  • Email:随便写

  • Password:随便写

    • 后面每次登录 会使用Email和Password

填入信息后,运行日志内容如下:

...
2026-03-08 06:12:57,210 5720 INFO None odoo.service.db: Create
database `odoo`.
...
2026-03-08 06:18:50,920 312 INFO odoo odoo.modules.loading: loading 1
modules...
...
2026-03-08 06:19:53,390 312 INFO odoo odoo.modules.registry: module
web: creating or updating database tables

出现这个界面,说明适配成功


输入之前填写的Email和Password

运行日志内容如下:

...
2026-03-08 06:21:10,703 312 INFO odoo
odoo.addons.base.models.res_users: Login successful for db:odoo login:1
from 192.168.3.2
...

进入主界面