(+) The coding problem in Odoo

Source: Internet
Author: User

There is no problem with all English, but we often use Chinese, which can lead to a tricky problem.

Conventions:

System Ubuntu trusty14.04 comes with python2.7.6

python2.7.9 upgraded himself.

Upgrade Method:

-------------------------

Get ready

# apt-get-y Install build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev Libgdbm-dev Libc6-dev Libbz2-dev

Installing python2.7.9

# mkdir-p/opt/soft/python

# Cd/opt/soft/python

# wget Https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz

# TAR-XZVF Python-2.7.9.tgz

# CD Python-2.7.9

#./configure

# make

# make Install

Upgrade Python complete

-------------------------

Python default encoding is ASCII

Set it to Utf-8, which is a relatively good coding process.

Create a new sitecustomize.py in the Python lib\site-packages folder, with the following content:

Python code

# Encoding=utf8

Import Sys

Reload (SYS)

Sys.setdefaultencoding (' UTF8 ')

Such as:

Specific lib/site-packages Everyone has all the different, find their own on it can.

To restart the Python service, let's just ctrl+d exit the console and enter Python into

-----------------------------------

Check the effect of the change:

All right, check it out.

---------------------------------------

Below to upgrade a module, the module has the Chinese file name as an example:

The module directory is as follows:

Point "module Upgrade" error.

Find openerp/tools/osutil.py ", line walksymlinks

Not encoded as utf-8, naturally cannot get the Chinese file name correctly, then the variable is Unicode

Add only one line, as follows:

Save can, have this line, later in the module has the file name in the Chinese upgrade will not error

I just got an error. The refresh appears as follows:

Then do not worry, using database Tools to connect to the database to find ir_module_module this table, and then find the module upgrade module rain_china_region

Filter in the data table

Change the upgrade in the red box to installed

Whenever the module upgrade, be sure to remember the directory name of the module, so that if the upgrade is wrong, change the state can be done again.

Otherwise, the system crashes and does not know how to handle it.

Click on the hook to finish

Change the python code above, be sure to remember to restart the Odoo service to take effect

Then go to refresh the browser

Resurrection, click "Module Upgrade", OK can be upgraded normally

For the file of Chinese is generally not garbled, mainly Python set the default encoding for Utf-8

File encoding is utf-8, content encoding is also utf-8 so it's consistent.

(+) The coding problem in Odoo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.