Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
4443 Ansichten

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 ?

Avatar
Verwerfen
Beste Antwort

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.

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
17
Dez. 21
24678
1
Dez. 18
19753
1
Juli 15
7246
2
März 15
5582
2
März 15
8893