Odoo Help

Welcome!

This community 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.

1

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

By
vital_zaq6
on 12/3/13, 6:19 AM 892 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 ?

0
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 = {
        ...
        'analytic_account_id':

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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