Skip to content

Latest commit

 

History

History
356 lines (254 loc) · 9.57 KB

odoo.md

File metadata and controls

356 lines (254 loc) · 9.57 KB

一、odoo访问远程pg数据库

数据库服务器设置:

1.修改postgresql.conf文件

sudo vim /etc/postgresql/10/main/postgresql.conf
修改listen_addresses*或者特定IP地址
# listen_addresses = 'localhost'         # what IP address(es) to listen on;
listen_addresses = '*'                  # what IP address(es) to listen on;

2.修改pg_hba.conf文件

sudo vim /etc/postgresql/10/main/pg_hba.conf
添加IPv4连接0.0.0.0/0或者特定IP地址
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0               md5

3.重启pg服务生效

sudo service postgresql restart

odoo服务器设置:

修改odoo.conf.odoorc配置文件

db_host = False      # 这里填写数据库ip地址
db_port = False      # 这是数据库的端口
db_user = odoo       # 这里填写数据库登陆账号
db_password = False  # 这里填写数据库登陆密码

二、Ubuntu 18.04安装Odoo 12/13步骤

  • 更换阿里源(可选)

    • 备份/etc/apt/sources.list
     cp /etc/apt/sources.list /etc/apt/sources.list.bak
    • 替换阿里源(简易方法)
     sudo sed -i "s/archive.ubuntu.com/mirrors.aliyun.com/g;s/security.ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list
    • 替换阿里源方法二
     sudo vim /etc/apt/sources.list
     # 添加在文件最前面
     deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
     deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
     deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
     deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
     deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
     deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
     deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
     deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
     deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
     deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    
  • 更新系统(可选)

sudo apt update && sudo apt upgrade -y
  • 更换Python的pip源(可选)

    • 在主目录下创建.pip文件夹,然后在该目录下创建pip.conf文件
     mkdir ~/.pip
     vim ~/.pip/pip.conf
    • pip.conf文件编写如下内容保存(更换为阿里源):
     [global]
     index-url = https://mirrors.aliyun.com/pypi/simple/
    
     [install]
     trusted-host=mirrors.aliyun.com
  • 添加libpng12-0存储库,wkhtmltopdf将使用此依赖

sudo add-apt-repository universe
sudo add-apt-repository "deb http://mirrors.aliyun.com/ubuntu/ xenial main"
# sudo add-apt-repository "deb http://mirrors.kernel.org/ubuntu/ xenial main"
sudo apt update && sudo apt upgrade -y
  • 安装 Python 3 (odoo13需3.6及以上版本)+ pip3
sudo apt install git python3 python3-pip build-essential wget python3-dev python3-wheel libxslt1-dev libzip-dev libldap2-dev libsasl2-dev python3-setuptools -y
  • 安装PostgreSQL-11/12数据库(可选,直接sudo apt install postgresql安装的是10版本)
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main"
sudo apt update
sudo apt install postgresql-11 -y
# sudo apt install postgresql-12 -y
  • 创建用户(可选,不建议用root用户创建服务)

    • 切换到root用户
     sudo -i
    • 新建用户(此处以odoo用户名为例)
     adduser odoo
    • 设置权限
     visudo

    添加 odoo ALL=(ALL:ALL) ALL
    Ctrl + O保存,Ctrl + X关闭

    • 切换用户
     su odoo
     cd
  • 创建数据库角色(此处以odoo用户名为例)

sudo su - postgres
createuser -d -U postgres -R -S -P odoo
# sudo su - postgres -c "createuser -s odoo"
exit
  • 安装依赖包
sudo pip3 install -r https://github.com/odoo/odoo/raw/13.0/requirements.txt
# sudo pip3 install -r https://github.com/odoo/odoo/raw/12.0/requirements.txt
# 因源码包里面一般都有requirements.txt,因此一般直接pip3 install -r requirements.txt安装即可,无需用网络地址安装。
  • 下载安装wkhtmltopdf(建议提前下载好)
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.trusty_amd64.deb
sudo dpkg -i wkhtmltox_0.12.5-1.trusty_amd64.deb
sudo apt --fix-broken install -y
sudo ln -s /usr/local/bin/wkhtmltopdf /usr/bin
sudo ln -s /usr/local/bin/wkhtmltoimage /usr/bin
  • 安装中文字体
sudo apt install fonts-wqy-zenhei fonts-wqy-microhei -y
  • 克隆代码(可选,也可在Odoo Nightly builds下载源码包或使用已有源码包解压,假设解压路径为/opt)
git clone https://www.github.com/odoo/odoo --depth 1 -b 13.0
# git clone https://gitee.com/mirrors/odoo -b 13.0 --depth=1
# git clone https://www.github.com/odoo/odoo --depth 1 -b 12.0
# pip3 install phonenumbers # 可选
  • 创建odoo配置文件(假设放在/etc)
sudo wget -P /etc https://github.com/odoo/odoo/raw/13.0/debian/odoo.conf
# sudo wget -P /etc https://github.com/odoo/odoo/raw/12.0/debian/odoo.conf
# 或者直接新建配置文件,内容见下一步。sudo vim /etc/odoo.conf
  • 打开配置文件新增或编辑各项参数:
[options]
; This is the password that allows database operations:
; admin_passwd = admin
db_host = False
db_port = False
db_user = odoo
db_password = False
addons_path = /opt/odoo/odoo/addons,/opt/odoo/myaddons

addons_path是必须设置的,设置为odoo源码包addons目录以及附加模块(如企业版模块)和第三方模块及自定义开发模块myaddons,逗号分隔。
常用其他参数有http_port指定端口,db_name或dbfilter指定数据库。Odoo Nightly builds下载的源码包无odoo-bin执行文件,需在setup目录下复制出来odoo文件,并改名为odoo-bin同时增加执行权限。cp setup/odoo odoo-bin && chmod +x odoo-bin

  • 创建systemd启动单元

    • 创建服务文件
     sudo vim /etc/systemd/system/odoo.service
    • 文件内容如下:
     [Unit]
     Description=Odoo
     Requires=postgresql.service
     After=network.target postgresql.service
    
     [Service]
     Type=simple
     SyslogIdentifier=odoo
     PermissionsStartOnly=true
     User=odoo
     Group=odoo
     ExecStart=/usr/bin/python3 /opt/odoo/odoo-bin -c /etc/odoo.conf
     StandardOutput=journal+console
     Restart=always
     RestartSec=5
     StartLimitInterval=0
    
     [Install]
     WantedBy=multi-user.target
    • 重新加载systemd守护程序,然后启动odoo服务
     sudo systemctl daemon-reload
     sudo systemctl start odoo
    • 设置系统启动时启动odoo
     sudo systemctl enable odoo

三、创建Odoo数据库时的“new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)“问题

Odoo创建数据库时,显示如下错误信息:

Database creation error: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT: Use the same encoding as in the template database, or use template0 as template.

解决方法:

  1. First, we need to drop template1. Templates can’t be dropped, so we first modify it so t’s an ordinary database:
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
  1. Now we can drop it:
DROP DATABASE template1;
  1. Now its time to create database from template0, with a new default encoding:
CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';
  1. Now modify template1 so it’s actually a template:
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
  1. Now switch to template1 and VACUUM FREEZE the template:
\c template1
VACUUM FREEZE;
  1. Problem should be resolved.

四、windows安装odoo11/12/13,默认打不开。

Odoo Nightly builds下载的exe安装包,安装后浏览器无法打开127.0.0.1:8069。

解决办法:

找到odoo安装目录下python\Lib\_strptime.py文件,在文件导入模块之后添加一行locale.setlocale(locale.LC_ALL,'en')保存,然后再重启odoo服务或重启电脑。

五、Wkhtmltopdf 失败 (错误代码: -8). 消息: b''

sudo apt install ttf-mscorefonts-installer
sudo fc-cache -f -v

六、登记付款提示“会计凭证不属同一会计科目”

Odoo12科目表中默认的 “222100 Tax payable” 类型是“应付”,我们需要把它修改成“流动负债”。

七、odoo数据库备份和恢复

odoo的数据库包括数据文件和filestore文件存储两部分,因此备份时两部分都需要备份。

备份

cd && pg_dump -Fc -f dbname.dump dbname
#比如demo数据库
#cd && pg_dump -Fc -f demo.dump demo
tar cjf dbname.tgz dbname.dump .local/share/Odoo/filestore/dbname
#tar cjf demo.tgz demo.dump .local/share/Odoo/filestore/demo

恢复

tar xf dbname.tgz
#tar xf demo.tgz
pg_restore -C -d dbname dbname.dump
#pg_restore -C -d demo demo.dump