One Module fields use in other module

陌路散爱 提交于 2019-12-10 12:01:57

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/13579178/one-module-fields-use-in-other-module

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!