This question has been flagged
3 Replies
4325 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

 

 

Avatar
Discard
Best Answer

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,,,

 

Avatar
Discard
Best Answer

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,,,

 

Avatar
Discard
Best Answer
Avatar
Discard