Odoo Help


When i need to use _inherits = {'model': "field"} ?

on 12/3/13, 6:19 AM 1,284 views

I want to link department (hr.department) to analytic account (account.analytic.account)

example dept d1 -> a1 and if user from d1 create invoice i auto select a1 as analytic account

and here is my code

class hr_department(osv.osv):
    _inherit = "hr.department"
    _name = "hr.department"
    _columns = {
        'analytic_account_id': fields.many2one('account.analytic.account', 'Contract/Analytic', ondelete="restrict", required=True),

but what i see the in project:

class project(osv.osv):
    _name = "project.project"
    _description = "Project"
    _inherits = {'account.analytic.account': "analytic_account_id",....}
_columns = {
        'analytic_account_id': fields.many2one('account.analytic.account', 'Contract/Analytic', help="Link this project to an analytic account if you need financial management on projects. It enables you to connect projects with budgets, planning, cost and revenue analysis, timesheets on projects, etc.", ondelete="cascade", required=True),

what is the difference ? why not just many2one? i think using many2one i always can access data from related object or i do not understand something? need i use _inherits = {'account.analytic.account': "analytic_account_id",....} in my case or it is enough just many2one to account.analytic.account ?

Torsten Francke
On 12/3/13, 9:54 AM

If you are define in a openerp model:

_name = "project.project"
_inherits = {'account.analytic.account': "analytic_account_id",....}

Means that you have a new Object "project.project" which get all methods and columns from "account.analytic.account". analytic_account_id is the referenz key to the inherit object. The columns share from "project.project" with "account.analytic.account" will be store in the account_analytic_account table and the extra columns from your object where store in project_project and add a relation to that key. The OpenERP ORM will load the data from both tables and gibe you one object "project.project" back.

On the other side:

_columns = {

is a relation (to the same table to make a tree in datastructure) and independent from inherits. So don't mix it.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 12/3/13, 6:19 AM
Seen: 1284 times
Last updated: 3/16/15, 8:10 AM