Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Override change_partner_id method in Opportunities

By
Jose Osuna
on 1/20/14, 2:58 PM 1,098 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.

1
Jose Osuna
On 8/20/15, 3:15 PM

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! :-)

0
zhanghao章浩
On 8/21/15, 12:21 AM

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.


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

Jose Osuna
on 8/21/15, 11:12 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/20/14, 2:58 PM
Seen: 1098 times
Last updated: 8/21/15, 8:52 PM