One Module fields use in other module

2019-06-10 02:58发布

I am trying to use some fields of "Job Positions" in "Opportunities" and we can say it as a merger fields. but i am unable to do this task . i have no knowledge about Python language.

I have created a user defined fields and use it in opportunities by XML coding by developer options . I know that it is easy because user defined fields has "crm.lead" named module which is same in opportunities.

but now When i want to use this fields in "hr.job" then it give me error "fields not found" . i know that this fields is not in current module and it is part of "crm.lead" not "hr.job".

Is it possible to use one module fields in another module?

标签: openerp
2条回答
淡お忘
2楼-- · 2019-06-10 03:26

yes you can it done by _inherits. for eg. hr_job in hr module .

class hr_job(osv.osv):
    _name = "hr.job"
    _description = "job position"
        _columns = {
        'name': fields.char('job name', size=64)

      }

crm_lead in crm module.

class crm_lead(osv.osv):
    _name = "crm.lead"
   _inherits = {'hr.job': 'job_id'}
    _description = "Lead/Opportunity"
        _columns = {
        'partner_id': fields.many2one('res.partner', 'Partner')

      }

in xml file of crm create form view.

<record id="crm_lead_form" model="ir.ui.view">
        <field name="name">crm.lead</field>
        <field name="model">crm.lead</field>
        <field name="arch" type="xml">
            <form>
             <field name="name"/> # job name from hr_job
             <field name="partner_id"/> # partner_id from crm.lead
           </form>
       </field>
 </record>

don't forget add dependency.

查看更多
对你真心纯属浪费
3楼-- · 2019-06-10 03:28

Yes you can do so. First you have to create an object for that and then browse the record and fetch the value of the field which you want.
For example create one method and then browse the crm.lead record:

crm_obj = self.pool.get('crm.lead')
crm_brw = crm_obj.browse(cr, uid, crm_rec_id, context=context)
print "my field value::  ", crm_brw.your_field

Here, "crm_rec_id" is the id of the record of crm.lead object

There are lots of examples given in addons.

查看更多
登录 后发表回答