Odoo Development
Odoo Development
Release master
IT-Projects LLC
Contents
First steps
Module Development
2.1 Docs and manifests .
2.2 Guidelines . . . . .
2.3 Odoo Python . . . .
2.4 XML . . . . . . . .
2.5 HTML . . . . . . .
2.6 CSS . . . . . . . . .
2.7 YAML . . . . . . .
2.8 Javascript . . . . . .
2.9 Frontend . . . . . .
2.10 Point of Sale (POS)
2.11 Access . . . . . . .
2.12 Hooks . . . . . . . .
2.13 Tests . . . . . . . .
2.14 Debugging . . . . .
2.15 Source Diving . . .
2.16 Lint . . . . . . . . .
2.17 Other . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5
5
19
19
29
31
32
32
33
34
35
37
44
44
48
55
57
59
Module Migration
3.1 Switching module to new api . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Fixing references on migration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
63
63
64
User documentation
4.1 static/description/index.html .
4.2 Screenshots tools . . . . . . .
4.3 Module description . . . . . .
4.4 Contact us block . . . . . . .
4.5 JS Tour . . . . . . . . . . . .
4.6 Preview module on App Store
4.7 Image sizes . . . . . . . . . .
.
.
.
.
.
.
.
65
65
67
67
68
68
70
72
75
75
76
77
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5.4
5.5
5.6
5.7
5.8
5.9
5.10
5.11
5.12
.
.
.
.
.
.
.
.
.
78
79
79
79
80
82
83
83
83
Continuous Integration
6.1 Runbot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.2 Odoo Travis Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.3 Coverage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
85
85
87
87
Odoo
7.1 Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.2 How to use Odoo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
89
89
98
Odoo administration
8.1 Odoo installation .
8.2 Longpolling . . .
8.3 About longpolling
8.4 --workers . . .
8.5 --addons-path
8.6 --log-handler
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Continuous Delivery
10 IDE
10.1
10.2
10.3
10.4
Emacs . . . . . .
PyCharm . . . . .
Tmux . . . . . . .
Visual Studio Code
103
103
105
106
106
107
107
109
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
111
111
113
115
117
11 Other
121
11.1 RST format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
11.2 Adjust chromium window size script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
ii
Contents
Contents
CHAPTER 1
First steps
Install odoo
take the course Bulding a module
read the article Source diving
Configure git
read Company rules (For IT-Projects LLC employees only)
Get tasks from your Guru!
Fork repo, clone repo to you machine, make commits, push updates, create Pull Request
CHAPTER 2
Module Development
Guidlines
OCAs README
Demo
addons-dev
HTML Description
Usage instructions
Changelog
Tested on
Guidlines
=============
Module Name
=============
Put some short introduction first.
Then add more detailed description, technical specifications, any other information that could be int
Credits
=======
Contributors
-----------* DEVELOPER_NAME <[email protected]>
0
The only exception could be made for data field in __openerp__.py file.
Sponsors
-------* `IT-Projects LLC <https://it-projects.info>`_
Maintainers
----------* `IT-Projects LLC <https://it-projects.info>`_
Further information
===================
Demo: http://runbot.it-projects.info/demo/REPO-NAME/BRANCH
HTML Description: https://apps.odoo.com/apps/modules/VERSION/TECHNICAL_NAME/
Usage instructions: `<doc/index.rst>`_
Changelog: `<doc/changelog.rst>`_
Tested on Odoo 10.0 ODOO_COMMIT_SHA_TO_BE_UPDATED
OCAs README
https://raw.githubusercontent.com/OCA/maintainer-tools/master/template/module/README.rst
Demo
Link to the runbot. Supported repo names are below. Change branche name if needed.
Demo:
Demo:
Demo:
Demo:
Demo:
Demo:
Demo:
Demo:
Demo:
Demo:
http://runbot.it-projects.info/demo/access-addons/10.0
http://runbot.it-projects.info/demo/addons-dev/misc-addons-10.0-some_feature
http://runbot.it-projects.info/demo/l10n-addons/10.0
http://runbot.it-projects.info/demo/mail-addons/10.0
http://runbot.it-projects.info/demo/misc-addons/10.0
http://runbot.it-projects.info/demo/odoo-saas-tools/10.0
http://runbot.it-projects.info/demo/odoo-telegram/10.0
http://runbot.it-projects.info/demo/pos-addons/10.0
http://runbot.it-projects.info/demo/rental-addons/10.0
http://runbot.it-projects.info/demo/website-addons/10.0
addons-dev In most cases, if you work in addons-dev, you shall not use demo link to addons-dev (e.g.
http://runbot.it-projects.info/demo/addons-dev/misc-addons-10.0-some_feature).
Use a link for target repo instead (e.g. http://runbot.it-projects.info/demo/misc-addons/10.0).
You can use links to addons-dev only if you know who will use it.
HTML Description
You have to prepare this link even if the module is not published yet, i.e. link returns 404 error.
Usage instructions
doc/index.rst
Changelog
doc/changelog.rst
Tested on
Tested on Odoo 10.0 03bc8c5f9ac53a3349c1caac222f7619a632ccd8
doc/index.rst
=============
Module name
=============
Installation
============
Instruction for daily usage. It should describe how to check that module works. What shall user do an
* Open menu ...
* Click ...
Uninstallation
==============
Optional section for uninstallation notes. Delete it if you don't have notes for uninstallation.
under
Documentation
tab.
Example:
__openerp__.py / __manifest__.py
Filename
Template
name
summary
category
Hidden
version
version in OCA
author
author in OCA
website
license
external_dependencies
Filename
# "currency": "EUR",
"depends": [
"DEPENDENCY1",
"DEPENDENCY2",
],
"external_dependencies": {"python": [], "bin": []},
"data": [
"FILE1.xml",
"FILE2.xml",
],
"qweb": [
"static/src/xml/QWEBFILE1.xml",
],
"demo": [
"demo/DEMOFILE1.xml",
],
"post_load": None,
"pre_init_hook": None,
"post_init_hook": None,
"auto_install": False,
"installable": True,
}
See also:
OCAs template: https://github.com/OCA/maintainer-tools/blob/master/template/module/__openerp__.py
name
Short description of the module. E.g. you can describe here which problem is solved by the module. It could sound as
a slogan.
category
Discuss
Document Management
eCommerce
Human Resources
Industries
Localization
Manufacturing
Marketing
Point of Sale
Productivity
Project
Purchases
Sales
Warehouse
Website
Extra Tools
Hidden For technical modules Hidden category can be used:
"category": "Hidden",
Note: whenever you change version, you have to add a record in changelog.rst
The x.y.z version numbers follow the semantics breaking.feature.fix:
x increments when the data model or the views had significant changes. Data migration might be needed, or
depending modules might be affected.
y increments when non-breaking new features are added. A module upgrade will probably be needed.
z increments when bugfixes were made. Usually a server restart is needed for the fixes to be made available.
On each version change a record in doc/changelog.rst should be added.
If a module ported to different odoo versions (e.g. 8 and 9) and some update is added only to one version (e.g. 9), then
version is changed as in example below:
init
[8.0] 1.0.0
[9.0] 1.0.0
feature added to 8.0 and ported to 9.0
[8.0] 1.1.0
10
[9.0] 1.1.0
feature added to 9.0 only and not going to be ported to 8.0:
[8.0] 1.1.0
[9.0] 1.2.0
fix made in 9.0 only and not going to be ported to 8.0:
[8.0] 1.1.0
[9.0] 1.2.1
fix made in 8.0 and ported to 9.0
[8.0] 1.2.2
[9.0] 1.2.2
i.e. two module branches cannot have same versions with a different meaning
version in OCA While OCA use odoo version in module version (e.g. 8.0.1.0.0), we specify odoo version in
README.rst file and use three numbers in version (e.g. 1.0.0).
author
In the main, if module already exists and you make small updatesfixes, you should not add your name to authors.
author in OCA For OCAs repositories put company name first, then OCA. Developers are listed in README file:
"author": "IT-Projects LLC, Odoo Community Association (OCA)",
website
11
external_dependencies
doc/changelog.rst
Template
Guidlines
`2.0.0`
------- **ADD:** absolutely new way of ..
`1.2.0`
------- **ADD:** new interface for ..
`1.0.1`
------- **FIX:** issue about ...
- **FIX:** another issue about ...
`1.0.0`
------- Init version
icon.png
File icon.png must be located at /static/description/icon.png
IT-Projects LLC
SaaS
Telegram
Access
Barcode
Mail
Pos
Stock
Website
Website_Sale
Misc
SaaS
Download
Telegram
Download
Access
Download
2.1. Docs and manifests
13
Barcode
Download
Mail
Download
Pos
Download
Stock
Download
14
Website
Download
Website_Sale
Download
Misc
Download
2.1.2 Notes
RST Requirements
Dont forget to keep correct rst format.
Extra lines
References to menu
Fields
Buttons
Selections
Titles and sections
Extra lines
15
Raw RST
This and next sentences are joined together.
To split sentences to paragraphs you must add add empty line.
Splited sentence 1.
Splited sentence 2.
Lists below doesn't rendered correctly, because extra line is required:
* 1
* 2
* 3
The same for sublist:
* 1
* 1.1
* 1.2
* 1.3
* 2
Correctly formated lists:
* 1
* 2
* 3
* 3.1
* 3.2
* 3.3
* 4
Rendered RST This and next sentences are joined together. To split sentences to paragraphs you must add add
empty line.
Splited sentence 1.
Splited sentence 2.
Lists below doesnt rendered correctly, because extra line is required: * 1 * 2 * 3
The same for sublist:
1 * 1.1 * 1.2 * 1.3
2
Correctly formated lists:
1
2
3
3.1
3.2
3.3
16
4
References to menu
menu
menu
menu
menu
``Settings>>Parameters>>System Parameters``
"Settings >> Parameters >> System Parameters"
''Settings >> Parameters >> System Parameters''
``Settings > Parameters > System Parameters``
Fields
Buttons
Use square brackets in double back-quotes to name buttons. Keep letter cases the same as in UI.
OK:
* click ``[Save]``
Bad:
* click ``[save]``
Selections
Use arrow symbol -> to specify value in selection and many2one fields:
* Choose ``Partner -> Administrator``
17
=============================
No space at the end of title
=============================
=======================================
Incorrect number of signs in title
========================================
================
Incorrect number of signs in title
================
Incorrect number of signs in section
=====================================
Incorrect number of signs in section
===================================
Usage instruction. Used by end users after purchasing the module. It shall give an answer to the question How to
check that module works (how to install, how to configure, how to use)?. Also, it may cover the question How to
safely uninstall the module.
index.html
Module representation. It shall give an answer to the questions Do I need this module? Should I buy it?.
Content intersection
While every file has its own purpose, the content may intersect. If you dont want duplicate content, use the following
priority:
index.html
index.rst
README.rst
18
2.2 Guidelines
Source:
https://www.odoo.com/documentation/8.0/reference/guidelines.html
2.2.1 Comments
First of all, comments in the source are required if its not obvious why are doing something.
Additionally, you can add comments about what are you doing, if it could be helpful.
2.2. Guidelines
19
@api.one
api.one is meant to be used when method is called only on one record. It makes sure, that there are no multiple records
when calling method with api.one decorator. Let say you got record partner = res.partner(1,). It is only one record and
there is method for example (in res.partner):
@api.one
def get_name(self):
return self.name #self here means one record
calling it, would raise Warning, telling you that you can only call it on one record.
@api.multi
something. For example:
@api.multi
def get_partner_names(self):
names = []
for rec in self:
names.append(rec.name)
return ', '.join(names)
And api.model is considered to be used when you need to do something with model itself and dont need to modify/check some exact models record/records. For example there could be method that returns some meta info about
models structure or some helper methods, etc. Also in documentation it is said that this api is good to use when migrating from old api, because it politely converts code to new api. Also in my own experience, if you need method
to return something, model decorator is good for it. api.one returns empty list, so it might lead to unexpected behavior
when using api.one on method when it is supposed to return something.
2.3.3 res.config.settings
Based on https://github.com/odoo/odoo/blob/9.0/openerp/addons/base/res/res_config.py
res.config.settings is a base configuration wizard for application settings. It provides support for setting
default values, assigning groups to employee users, and installing modules. To make such a settings wizard, define a
model like:
class my_config_wizard(osv.osv_memory):
_name = 'my.settings'
_inherit = 'res.config.settings'
20
_columns = {
'default_foo': fields.type(..., default_model='my.model'),
'group_bar': fields.boolean(..., group='base.group_user', implied_group='my.group'),
'module_baz': fields.boolean(...),
'other_field': fields.type(...),
}
The method execute (Apply button) provides some support based on a naming convention:
For a field like default_XXX, execute sets the (global) default value of the field XXX in the model named
by default_model to the fields value.
For a boolean field like group_XXX, execute adds/removes implied_group to/from the implied groups of
group, depending on the fields value. By default group is the group Employee. Groups are given by their
xml id. The attribute group may contain several xml ids, separated by commas.
For a boolean field like module_XXX, execute triggers the immediate installation of the module named XXX
if the field has value True.
For the other fields, the method execute invokes all methods with a name that starts with set_; such methods
can be defined to implement the effect of those fields.
The method default_get retrieves values that reflect the current status of the fields like default_XXX,
group_XXX and module_XXX. It also invokes all methods with a name that starts with get_default_; such
methods can be defined to provide current values for other fields.
Example
This for website.config.settings but it is similar to res.config.settings:
class website_config_settings(models.TransientModel):
_inherit = 'website.config.settings'
nobill_noship = fields_new_api.Boolean("Pickup and pay at store")
#When you press Apply
def set_nobill_noship(self, cr, uid, ids, context=None):
config_parameters = self.pool.get("ir.config_parameter")
for record in self.browse(cr, uid, ids, context=context):
config_parameters.set_param(cr, uid, "website_sale_checkout_store.nobill_noship", record.
#When page loads
def get_default_nobill_noship(self, cr, uid, fields, context=None):
nobill_noship = self.pool.get("ir.config_parameter").get_param(cr, uid, "website_sale_checkou
return {'nobill_noship': nobill_noship}
#website_sale_checkout_store - is your module
21
module_XXX
Add XXX to the depends parameter in the __openerp__.py file
22
2.3.7 Fields
Based on: http://odoo-new-api-guide-line.readthedocs.io/en/latest/fields.html
Now fields are class property:
from openerp import models, fields
class AModel(models.Model):
_name = 'a_name'
name = fields.Char(
string="Name",
compute="_compute_name_custom",
store=True,
select=True,
readonly=True,
inverse="_write_name"
required=True,
translate=True,
help='blabla',
company_dependent=True,
search='_search_function'
)
#
#
#
#
#
#
#
#
#
#
#
Valid definition
Field inheritance
One of the new features of the API is to be able to change only one attribute of the field:
name = fields.Char(string='New Value')
Field types
Boolean
Char
Specific options:
size: data will be trimmed to specified size
23
Specific options:
translate: field can be translated
HTML
Specific options:
translate: field can be translated
Integer
Store integer value. No NULL value support. If value is not set it returns 0:
anint = fields.Integer()
Float
Store float value. No NULL value support. If value is not set it returns 0.0 If digits option is set it will use numeric
type:
afloat = fields.Float()
afloat = fields.Float(digits=(32, 32))
afloat = fields.Float(digits=lambda cr: (32, 32))
Specific options:
digits: force use of numeric type on database. Parameter can be a tuple (int len, float len) or a callable that return
a tuple and take a cursor as parameter
Date
24
DateTime
Binary
Selection
Store text in database but propose a selection widget. It induces no selection constraint in database. Selection must be
set as a list of tuples or a callable that returns a list of tuples:
aselection = fields.Selection([('a', 'A')])
aselection = fields.Selection(selection=[('a', 'A')])
aselection = fields.Selection(selection='a_function_name')
Specific options:
selection: a list of tuple or a callable name that take recordset as input
size: the option size=1 is mandatory when using indexes that are integers, not strings
2.3. Odoo Python
25
When extending a model, if you want to add possible values to a selection field, you may use the selection_add
keyword argument:
class SomeModel(models.Model):
_inherits = 'some.model'
type = fields.Selection(selection_add=[('b', 'B'), ('c', 'C')])
Reference
Specific options:
selection: a list of tuple or a callable name that take recordset as input
Many2one
Specific options:
comodel_name: name of the opposite model
delegate: set it to True to make fields of the target model accessible from the current model (corresponds to
_inherits)
One2many
Specific options:
comodel_name: name of the opposite model
inverse_name: relational column of the opposite model
Many2many
26
Specific options:
comodel_name: name of the opposite model
relation: relational table name
columns1: relational table left column name
columns2: relational table right column name
Name Conflicts
Using a fun will force you to define function before fields definition.
Computed Fields
There is no more direct creation of fields.function.
Instead you add a compute kwarg. The value is the name of the function as a string or a function. This allows to
have fields definition atop of class:
class AModel(models.Model):
_name = 'a_name'
computed_total = fields.Float(compute='compute_total')
def compute_total(self):
...
self.computed_total = x
The function can be void. It should modify record property in order to be written to the cache:
self.name = new_value
Be aware that this assignation will trigger a write into the database. If you need to do bulk change or must be careful
about performance, you should do classic call to write
27
To provide a search function on a non stored computed field you have to add a search kwarg on the field. The value
is the name of the function as a string or a reference to a previously defined method. The function takes the second
and third member of a domain tuple and returns a domain itself
def search_total(self, operator, operand):
...
return domain # e.g. [('id', 'in', ids)]
Inverse
The inverse key allows to trigger call of the decorated function when the field is written/created
Multi Fields
To have one function that compute multiple values:
@api.multi
@api.depends('field.relation', 'an_otherfield.relation')
def _amount(self):
for x in self:
x.total = an_algo
x.untaxed = an_algo
Related Field
There is not anymore fields.related fields.
Instead you just set the name argument related to your model:
participant_nick = fields.Char(string='Nick name',
related='partner_id.name')
Note: When updating any related field not all translations of related field are translated if field is stored!!
Chained related fields modification will trigger invalidation of the cache for all elements of the chain.
Property Field
There is some use cases where value of the field must change depending of the current company.
To activate such behavior you can now use the company_dependent option.
A notable evolution in new API is that property fields are now searchable.
28
SQL constraints are defined through the model attribute ~openerp.models.Model._sql_constraints. The latter is assigned to a list of triples of strings (name, sql_definition, message), where name is a valid SQL constraint name, sql_definition is a table_constraint_ expression, and message is the error message.
2.4 XML
2.4.1 Create record of model
Create new record:
<openerp>
<data>
<record id="demo_multi_session" model="pos.multi_session">
<field name="name">multi session demo</field>
</record>
</data>
openerp>
If model exist it will be modifyed. Record creating in module it declareted. To change model created in another
module add mule name before id:
<openerp>
<data>
<record id="point_of_sale.pos_config_main" model="pos.config">
<field name="multi_session_id" ref="demo_multi_session"/>
</record>
</data>
openerp>
2.4. XML
29
2.4.2 Xpath
Add some attributes to node
Code:
<xpath expr="//some/xpath" position="attributes">
<attribute name="some_field">
</xpath>
Qweb expression:
<attribute name="t-att-another_field">website.get_another_field_value()</attribute>
Important
Inside of
<xpath expr="//some/xpath" position="attributes">
...
</xpath>
30
2.4.4 Inherit
Collisions and priority
If two or more xml templates inherit same parent template they can have same priorities. It may produce conflicts and
unexpected behavior. What you need is just set priority explicitly in your template:
<template id="..." inherit_id="..." priority="8" ..>
<xpath expr="..." position="...">
...
</xpath>
</template>
<!-- or -->
<record id="..." model="ir.ui.view">
...
<field name="inherit_id" ref="..."/>
<field name="priority" eval="8" />
<field name="arch" type="xml">
<xpath expr="..." position="...">
</xpath>
</field>
</record>
2.5 HTML
2.5.1 Active elements
Link-button that calls controller
Code:
2.5. HTML
31
Here action=/shop/checkout sets controller address. Class a-submit usually means do what in action of form.
Submit with button
Code:
<form action="/my_page" name="myform" method="post">
<button type="submit" class="btn btn-default">My button</button>
</form>
Wherein in controller in **post will be available some values from source form, those like <input/>.
2.6 CSS
2.6.1 CSS tips and tricks
Add your css on template
Code:
<template id="my_module_frontend" name="my_module assets" inherit_id="website_sale.assets_frontend">
<xpath expr="//link[@rel='stylesheet']" position="after">
<link rel="stylesheet" href="/my_module/static/src/css/main.css"/>
</xpath>
</template>
2.7 YAML
2.7.1 Pure YAML
TODO
32
2.8 Javascript
2.8.1 Inheritance
TODO
2.8.2 core.bus
core.bus (web.bus in 8.0) is used handle js events between modules.
Usage
// 8.0
var bus = openerp.web.bus;
// 9.0+
var core = require('web.core');
var bus = core.bus;
// bind event handler
bus.on('barcode_scanned', this, function (barcode) {
//...
})
// trigger event
bus.trigger('barcode_scanned', barcode);
2.8. Javascript
33
kwargs: kwargs
}, options);
},
2.9 Frontend
2.9.1 Web page
Common
Open a new project:
./odoo.py scaffold newpage addons
then add the website=True flag on the controller, this sets up a few new variables on the request object and allows
using the website layout in our template.
Creating pages
1 way
Write the following code in controllers.py:
from openerp import http
classNewPage(http.Controller):
@http.route('/new-page/',auth='public', website=True)
def index(self,**kw):
return http.request.render('newpage.index')
34
</t>
</template>
</data>
</openerp>
35
partner_model.fields.push('qty_available');
// Inheritance
return _super_posmodel.initialize.call(this, session, attributes);
},
});
This defenition doesnt return class ReprintButton. So, we cannot inherit it in a usual way.
In order to reach that object we need get instance of it using gui. Then we can inherit it
To make clear what this is like look up example where guests number button renderings:
this.gui.screen_instances['products'].action_buttons['guests'].renderElement();
While you can make call and even replace function with new one, you are not able to make inheritance via extend
or include functions. Its because we cannot reach Class and only get access to instance of that class.
This kind of approach make sense only for those widgets:
DiscountButton
ReprintButton
TableGuestsButton
SubmitOrderButton
OrderlineNoteButton
PrintBillButton
SplitbillButton
set_fiscal_position_button
screen_classes
To create new screen widget (via the extend() method) or to modify existing screen widget (via the include() method)
you need the target class. Usually you can get this class using following code:
odoo.define('module_name.file_name', function (require) {
"use strict";
var screens = require('point_of_sale.screens');
screens.OrderWidget.include({
...
36
But it is available only for widgets that are returned by main function in the file point_of_sale/static/src/js/screens.js.
List of the screens:
ReceiptScreenWidget
ActionButtonWidget
define_action_button
ScreenWidget
PaymentScreenWidget
OrderWidget
NumpadWidget
ProductScreenWidget
ProductListWidget
In other cases you can get targeted screen widget class using following code:
odoo.define('module_name.file_name', function (require) {
"use strict";
var gui = require('point_of_sale.gui');
2.11 Access
2.11.1 Security tutorial
Resources:
http://odoo-docs.readthedocs.org/en/latest/04_security.html
https://www.odoo.com/documentation/9.0/howtos/backend.html#security
https://www.odoo.com/documentation/9.0/reference/security.html
Odoo is very flexible on the subject of security. We can control what users can do and what they cannot on different
levels. Also we can control independently each of the four basic operations: read, write, create, unlink. I.e. allow only
read, allow only create, grant permission to create or delete only.
On fields/menu level we can:
hide fields or menus for some users and show them for others
2.11. Access
37
make fields readonly for some users and make them editable for others
show different variants to pick on the Selection fields for different users
On the fields level of security res.users and res.groups models are used. These models relate to each other as
many2many. This means that a user can be a member of many groups and one group can be assigned to many users.
One example of how we can hide menu in regard to current users groups is the following.
On the picture above in Settings / Users we can see only Users menu. We know that there should be Groups
menu also. Let Us see in ./openerp/addons/base/res/res_users_view.xml on the point of how menuitem can be hidden.
38
The groups attribute in the menuitem element shows us that only the members of base.group_no_one
group can see the Groups menu item.
The base.group_no_one xmlid is defined in the
./openerp/addons/base/security/base_security.xml as follows.
<record model="res.groups" id="group_erp_manager">
<field name="name">Access Rights</field>
</record>
<record model="res.groups" id="group_system">
<field name="name">Settings</field>
<field name="implied_ids" eval="[(4, ref('group_erp_manager'))]"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
<record model="res.groups" id="group_user">
<field name="name">Employee</field>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
<record model="res.groups" id="group_multi_company">
<field name="name">Multi Companies</field>
</record>
<record model="res.groups" id="group_multi_currency">
<field name="name">Multi Currencies</field>
</record>
<record model="res.groups" id="group_no_one">
<field name="name">Technical Features</field>
</record>
<record id="group_sale_salesman" model="res.groups">
<field name="name">User</field>
</record>
<record id="group_sale_manager" model="res.groups">
<field name="name">Manager</field>
<field name="implied_ids" eval="[(4, ref('group_sale_salesman'))]"/>
</record>
Here we can see the group_no_one along with the other base groups. Note that group_no_one has Technical
Features name. Let us include our user in the Technical Features group. Since we have no access to the
Groups menu item, the only way we can do it is from the Users menu item. See the picture below.
2.11. Access
39
Check the Technical Features box and reload odoo. Now we can see the Groups menu item!
40
From Settings / Users / Groups we can see a list of existing groups. Here we also can assign users for
groups.
Hide fields
In
the
./openerp/addons/base/res/res_users_view.xml
we
can
see
the
view_users_simple_form view. Note here that the company_id field is visible only for members of
the base.group_multi_company group.
<!-- res.users -->
<record id="view_users_simple_form" model="ir.ui.view">
<field name="name">res.users.simplified.form</field>
<field name="model">res.users</field>
<field name="priority">1</field>
2.11. Access
41
Our current user is Administrator. By default he is not a member of the base.group_multicompany group. That
is why the company_id isnt visible for him on the form.
42
Model records:
restrict access to specified subset of records in model
Model:
restrict access to all records of model
2.11. Access
43
ir.rule
2.12 Hooks
2.13 Tests
2.13.1 Basic python tests
This tests runs with -d [my_db] -u [module_to_be_tested] --test-enable --workers=0 parameters.
To make some tests do next steps:
Create folder named tests
Add __init__.py file
Create file that name begins from test_
Add test methods that names start from test_
Example (will result testing error):
from openerp.tests.common import TransactionCase
class TestMessage(TransactionCase):
at_install = False
post_install = True
def test_count(self):
self.assertEqual(1, 0)
Test class
From openerp/tests/common.py:
class BaseCase(unittest.TestCase):
"""
Subclass of TestCase for common OpenERP-specific code.
This class is abstract and expects self.registry, self.cr and self.uid to be
initialized by subclasses.
"""
class TransactionCase(BaseCase):
""" TestCase in which each test method is run in its own transaction,
and with its own cursor. The transaction is rolled back and the cursor
is closed after each test.
"""
class SingleTransactionCase(BaseCase):
""" TestCase in which all test methods are run in the same transaction,
the transaction is started with the first test method and rolled back at
the end of the last.
"""
class SavepointCase(SingleTransactionCase):
""" Similar to :class:`SingleTransactionCase` in that all test methods
44
are run in a single transaction *but* each test case is run inside a
rollbacked savepoint (sub-transaction).
Useful for test cases containing fast tests but with significant database
setup common to all cases (complex in-db test data): :meth:`~.setUpClass`
can be used to generate db test data once, then all test cases use the
same data without influencing one another but without having to recreate
the test data either.
"""
class HttpCase(TransactionCase):
""" Transactional HTTP TestCase with url_open and phantomjs helpers.
"""
at_install, post_install
By default, odoo runs test with paramaters:
at_install = False
post_install = True
at_install - run tests right after loading modules files. It runs only in demo mode.
post_install - run test after full installation process. It differs from at_install, because
it runs after calling registry.setup_models(cr)
it runs after calling model._register_hook(cr)
Assert Methods
https://docs.python.org/2.7/library/unittest.html#assert-methods
2.13.2 JS Testing
Regular phantom JS tests
For automatic web tests odoo uses phantom_js. You can test you module web mechanics behavior using phantom js.
What you need is:
Install phantom. sudo apt-get install phantomjs
Create folder named tests
Add __init__.py file
Create file that name begins from test_
Add test methods than names start from test_
Example:
import openerp.tests
@openerp.tests.common.at_install(False)
@openerp.tests.common.post_install(True)
class TestUi(openerp.tests.HttpCase):
2.13. Tests
45
def test_01_mail_sent(self):
# wait till page loaded and then click and wait again
code = """
setTimeout(function () {
$(".mail_sent").click();
if (location.href.indexOf('channel_sent')!=-1) {
throw new Error('Already on channel_sent.');
}
setTimeout(function () {
if (location.href.indexOf('channel_sent')==-1) {
throw new Error('End page is not channel_sent.');
}
console.log('ok');
}, 3000);
}, 1000);
"""
link = '/web#action=%s' % self.ref('mail.mail_channel_action_client_chat')
self.phantom_js(link, code, "odoo.__DEBUG__.services['mail_sent.sent']", login="demo")
In 9.0 it may be
User name
Use throw new Error(Error text); for errors handling.
JS phantom tests using Tours
It is possible to run js phantom tests using Tour as JS testing code. To run test automatically after installing module
you will need:
Install phantomjs if dont have yet
Inject JS Tour file on web page
Create test as described higher
Call tour
Call tour example:
class TestUi(openerp.tests.HttpCase):
def test_01_res_partner_mails_to_count(self):
self.phantom_js('/', "openerp.Tour.run('mails_count_tour', 'test')", "openerp.Tour.tours.mai
Also odoo must be started with -d , test-enable and without db-filter , workers. If assumes ti run test only on install
or update use -i or -u. Werkzeug must be 0.11.5 or higher.
Look up js tour page for details.
46
2.13. Tests
47
User
While you develop a module, you can use an admin user for manual checking the result. It could simplify the process of
development, because you can skip security stuff for a while. But when you prepare module for relase you absolutely
need to check how system works from non-admin user.
Warning: Admin user has special access rights. Use another User to test module.
2.14 Debugging
2.14.1 Logs
There are several places where you can get logs.
Its better to activate developer (debug) mode in browser when you are looging for logs.
Error Message
Terminal
Console
boot.js
Sources
Network
How to see html request initiator
Error Message
Its a first place where you can see error message. But in most time, it doesnt contain enough information to resolve
problem. Check other possbile ways to get log messages below.
Terminal
Its a place where you run odoo.
Any errors related to python can be found here
Console
Its a short term for browsers console. Click F12 in browser to open console.
It can contain error and warning about client part.
boot.js
48
Sources
Allows you to check which client side files are loaded and which are not. To do this:
1. Turn on debug mode in the url.
2. Open Developer tools (F12), go to the Sources tab and reload page.
3. Open left panel (if it is not open yet) and search interested app.
Example: Missing dependencies error in console
Network
Sometime error are not printed neither in Terminal, nor in Console. Then you can try to find some logs at Network tab
of browsers developer tool. To see original odoo js files i.e. not minimized versions, swich odoo in debug mode first.
How to see html request initiator
Suppose we want to know which part of our script initiate the request. If it is javascript we could see full program
stack by putting mouse pointer on the initiator columns element.
2.14. Debugging
49
50
2.14. Debugging
[...]
[...]
51
You can find out reason in the Developer Tool in the tab Sources as described above.
Likely you can not find files included in the Missing dependencies list. Then you need to check they are included in
the view (.xml) files.
AccessError: Please contact your system administrator
There is an AccessError which doesnt specify groups that have access to an operation. It simply states:
The requested operation cannot be completed due to security restrictions. Please contact your system
administrator.
52
Such error means, that your user doesnt satisfy access requirements specified in ir.rule. See Access section for general
understanding how odoo security works.
2.14.3 QWeb
The javascript QWeb implementation provides a few debugging hooks:
t-log takes an expression parameter, evaluates the expression during rendering and logs its result with
console.log:
<t t-set="foo" t-value="42"/>
<t t-log="foo"/>
will stop execution if debugging is active (exact condition depend on the browser and its development tools)
t-js the nodes body is javascript code executed during template rendering. Takes a context parameter, which is
the name under which the rendering context will be available in the t-jss body:
<t t-set="foo" t-value="42"/>
<t t-js="ctx">
console.log("Foo is", ctx.foo);
</t>
Source
2.14. Debugging
53
# lose 30 %
sudo tc qdisc add dev eth0 root netem loss 30%
# "burst of losing"
# Probabilyt of each next lossing depends on previous result.
# For example below:
# Pnext = 0.1 * Pprev + (1-0.1)* Random(0,1)
# Then the package is lost, if Pnext < 0.3
sudo tc qdisc add dev eth0 root netem loss 30% 10%
# show current settings
tc -s qdisc show dev eth0
# reset settings
sudo tc qdisc del dev eth0 root
54
or so:
sleep 3 && echo '3333333333338'| grep -o . | xargs xdotool key && xargs xdotool key \n &
On printing:
some binary data is sent to /tmp/printer
odoo prints logs with unparsed data
POS
At any database, including one on runbot:
set Receipt printer checkbox in pos.config and set ip equal to 127.0.0.1
open POS interface
print ticket
55
When porting module mail_move_message in the file static/src/js/mail_move_message.js there is a method session.web.form.FormOpenPopup(this).
Problem
In 9.0 not found such object. What object would be the analogue of the object? What you need to do to find this
object?
Solution
Possible solution
Guidelines
Use template below for new cases
===========
CASE NAME
===========
Context
=======
What we have. E.g. some module, or out-of-box odoo version 8.0
* LINK1
* LINK2
Problem
=======
What we need to do. E.g. port module to 9.0
* LINK1
* LINK2
Solution
========
:doc:`Possible solution <./answers/CASE_NAME>`
56
2.16 Lint
2.16.1 Script for fixing travis error on odoo
Installation
# install autopep8
sudo pip install --upgrade autopep8
# install oca-autopep8
git clone https://github.com/OCA/maintainer-tools.git
cd maintainer-tools
sudo python setup.py install
# install autoflake
sudo pip install --upgrade autoflake
# install fixmyjs
sudo npm install fixmyjs -g
Script
# fix line break symbols
cd /path/to/MODULE_NAME
find * -type f | grep -v ".\(svg\|png\|jpg\)$" | xargs sed -i 's/\r//g'
# add line break to the end of file
find * -type f | grep -v ".\(png\|jpg\)$" | xargs sed -i '$a\'
# trim trailing whitespaces
find * -type f | grep -v ".\(svg\|png\|jpg\)$" | xargs sed -i 's/[ \t]*$//g'
# PEP8
py-:
2.16. Lint
57
/g'
/g'
/g'
# Replacement (relative-import)
find . -type f -name '__init__.py' | xargs sed -i 's/^import/from . import/g'
#find . -type f -name '__init__.py' | xargs sed -i 's/^import controllers/from . import controllers/g
#find . -type f -name '__init__.py' | xargs sed -i 's/^import models/from . import models/g'
58
2.17 Other
2.17.1 Dynamic records
While XML allows you create only static records, there is a way to create record dynamically via python code. You
need dynamic records, for example, to add support both for enterprise and community releases or to add some records
to each company in database etc.
There several ways to execute code on installation:
TODO
TODO
TODO
The problem with dynamic records is that odoo considers such records as ones, which were in xml files, but now
deleted. It means that odoo will delete such dynamic records right after updating. There are two ways to resolve it.
noupdate=False
Simply add update=True to your ir.model.data record:
noupdate=True
If for some reason you cannot use noupdate=False, you can use following trick.
Here is the example from web_debranding module. To create records in ir.model.data we use name
_web_debranding. Then odoo will consider such records as belonging to another module (_web_debranding)
and will not delete them. But it also means, that odoo will not delete them after uninstalling. For later case, we need
to use uninstall_hook.
2.17. Other
59
Contents
Dynamic records
noupdate=False
noupdate=True
* python file
* yaml file
* __openerp__.py
* __init__.py
python file
from openerp import SUPERUSER_ID, models, tools, api
MODULE = '_web_debranding'
class view(models.Model):
_inherit = 'ir.ui.view'
def _create_debranding_views(self, cr, uid):
self._create_view(cr, uid, 'menu_secondary', 'web.menu_secondary', '''
<xpath expr="//div[@class='oe_footer']" position="replace">
<div class="oe_footer"></div>
</xpath>''')
60
yaml file
!python {model: ir.ui.view}: |
self._create_debranding_views(cr, uid)
__openerp__.py
'uninstall_hook': 'uninstall_hook',
'data': [
'path/to/file.yml'
]
__init__.py
from openerp import SUPERUSER_ID
MODULE = '_web_debranding'
def uninstall_hook(cr, registry):
registry['ir.model.data']._module_data_uninstall(cr, SUPERUSER_ID, [MODULE])
2.17. Other
61
62
CHAPTER 3
Module Migration
orm
-name
-name
-name
-name
-name
-name
-name
-name
-name
-name
'*.py'
'*.py'
'*.py'
'*.py'
'*.py'
'*.py'
'*.py'
'*.py'
'*.py'
'*.py'
|
|
|
|
|
|
|
|
|
|
xargs
xargs
xargs
xargs
xargs
xargs
xargs
xargs
xargs
xargs
sed
sed
sed
sed
sed
sed
sed
sed
sed
sed
-i
-i
-i
-i
-i
-i
-i
-i
-i
-i
import
-name '*.py' | xargs sed -i 's/from openerp.addons.web import http/from odoo import ht
-name '*.py' | xargs sed -i 's/openerp.addons.web.http/odoo.http/g'
-name '*.py' | xargs sed -i 's/openerp.http/odoo.http/g'
# replace odoo
# fix importing. Otherwise you will get error:
#
AttributeError: 'module' object has no attribute 'session_dir'
find . -type f -name '*.py' | xargs sed -i 's/openerp.tools.config/odoo.tools.config/g'
# FIELDS
# update fields
# (multiline: http://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sed/7697
# delete _columns
find . -type f -name '*.py' | xargs perl -i -p0e 's/
_columns = {(.*?)\n
}/$1\n/gs'
# computed fields
find . -type f -name '*.py' | xargs sed -i 's/fields.function(\(.*\) \(["\x27][^,]*\)/fields.function
find . -type f -name '*.py' | xargs sed -i 's/fields.function(\(.*\) multi=[^,)]*/fields.function(\1/
63
find
find
find
find
find
.
.
.
.
.
-type
-type
-type
-type
-type
f
f
f
f
f
-name
-name
-name
-name
-name
'*.py'
'*.py'
'*.py'
'*.py'
'*.py'
|
|
|
|
|
xargs
xargs
xargs
xargs
xargs
sed
sed
sed
sed
sed
-i
-i
-i
-i
-i
's/fields.function(\([^,]*\)\(.*\)type=.\([2a-z]*\)["\x27]
's/fields.many2one(\(.*\)obj=\([^,]*\)/fields.many2one(\2,
's/,[ ]*,/,/g'
's/,[ ]*,/,/g'
's/,[ ]*,/,/g'
# replace fields
find . -type f -name '*.py' | xargs perl -i -p0e 's/
_columns = {(.*?)
}/$1/gs'
find . -type f -name '*.py' | xargs sed -i 's/fields\.\(.\)/fields.\u\1/g'
find . -type f -name '*.py' | xargs sed -i 's/
[\x27"]\(.*\)[\x27"].*:.*\(fields.*\),$/\1 = \2/g'
# renamed attributes
find . -type f -name '*.py' | xargs sed -i 's/select=/index=/g'
find . -type f -name '*.py' | xargs sed -i 's/digits_compute=/digits=/g'
|
|
|
|
|
xargs
xargs
xargs
xargs
xargs
sed
sed
sed
sed
sed
-i
-i
-i
-i
-i
# menu_hr_configuration
find . -type f -name '*.xml' | xargs sed -i 's/menu_hr_configuration/menu_human_resources_configurati
# base.group_hr
find . -type f -name '*.csv' -o -name '*.py' -o -name '*.xml' | xargs sed -i 's/base.group_hr/hr.gr
# website.salesteam_website_sales
find . -type f -name '*.csv' -o -name '*.py' -o -name '*.xml' | xargs sed -i 's/website.salesteam_w
# base.group_sale_salesman
find . -type f -name '*.csv' -o -name '*.py' -o -name '*.xml' | xargs sed -i 's/base.group_sale_sal
# product.prod_config_main
find . -type f -name '*.xml' | xargs sed -i 's/product.prod_config_main/sale.prod_config_main/g'
Note: We are happy to share our experience and hope that it will help someone to port odoo modules. We will be
glad, if you share this page or recommend our team for module migration jobs:
[email protected]
https://www.it-projects.info/page/module-migration
64
CHAPTER 4
User documentation
4.1 static/description/index.html
Image sizes
Templates
Title
Text + Image
Image + Text
Text, Image
Contact us
oe_dark
4.1.2 Templates
Title
<section class="oe_container">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2 class="oe_slogan">NAME</h2>
<h3 class="oe_slogan">SUMMARY OR SLOGAN</h3>
</div>
</div>
</section>
Text + Image
<section class="oe_container oe_dark">
<div class="oe_row oe_spaced">
<div class="oe_span6">
<p class="oe_mt32">
65
TEXT
</p>
</div>
<div class="oe_span6">
<div class="oe_row_img oe_centered">
<img class="oe_demo oe_picture oe_screenshot" src="IMAGE.png"/>
</div>
</div>
</div>
</section>
Image + Text
TODO
Text, Image
<section class="oe_container oe_dark">
<div class="oe_row oe_spaced">
<div class="oe_span12 text-center">
<p class="oe_mt32">
TEXT
</p>
</div>
<div class="oe_row_img oe_centered">
<img class="oe_demo oe_picture oe_screenshot" src="IMAGE.png"/>
</div>
</div>
</section>
Contact us
Contact us block
4.1.3 oe_dark
Use oe_dark class on every even section. Dont use oe_dark on the last section Contact us.
<section class="oe_container">
<!--Title-->
</section>
<section class="oe_container">
</section>
<section class="oe_container oe_dark">
</section>
<section class="oe_container">
</section>
<section class="oe_container oe_dark">
</section>
66
<section class="oe_container">
</section>
<section class="oe_container">
<!--Contact us block-->
</section>
4.3.3 Summary
This is an overview of content that provides a reader with the overaching theme, but does not expand on specific
details.
Summary should be included at __openerp__.py as summary:
67
export ODOO_BRANCH=10.0
echo && echo && \
curl --silent https://raw.githubusercontent.com/it-projects-llc/odoo-development/master/docs/descript
| sed "s/ODOO_BRANCH/$ODOO_BRANCH/g" \
| sed "s/STAMP1_ROTATION/$(($RANDOM % 20 - 10))/g" \
| sed "s/STAMP2_ROTATION/$(($RANDOM % 20 - 10))/g" && \
echo && echo
4.5 JS Tour
Used to demonstrate module capabilities step by step with popup windows. It may be launched automatically or
manually.
id: 'mails_count_tour',
name: _t("Mails count Tour"),
mode: 'test',
path: '/web#id=3&model=res.partner',
steps: [
{
title:
_t("Mails count tutorial"),
content:
_t("Let's see how mails count work."),
popover:
{ next: _t("Start Tutorial"), end: _t("Skip") },
},
{
title:
_t("New fields"),
content:
_t("Here is new fields with mails counters. Press one of it."),
element:
'.mails_to',
},
{
waitNot:
'.mails_to:visible',
title:
_t("Send message from here"),
placement: 'left',
content:
_t("Now you can see corresponding mails. You can send mail to this partner rig
element:
'.oe_mail_wall .oe_msg.oe_msg_composer_compact>div>.oe_compose_post',
},
]
}
What you do here is describing steps that got to be proceeded by user or phantom (phantomjs).
In odoo 8 tour defines this way:
(function () {
'use strict';
var _t = openerp._t;
openerp.Tour.register({ ...
68
Important details:
id - need to call this tour
path - from this path tour will be started in test mode
Next step occurs when all conditions are satisfied and popup window will appear near (chose position in placement)
element specified in element. Element must contain css selector of corresponding node. Conditions may be:
waitFor - this step will not start if waitFor node absent.
waitNot - this step will not start if waitNot node exists.
wait - just wait some amount of milliseconds before next step.
element - similar to waitFor, but element must be visible
closed window - if popup window have close button it must be closed before next step.
Opened popup window (from previous step) will close automatically and new window (next step) will be shown.
Inject JS Tour file on page:
4.5. JS Tour
69
70
AFTER
71
Nginx
Configure your nginx and use local link in src attribute.:
<img src="static.local/path/to/image.png"/>
You cannot use localhost due to security restrictions. So, you need to add some domain to /etc/hosts::
127.0.0.1
static.local
72
app list:
262,5 x 130
4.7.2 description/index.html
All values assumed, that you put the code inside .oe_container and .oe_row, e.g.:
<section class="oe_container">
<div class="oe_row oe_spaced">
...
<div class="oe_demo oe_picture oe_screenshot">
<img class="img img-responsive" src="1.png"/>
</div>
...
</div>
</section>
oe_span6 img.oe_demo.oe_picture.oe_screenshot
:: max-width: 362px; max-height: 382px;
img.oe_demo.oe_picture.oe_screenshot
:: max-width: 761px; max-height: 382px;
img.oe_demo.oe_screenshot
:: max-width: 928px;
4.7. Image sizes
73
74
CHAPTER 5
5.1.5 gitignore
Configure global gitignore
Possible content for ~/.gitignore_global:
*~
*.pyc
75
5.2 Porting
If you add some feature to one branch and need to add it to anoher branch, then you have to make port.
See also:
Conflicts resolving
5.2.1 Forward-port
Its the simplest case. You merge commits from older branch (e.g. 8.0) to newer branch (e.g. 9.0)
git checkout 9.0
git merge origin/8.0
# [Resolve conflicts if needed]
git push
After git merge you probably need to make some minor changes. In that case just add new commits to newer
branch
git add ...
git commit -m "...."
git push
5.2.2 Back-port
If you need to port new feature from newer branch (e.g. 9.0) to older one (e.g. 8.0), then you have to make back-port.
The problem here is that newer branch has commits which should be applied for newer branch only. That is you cannot
just make git merge 9.0, because it brings 9.0-only commits to 8.0 branch. Possible solutions here are:
Also possible to pick the commit from any remote repository. Add this repository to your remotes. Do fetch from it.
And then cherry-pick.
76
Resolve conflicts:
either edit files manually:
* open file with conflicts
* search for <<< or >>> and delete obsolete variant or make a mix of both variants.
or use following commands, if you are sure which version should be kept
git checkout --ours -- <file>
# or
git checkout --theirs -- <file>
5.3.2 Notes
Its important, that on resolving conflict stage you should not make any updates inside conflicting lines. You
can only choose which lines should be kept and which deleted. E.g. if you resolve conflicts due to porting some
updatefeature from one odoo version (e.g. 8.0) to another (e.g. 9.0), then such changes some time must be
tuned to make updatefeature work on target odoo version. But you have to make such tuning on a new commit
77
only. Make mergingchery-picking commits be only about merging and chery-picking, make porting commits
separately.
If you dont have conflicts, you do not need to make commit after cherry-pick because it creates commit by its
own.
# take one commit sha from the list and check that it's in origin/9.0.
git branch -r --contains 5cb3652be72a05330c3988d270f3aef548511b29
# possible output:
# upstream/9.0
# origin/9.0-dev
#
#
#
#
78
Nessesary to add some header for pull request. Save it. If everything is ok you will got link to your pull request.
79
# Set variables
export REPO_PATH=/path/to/misc-addons REPO_NAME=misc-addons MODULE=some_module BRANCH=10.0 DEST_REPO_
# Create patch
cd $REPO_PATH
git fetch upstream
git format-patch --stdout --root upstream/$BRANCH -- $MODULE > /tmp/relocation.patch
# Remove module from source repository
git checkout -b $BRANCH-$MODULE-relocation-remove upstream/$BRANCH
git rm -r $MODULE
git commit -m "[REM] $MODULE is relocated to $DEST_REPO_NAME"
git push origin
# then create PR on github
# Add commits to target repository
cd $DEST_REPO_PATH
git fetch upstream
git checkout -b $BRANCH-$MODULE-relocation-add upstream/$BRANCH
git am -3 < /tmp/relocation.patch
git push origin
# then create PR on github
80
Lets start
$REPO: the repository hosting the module (e.g. misc-addons)
$DEST_REPO: the repository you want to move the module to (e.g. access-addons)
$MODULE: the name of the module you want to move (e.g. group_menu_no_access)
$BRANCH: the branch of the $REPO with $MODULE (source branch, e.g. 8.0)
Warning: If you have installed git from official ubuntu 14.04 deb repository then you should first update it. You
can update git using this instruction Update git
$
$
$
$
$
$
$
$
$
$
$
$
$
cd ~
git clone https://github.com/it-projects-llc/$REPO -b $BRANCH
cd $REPO
git remote rm origin
git filter-branch --subdirectory-filter $MODULE -- --all
mkdir $MODULE
mv * $MODULE # never mind the "mv: cannot move..." warning message
git add .
git commit -m "[MOV] $MODULE: ready"
cd ~
cd $DEST_REPO
git remote add $MODULE-hosting-remote ~/$REPO
git pull $MODULE-hosting-remote $BRANCH
After the last command you will have the module with all its commits in your destination repo. Now you can push it
on github etc. You can remove ~/$REPO folder - no use of it now.
Warning: Cloning - this is required step. It is temporary directory. It will removed all modules except the one
that you want to move.
The following script may come in handy if you need to move several modules. But be sure that you understand all its
commands before using.
#!/bin/bash
source_repo=$PWD
echo $source_repo
if [ -n "$1" ]
then
module=$1
echo $module
else
echo "Must be module name"
exit $E_WRONGARGS
fi
if [ -n "$2" ]
then
dest_repo=$2
echo $dest_repo
else
echo "Must be dest_repo"
exit $E_WRONGARGS
fi
81
if [ -n "$3" ]
then
branch=$3
echo $branch
else
echo "Must be branch specified"
exit $E_WRONGARGS
fi
cp -r $source_repo ../$module
cd ../$module
git remote rm origin
git filter-branch --subdirectory-filter $module -- --all
mkdir $module
mv * $module
git add .
git commit -m "[MOV] module -- $module"
cd $dest_repo
git remote add repo_moved_module $source_repo/../$module
git pull repo_moved_module $branch --no-edit
git remote rm repo_moved_module
rm -rf $source_repo/../$module
In order to use it you should make the movemodule.sh file in your home directory and put all lines above there and
make this file executable.
$ cd ~
$ chmod +x movemodule.sh
To do the moving of group_menu_no_access from addons-yelizariev to access-addons with the movemodule.sh take
the following steps.
$ cd ~
$ git clone https://github.com/yelizariev/addons-yelizariev.git
$ cd addons-yelizariev
This part is the same as moving without the script. But then I type only one command instead of many in case of fully
manual approach.
addons-yelizarie$ ~/movemodule.sh group_menu_no_access ~/access-addons 8.0
82
5.9.1 Forbidden
Dont use tags below
[WIP], [DEV] instead of noting that work in progress make message as if your work is already done.
Remote backup
git push origin 9.0-new-module:9.0-new-module-backup
83
Then edit opened file and keep pick for the first commit and and replace pick with squash for the rest ones. E.g.
Origin:
TODO
Edited:
TODO
5.12.4 Push
git push -f origin 9.0-new-module
84
CHAPTER 6
Continuous Integration
6.1 Runbot
runbot.odoo.com
How to use runbot.odoo.com?
runbot.it-projects.info
How to deploy runbot?
6.1.1 runbot.odoo.com
http://runbot.odoo.com/ official runbot. While its main purpose is checking pull requests to official repository, it is
usefull on daily development routine.
It allows to play with any odoo version. Each build has all modules installed with demo data.
It allows to quickly try enterprise odoo versions
How to use runbot.odoo.com?
open http://runbot.odoo.com/runbot/
switch to repository you need. Odoo community (odoo/odoo) is default.
find a row with odoo version you need (10.0, 9.0, 8.0, 7.0)
click on fast forward icon to open latest build. Alternatively, click on any blue button on a row, that corresponds
to odoo version you need.
on login page enter credentials:
Admin
* login: admin
* password: admin
Demo
* login: demo
* password: demo
85
6.1.2 runbot.it-projects.info
http://runbot.it-projects.info/ customized runbot for IT-Projects repositories.
Stages of making a build:
Checkout sources from github
-base database: install updated modules for pull request builds and base modules for branch builds. For some
repositories explicit modules (i.e. ones, that are specified in runbot settings) are installed too
-all database: install all modules of the repo
run the build with two prepared databases
Main features:
Blue button - enter to -all database
Green button - enter to -base database
Key logs (shown on build page) key logs, warnings and errors
Detailed logs (txt files)
Full base logs full logs of installation process in -base database
Full all logs full logs of installation process in -all database
Full run logs full logs for both databases after running, i.e. when Blue and Green button are available.
Logs includes cron work, url requests etc
86
6.3 Coverage
87
88
CHAPTER 7
Odoo
7.1 Models
Section helps in understanding built-in models
7.1.1 ir.config_parameter
Add record by module
XML: <record>
Code:
<data noupdate="1">
<record id="myid" model="ir.config_parameter">
<field name="key">mymodule.mykey</field>
<field name="value">True</value>
</record>
Prons:
record is deleted on uninstalling
Cons:
it raises error, if record with that key is already created manulally
XML: <function>
Code:
Prons:
it doesnt raise error, if record with that key is already created manulally
Cons:
record is not deleted on uninstalling
value is overwrited after each module updating
89
YML
Code:
!python {model: ir.config_parameter}: |
SUPERUSER_ID = 1
if not self.get_param(cr, SUPERUSER_ID, "ir_attachment.location"):
self.set_param(cr, SUPERUSER_ID, "ir_attachment.location", "
postgresql:lobject")
Prons:
value is not overwrited if it already exists
Cons:
record is not deleted on uninstalling
7.1.2 res.users
TODO
7.1.3 res.groups
TODO
7.1.4 ir.model.access
Defines access to a whole model.
Each access control has a model to which it grants permissions, the permissions it grants and optionally a group.
Access controls are additive, for a given model a user has access all permissions granted to any of its groups: if the
user belongs to one group which allows writing and another which allows deleting, they can both write and delete.
If no group is specified, the access control applies to all users, otherwise it only applies to the members of the given
group.
Available permissions are creation (perm_create), searching and reading (perm_read), updating existing records
(perm_write) and deleting existing records (perm_unlink)
See also:
Superuser rights
ir.rule
Fields
90
Chapter 7. Odoo
7.1.5 ir.rule
Record rules are conditions that records must satisfy for an operation (create, read, write or delete) to be allowed.
Example of a condition: User can update Task that assigned to him.
Group field defines for which group rule is applied. If Group is not specified, then rule is global and applied for all
users.
Domain field defines conditions for records.
Boolean fields (read, write, create, delete) of ir.rule mean Apply this rule for this kind of operation. They do not mean
restrict access for this kind of operation.
Checking access algorithm
To check either user has access for example to read a record, system do as following:
Check access according to ir.model.access records. If it doesnt pass, then user doesnt get access
Find and check global rules for the model and for read operation
if the record doesnt satisfy (doesnt fit to domain) for at least one of the global rules, then user doesnt
get access
Find and check non-global rules for the model and for read operation.
if there are no such groups, then user get access
if the record satisfy (fit to domain) for at least one of the non-global rules, then user get access
See also:
Superuser rights
Fields
name = fields.Char(index=True)
active = fields.Boolean(default=True, help="If you uncheck the active field, it will disable the reco
model_id = fields.Many2one('ir.model', string='Object', index=True, required=True, ondelete="cascade"
groups = fields.Many2many('res.groups', 'rule_group_rel', 'rule_group_id', 'group_id')
domain_force = fields.Text(string='Domain')
domain = fields.Binary(compute='_force_domain', string='Domain')
perm_read = fields.Boolean(string='Apply for Read', default=True)
perm_write = fields.Boolean(string='Apply for Write', default=True)
perm_create = fields.Boolean(string='Apply for Create', default=True)
perm_unlink = fields.Boolean(string='Apply for Delete', default=True)
7.1.6 product.template
The stores have products that differ from some other only a one or few properties. Such goods it makes no sense to
separate as individual products. They are join in a group of similar goods, which are called template.
shop: product pages use product.template (when order is created, then product.product is used).
7.1. Models
91
7.1.7 product.product
The product, unlike the template, it is a separate product that can be calculated, set the price, to assign a discount.
product.product is used:
sale.order
stock
pos
7.1.8 ir.actions.todo
The model is used for executing actions (records in the ir.actions.act_window model). The model allows to set
conditions and sequence of appearance of wizards. Also you can specify a regular interface window but only as last
action. Code:
<record id="sce.initial_setup" model="ir.actions.todo">
<field name="action_id" ref="action_initial_setup"/>
<field name="state">open</field>
<field name="sequence">1</field>
<field name="type">automatic</field>
</record>
7.1.9 bus.bus
Bus
Bus is a module for instant notifications via longpolling. Add it to dependencies list:
'depends': ['bus']
What is longpolling
About longpolling
How to enable Longpolling in odoo
92
Chapter 7. Odoo
Scheme of work
Channel identifier
Listened channels
Binding notification event
Start polling
Sending notification
Handling notifications
Scheme of work
Channel identifier - is a way to distinguish one channel from another. In the main, channel contains dbname, some
string and some id.
Added via js identifiers can be string only.
var channel = JSON.stringify([dbname, 'model.name', uid]);
Listened channels
You can add channels in two ways: either on the server side via _poll function in bus controller or in js file using the
method bus.add_channel().
With controllers:
# In odoo 8.0:
import openerp.addons.bus.bus.Controller as BusController
# In odoo 9.0:
import openerp.addons.bus.controllers.main.BusController
class Controller(BusController):
def _poll(self, dbname, channels, last, options):
7.1. Models
93
if request.session.uid:
registry, cr, uid, context = request.registry, request.cr, request.session.uid, request.c
new_channel = (request.db, 'module.name', request.uid)
channels.append(new_channel)
return super(Controller, self)._poll(dbname, channels, last, options)
In the js file:
// 8.0
var bus = openerp.bus.bus;
// 9.0+
var bus = require('bus.bus').bus;
var channel = JSON.stringify([dbname, 'model.name', uid]);
bus.add_channel(new_channel);
In js file:
bus.on("notification", this, this.on_notification);
Start polling
In js file:
bus.start_polling();
Note: You dont need to call bus.start_polling(); if it was already started by other module.
When polling starts, request /longpolling/poll is sent, so you can find and check it via Network tool in your
browser
Sending notification
You can send notification only through a python. If you need to do it through the client send a signal to server in a
usual way first (e.g. via controllers).
self.env['bus.bus'].sendmany([(channel1, message1), (channel2, message2), ...])
# or
self.env['bus.bus'].sendone(channel, message)
Handling notifications
on_notification: function (notifications) {
// Old versions passes single notification item here. Convert it to the latest format.
if (typeof notification[0][0] === 'string') {
notification = [notification]
}
for (var i = 0; i < notification.length; i++) {
var channel = notification[i][0];
94
Chapter 7. Odoo
Examples
pos_multi_session:
add channel (python)
bind event
send notification
chess:
add channel (js)
bind event
send notification
mail_move_message:
add channel (python)
bind event
send notification
7.1.10 ir.cron
Creating automated actions in Odoo
Schedulers are automated actions that run automatically over a time period and can do a lot of things. They give the
ability to execute actions database without needing manual interaction. Odoo makes running a background job easy:
simply insert a record to ir.cron table and Odoo will execute it as defined.
1. Creating the model and method of this model.
class model_name(models.Model):
_name = "model.name"
# fields
def method_name(self, cr, uid, context=None): # method of this model
# your code
7.1. Models
95
The first thing you notice is the data noupdate="1", this is telling Odoo that all code within this tag shouldnt be
updated when you update your module.
<record id="unique_name" model="ir.cron">
The id is an unique identifier for Odoo to know what record is linked to which id. The model called (ir.cron) is the
model specifically made by Odoo for all automated actions. This model contains all automated actions and should
always be specified.
<field name="name">Name </field>
This user id is referring to a specific user, in most cases this will be base.user_root.
<field name="interval_number">1</field>
Interval Unit.
It should be one value for the list: minutes, hours, days, weeks, months.
<field name="numbercall">-1</field>
An integer value specifying how many times the job is executed. A negative value means no limit.
<field name="doal">1</field>
A boolean value indicating whether missed occurrences should be executed when the server restarts.
<field name="nextcall" >2016-12-31 23:59:59</field> <!-- notice the date/time format -->
The field model specifies on which model the automated action should be called.
96
Chapter 7. Odoo
The priority of the job, as an integer: 0 means higher priority, 10 means lower priority.
Defaults.
Name
nextcall
priority
user_id
interval_number
interval_type
numbercall
active
doall
Definition
lambda *a: time.strftime(DEFAULT_SERVER_DATETIME_FORMAT
5
lambda obj,cr,uid,context: uid
1
months
1
1
1
7.1.11 mail.message
Message Subtypes in Odoo
Most of the time in Odoo multiple users work upon one particular record or document like sale order,Invoice ,Tasks
etc. In such scenarios,it becomes extremely important to track changes done by every individual against that document.
It helps management to find any possible reason in case of any issue occurs. Odoo provides this feature to great extent
with the help of OpenChatter Integration.
Consider a scenario where multiple users are working in a single project.Various parameters for that project are already
configured like deadline,Initially Planned Hours etc. Now one of the user changes the value of Planned Hours. So
now it is important to know which user has changed it and what was the previous value. We can track it by creating
message subtypes in Odoo as following.
It needs to be defined in XML which will have following syntax.
<record id="mt_task_planned_hours" model="mail.message.subtype">
<field name="name">Task planned hours changed</field>
<field name="res_model">project.task</field>
<field name="default" eval="True"/>
<field name="description">Task planned hours changed</field>
</record>
Users can also have a mail.message.subtype that depends on an other to act through a relation field. For the planned
hours, we can have following sysntax for it.
<record id="mt_task_planned_hours_change" model="mail.message.subtype">
<field name="name">Task planned hours changed</field>
<field name="sequence">10</field>
<field name="res_model">project.task</field>
<field name="parent_id" eval="ref('mt_task_planned_hours')"/>
<field name="relation_field">project_id</field>
</record>
7.1. Models
97
Odoo provide feature to track various events related with one particular document with the help of _track attribute. If
we inherit mail.thread object then with the help of _track attribute, user can sent notification also to keep aware others
about changes happening against this particular document. The syntax can be as follow.
_track = {
'planned_hours': {
'module_name.mt_task_planned_hours': lambda self, cr, uid, obj, ctx=None: obj.planned_hours,
},
In order to track changes related with any field,Odoo provides an attribute named as track_visibility.It has to be defined
at field level which has below syntax.
Hence, it is easy to track the changes done so far against any particular document by different users.
Database with dots Early version of odoo doesnt allow to create databases with dots. You can remove this restriction in two ways:
1. Updates sources:
cd path/to/odoo
sed -i 's/matches="[^"]*"//g' addons/web/static/src/xml/base.xml
98
Chapter 7. Odoo
From terminal
9.0+
To create new database simple add -d parameter when you run odoo, e.g.:
./openerp-server -d database1
99
click [Install]
9.0+
100
Chapter 7. Odoo
101
102
Chapter 7. Odoo
CHAPTER 8
Odoo administration
Official
docs:
*
https://www.odoo.com/documentation/8.0/setup/install.html
https://www.odoo.com/documentation/8.0/setup/deploy.html
103
# http://wkhtmltopdf.org/downloads.html
# e.g.
apt-get install xfonts-base xfonts-75dpi
apt-get -f install
wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-trusty-amd64.deb
dpkg -i wkhtmltox-*.deb
# requirements.txt
cd /path/to/odoo
sudo pip install -r requirements.txt
sudo pip install watchdog
# fix error with jpeg (if you get it)
# uninstall PIL
sudo pip uninstall PIL
# install libjpeg-dev with apt
sudo apt-get install libjpeg-dev
# reinstall pillow
pip install -I pillow
# (from here https://github.com/odoo/odoo/issues/612 )
# fix issue with lessc
# install Less CSS via nodejs according to this instruction:
# https://www.odoo.com/documentation/8.0/setup/install.html
# create postgres user:
sudo su - postgres -c "createuser -s $USER"
# Create new config file if you don't have it yet:
cd /path/to/odoo
./openerp-server --save
# then edit it, e.g. via emacs
emacs -nw ~/.openerp_serverrc
# set dbfilter = ^%h$
# set workers = 2 # to make longpolling\bus\im work
# create different versions of conf file:
cp ~/.openerp_serverrc ~/.openerp_serverrc-9
cp ~/.openerp_serverrc ~/.openerp_serverrc-8
################### /etc/hosts
# /etc/hosts must contains domains you use, e.g:
sudo bash -c "echo '127.0.0.1 8_0-project1.local'
sudo bash -c "echo '127.0.0.1 8_0-project2.local'
sudo bash -c "echo '127.0.0.1 9_0-project1.local'
>> /etc/hosts"
>> /etc/hosts"
>> /etc/hosts"
################### nginx
# put nginx_odoo.conf to /etc/nginx/sites-enabled/
# delete default configuration:
cd /etc/nginx/sites-enabled/
rm default
# restart nginx
sudo /etc/init.d/nginx restart
################### run Odoo
cd /path/to/odoo
104
nginx_odoo.conf
server {
listen 80 default_server;
server_name .local;
proxy_buffers 16 64k;
proxy_buffer_size 128k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
#proxy_redirect http:// https://;
proxy_read_timeout 600s;
client_max_body_size 100m;
location /longpolling {
proxy_pass http://127.0.0.1:8072;
}
location / {
proxy_pass http://127.0.0.1:8069;
}
}
8.2 Longpolling
Longpolling is a way to deliver instant notification to web client (e.g. in chats).
To activate longpolling:
install gevent and psycogreen
python -c "import gevent" || sudo pip install gevent
python -c "import psycogreen" || sudo pip install psycogreen
105
configure nginx
location /longpolling {
proxy_pass http://127.0.0.1:8072;
}
location / {
proxy_pass http://127.0.0.1:8069;
}
if you install odoo 9.0 via deb package, then you have to restore openerp-gevent file (see #10207):
cd /usr/bin/
wget https://raw.githubusercontent.com/odoo/odoo/9.0/openerp-gevent
chmod +x openerp-gevent
8.4 --workers
Non-zero values for --workers activates Multiprocessing.
Multiprocessing increases stability, makes somewhat better use of computing resources and can be better monitored
and resource-restricted.
106
Number of workers should be based on the number of cores in the machine (possibly with some room for cron
workers depending on how much cron work is predicted)
Worker limits can be configured based on the hardware configuration to avoid resources exhaustion
Warning: multiprocessing mode currently isnt available on Windows
8.4.1 Longpolling
Hidden feature of Multiprocessing is automatic run gevent process for longpolling support.
Longpolling is an extra proccess, i.e. if you have --workers=2 then you will get 2 worker processes and 1 gevent
process
8.5 --addons-path
8.5.1 Duplicate addons
If you have two folder with the same module and you have reason to add both folders to addons_path, then first
found version of the module will be used. That is folder in the begging of addons_path list has more priority.
8.6 --log-handler
--log-handler=PREFIX:LEVEL
Setups a handler at LEVEL for a given PREFIX. This option can be repeated.
For example, if you want to have DEBUG level for module telegram only, you can run it with parameter:
--log-handler=openerp.addons.telegram:DEBUG
8.5. --addons-path
107
108
CHAPTER 9
Continuous Delivery
TODO
109
110
CHAPTER 10
IDE
10.1 Emacs
10.1.1 Emacs
Install emacs 24.4+ http://askubuntu.com/questions/437255/how-to-install-emacs-24-4-on-ubuntu
Open Emacs
Press Alt-x package-list-packages
install packages: click i and then x
some packages require dependencies, that have to be installed via terminal * flymake * loccur * flymake-css *
flymake-jslint * flymake-python-pyflakes
sudo pip install flake8
magit
js3-mode
10.1.2 Spacemacs
Requirements
emacs version 24 or newer.
Installation
Install spacemacs from github https://github.com/syl20bnr/spacemacs
Documentation
http://spacemacs.org/doc/DOCUMENTATION.html
111
10.1.4 Pylint
Pylint is a tool that checks for errors in Python code, tries to enforce a coding standard and looks for code smells. It
can also look for certain type errors, it can recommend suggestions about how particular blocks can be refactored and
can offer you details about the codes complexity. https://pylint.readthedocs.io/en/latest/
Install pylint.
sudo pip install pylint
With the Flycheck emacs extension, pylints output will be shown right inside your emacs buffers. Spacemacs has
flycheck in his syntax-checking layer.
M-x package-install RET flycheck
112
Useful configurations
By default there is 100 characters per line allowed. Allow 120 characters
max-line-length=120
To disable certain warning add its code to disable list in pylintrc. For example, If you dont like this message Missing method docstring with code C0111 or this Use of super on an old style class
(E1002)
disable=E1608,W1627,E1601,E1603,E1602,E1605,E1604,E1607,E1606,W1621,W1620,W1623,W1622,W1625,W1624,W16
10.2 PyCharm
10.2.1 PyCharm
Remote access with pgAdmin to Odoo postgre database on Ubuntu
This is for PgAdmin integration, but same method working with PyCharm.
STEP #1 get pgAdmin Install pgAdmin from pgadmin.org
STEP #2 allow postgre server remote connections from everywhere Open etc/postgresql/9.x/main/pg_hba.conf and
add following line: host all all all md5
STEP #3 let the postgre server listen to everyone Open etc/postgresql/9.x/main/postgresql.conf and change following
line: listen_addresses = *
10.2. PyCharm
113
STEP #4 give the user postgres a password Start the psql terminal: sudo -u postgres psql Give a password: ALTER
USER postgres PASSWORD yourpassword; Leave the psql terminal: q
STEP #5 Restart postgre server by executing this terminal command: sudo /etc/init.d/postgresql restart
STEP #6 Start pgAdmin and add a connection to a server like this:
114
10.3 Tmux
10.3.1 Tmux installation
Install Tmux
sudo apt-get install tmux
Check version
tmux -V
If you have 1.8 or older then you should update. Here are update commands for ubuntu 14.04
sudo
sudo
sudo
sudo
sudo
apt-get update
apt-get install -y python-software-properties software-properties-common
add-apt-repository -y ppa:pi-rho/dev
apt-get update
apt-get install -y tmux=2.0-1~ppa1~t
Now if you do tmux -V it should show tmux 2.0 which is a good version for tmux plugins.
Based on: http://stackoverflow.com/questions/25940944/ugrade-tmux-from-1-8-to-1-9-on-ubuntu-14-04
Install Tmux Plugin Manager
Requirements: tmux version 1.9 (or higher), git, bash
Clone TPM:
$ git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Other examples:
set -g @plugin 'github_username/plugin_name'
set -g @plugin '[email protected]/user/plugin'
set -g @plugin '[email protected]/user/plugin'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
10.3. Tmux
115
Hit prefix + I to fetch the plugin and source it. You should now be able to use the plugin.
Based on: https://github.com/tmux-plugins/tmux-resurrect
Install tmux-continuum
Last saved environment is automatically restored when tmux is started. Put the following lines in tmux.conf:
set -g @continuum-save-interval '5'
set -g @continuum-restore 'on'
Your environment will be automatically saved every 5 minutes. When you start tmux it will automatically restore
Based on: https://github.com/tmux-plugins/tmux-continuum
116
of plugins
@plugin 'tmux-plugins/tpm'
@plugin 'tmux-plugins/tmux-sensible'
@plugin 'tmux-plugins/tmux-resurrect'
@plugin 'tmux-plugins/tmux-continuum'
@continuum-save-interval '5'
@continuum-restore 'on'
Other examples:
set -g @plugin 'github_username/plugin_name'
set -g @plugin '[email protected]/user/plugin'
set -g @plugin '[email protected]/user/plugin'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
117
// The following will hide the compiled file in the editor/ add other file to hide them from edit
"files.exclude": {
"**/*.pyc": true
}
}
Note: some lines are commented because it is optional. you can activate them if needed like in the case of using
Virtualenv.
10.4.3 Debugging
Launch Configurations
To debug your app in VS Code, youll first need to set up your launch configuration file - launch.json.
Click on the Configure gear icon on the Debug view top bar, choose your debug environment and VS
Code will generate a launch.json file under your workspaces .vscode folder.
sample python Debugging
118
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config.python.pythonPath}",
//"program": "${file}", use this to debug opened file.
"program": "${workspaceRoot}/Path/To/odoo.py",
"args": [
"-c ${workspaceRoot}/sampleconfigurationfile.cfg"
],
"cwd": "${workspaceRoot}",
"console": "externalTerminal",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
Important: use args to specify any options like databace, config or user name and password.
sorce
119
120
CHAPTER 11
Other
Note that Document Title and Section Title above both use equals signs, but are distict and unrelated styles. The
text of overline-and-underlined titles (but not underlined-only) may be inset for aesthetics.
Sections
# with overline, for parts
* with overline, for chapters
=, for sections
-, for subsections
^, for subsubsections
, for paragraphs
121
Code block
Enter double colon (::) and then empty line and then at least one space and finaly you can enter your code.
Also you can use inplace code reference by using .
11.1.2 Selection
**bold**
*italic*
code
11.1.3 Lists
* - not numerated
#. - numerated
1,2,3, ... - numerated
11.1.4 Links
internal link:
:doc:`Link Text<../relative/path/to/article>`
external link:
`Link Text <https://google.com/>`_
Last two arguments is width and height. Consider to add chromium window borders to your screenshot size. In my
case it 10px to width and 80px to height. Likely you got same. So for 750 x 371 it be 760 x 451.
Note: We try our best to improve this manual, but if you still have difficults, we can offer private tutoring / advising
/ consultation on odoo development (resolve problem that developer(s) stack on, reveview code and pull requests ect).
Feel free to hire us on upwork:
Ivan Yelizariev
Ildar Nasyrov
122
123