콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
4490 화면

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 ?

아바타
취소
베스트 답변

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.

아바타
취소
관련 게시물 답글 화면 활동
17
12월 21
24768
1
12월 18
19824
1
7월 15
7271
2
3월 15
5626
2
3월 15
8974