Skip to Content
Menu
This question has been flagged
2 Replies
4468 Views

Hi,

I'm working on adding a new field in opportunites view and I want to override the on_change event of the parent_id field to use my new custom field. I've changed the view crm.crm_case_form_view_oppor of crm.lead object as follow>

Original: \< field name="partner_id" on_change="onchange_partner_id(partner_id, email_from)" string="Customer" context="{'default_name': partner_name, 'default_email': email_from, 'default_phone': phone}" />

Changed: \, field name="partner_id" on_change="onchange_partner_id(partner_id, email_from)" string="Customer" context="{'default_name': partner_name, 'default_email': email_from, 'default_phone': phone, 'new_partner_field' : new_partner_field_value}" />

But now, I can't find the onchange_partner_id method!

I noticed that in crm.lead, there are 2 onchange methods for partner_id: - on_change_partner ( I used this in the lead view ) - onchange_partner_id (defined in base_stage)

The first one is called when changing the partner_id in the lead form. The second one when changing the partner_id in the opportunity form. The methods seem to be almost identical, except that the second one does an address_get for 'contact'.

On Opportunity view the method receives the parameters ( parent_id and email ) and context, however, in base_stage the method doesn't seems to receive the context and I can't override it in order to use my new custom field :

def onchange_partner_id(self, cr, uid, ids, part, email=False):
    """ This function returns value of partner address based on partner
        :param part: Partner's id
        :param email: Partner's email ID
    """
    data={}
    if  part:
        addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['contact'])
        data.update(self.onchange_partner_address_id(cr, uid, ids, addr['contact'])['value'])
    return {'value': data}

I want to override this method in Opportunity view. Someone has coped with this task?

Thank you all.

Avatar
Discard
Author Best Answer

Well, after more than a year I have evolved as a pokemon in a new level of evolution. And I came back to my old question to answer to myself of the past. The solution was quite simple.
base_stage object is a set of utilities for all the models who have inherited the mailgate.thread model, like crm.lead does in

 class crm_lead(base_stage, format_address, osv.osv):
    """ CRM Lead Case """
    _name = "crm.lead"
    _description = "Lead/Opportunity"
    _order = "priority,date_action,id desc"
    _inherit = ['mail.thread', 'ir.needaction_mixin']

So I didn't needed to find a way to override onchange_partner_address_id() directly from base_stage. I only need to override this method in the same place where I have done with onchange_partner() for crm.lead (commented in my question) .
This is the simple solution:.

class crm_lead_x(osv.osv):
  _inherit = "crm.lead"
def onchange_partner_id(self, cr, uid, ids, part, email=False): #Override on_change_partner_id used in crm.lead but is defined in base_status/base_stage values=super(crm_lead_x, self).onchange_partner_id(cr,uid,ids,part,email=email) if part: partner = self.pool.get('res.partner').browse(cr, uid, part, context=False) values['value']['new_partner_field'] = partner.new_partner_field return values

Enjoy it myself of the past! :-)

Avatar
Discard
Best Answer

Thanks for your answer. 

Just at yestday,

I have add 3 new field to res.partner  and I want use these 3 new field at crm.lead. (Opportunities form view )

I want these 3 new field  can appear infomation automatic when i select Custom.

: when you choose a custom at Opportunities form view , the Email and Phone can automatic appear.

read your question and  answer ,I think it will help me to do these.

and i change my plan :  

add 3 new field in crm.lead ,  when these field's infomation is changed at crm.lead  it also changed at res.partnet automaticly.

Maybe it is still hard to me ,but at least it can improve  my skill.:-)

sorry for my poor english. 

thanks again.


Avatar
Discard
Author

zhanghao: I'm happy that my ask&answer lost in time case could help you :-)

Related Posts Replies Views Activity
0
Aug 24
188
2
Mar 24
256
2
Jun 23
964
1
Jul 22
1588
0
May 22
911