Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
4447 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
17
dic 21
24680
1
dic 18
19753
1
jul 15
7246
2
mar 15
5582
2
mar 15
8896