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

Transfer data from a many2one field to another form

By
Mohammed Roshan
on 1/14/15, 12:44 AM 692 views

Am using ' create_uid' field in crm.phonecall model, which is a many to one field.

when i convert that phonecall to opportunity using 'convert to opportunity' button.

I want the data in create_uid to be transfered to a custom field in 'crm.lead' model (this model holds the code for opportunity).

thanks in advance

 

 

3
abin c ibrahim
On 1/16/15, 8:53 AM

Dear roshan,

try this,,,,

def convert_opportunity in crm_phonecall.py as follows,

def convert_opportunity(self, cr, uid, ids, opportunity_summary=False, partner_id=False,cr_id=False, planned_revenue=0.0, probability=0.0, context=None):
        partner = self.pool.get('res.partner')
        opportunity = self.pool.get('crm.lead')
        #cr_cr = self.pool.get('crm.user')
        opportunity_dict = {}
        default_contact = False
        for call in self.browse(cr, uid, ids, context=context):            
            #cr_id=cr_cr.browse(cr, uid, call.create_uid, context=context)
            if not cr_id:
                cr_id= call.create_uid and call.create_uid.id or False  
            if not partner_id:
                partner_id = call.partner_id and call.partner_id.id or False                              
            if partner_id:
                address_id = partner.address_get(cr, uid, [partner_id])['default']
                if address_id:
                    default_contact = partner.browse(cr, uid, address_id, context=context)
            opportunity_id = opportunity.create(cr, uid, {
                            'name': opportunity_summary or call.name,
                            'activity':call.activity,
                            'planned_revenue': planned_revenue,
                            'probability': probability,
                            'partner_id': partner_id or False,
                            'mobile': default_contact and default_contact.mobile,
                            'section_id': call.section_id and call.section_id.id or False,
                            'description': call.description or False,
                            'priority': call.priority,
                            'type': 'opportunity',
                            'phone': call.partner_phone or False,
                            'email_from': default_contact and default_contact.email,
                            'created_by':cr_id,
                        })
            vals = {
                'partner_id': partner_id,
                'opportunity_id': opportunity_id,
                'state': 'done',
            }
            self.write(cr, uid, [call.id], vals, context=context)
            opportunity_dict[call.id] = opportunity_id
        return opportunity_dict

Then create a field in crm_lead.py as follows,

        'created_by':fields.many2one('res.users', 'Created By', ondelete='set null', track_visibility='onchange',select=True),

Then add the field in crm_lead_view.xml to view this..

hope this helps,,,

 

0
abin c ibrahim
On 1/16/15, 8:53 AM

Dear roshan,

try this,,,,

def convert_opportunity in crm_phonecall.py as follows,

def convert_opportunity(self, cr, uid, ids, opportunity_summary=False, partner_id=False,cr_id=False, planned_revenue=0.0, probability=0.0, context=None):
        partner = self.pool.get('res.partner')
        opportunity = self.pool.get('crm.lead')
        #cr_cr = self.pool.get('crm.user')
        opportunity_dict = {}
        default_contact = False
        for call in self.browse(cr, uid, ids, context=context):            
            #cr_id=cr_cr.browse(cr, uid, call.create_uid, context=context)
            if not cr_id:
                cr_id= call.create_uid and call.create_uid.id or False  
            if not partner_id:
                partner_id = call.partner_id and call.partner_id.id or False                              
            if partner_id:
                address_id = partner.address_get(cr, uid, [partner_id])['default']
                if address_id:
                    default_contact = partner.browse(cr, uid, address_id, context=context)
            opportunity_id = opportunity.create(cr, uid, {
                            'name': opportunity_summary or call.name,
                            'activity':call.activity,
                            'planned_revenue': planned_revenue,
                            'probability': probability,
                            'partner_id': partner_id or False,
                            'mobile': default_contact and default_contact.mobile,
                            'section_id': call.section_id and call.section_id.id or False,
                            'description': call.description or False,
                            'priority': call.priority,
                            'type': 'opportunity',
                            'phone': call.partner_phone or False,
                            'email_from': default_contact and default_contact.email,
                            'created_by':cr_id,
                        })
            vals = {
                'partner_id': partner_id,
                'opportunity_id': opportunity_id,
                'state': 'done',
            }
            self.write(cr, uid, [call.id], vals, context=context)
            opportunity_dict[call.id] = opportunity_id
        return opportunity_dict

Then create a field in crm_lead.py as follows,

        'created_by':fields.many2one('res.users', 'Created By', ondelete='set null', track_visibility='onchange',select=True),

Then add the field in crm_lead_view.xml to view this..

hope this helps,,,

 

-1
aci aisha
On 1/16/15, 8:57 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/14/15, 12:44 AM
Seen: 692 times
Last updated: 3/16/15, 8:10 AM