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.

1

Many2one Problem...

By
abin c ibrahim
on 1/14/15, 6:49 AM 593 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

Inherit method  def convert_opportunity() and pass the create_uid from crm.phonecall to custom field of crm.lead object.

Yogesh
on 1/14/15, 9:43 AM
0

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
3883
| 5 3 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 1/14/15, 7:24 AM

Try this,
class crm_phonecall(orm.Model):
    """ Inherit Model for CRM phonecalls """
    _inherit = "crm.phonecall"

    def convert_opportunity(self, cr, uid, ids, opportunity_summary=False, partner_id=False, planned_revenue=0.0, probability=0.0, context=None):
        res = super(crm_phonecall, self).convert_opportunity(cr, uid, ids, opportunity_summary=opportunity_summary, partner_id=partner_id, planned_revenue=planned_revenue, probability=probability, context=context)
        for record in self.browse(cr, uid, ids, context):
            opportunity_id = res[record.id]
            self.pool.get('crm.lead').write(cr, uid, [opportunity_id], {'custom_field': record.create_uid})
        return res

0
abin c ibrahim
On 1/15/15, 12:09 AM

Thanks Atchuthan,

I already have the class "crm_phonecall" and def "convert_opportunity",

Can you plz tell in where the code should added in my def,

my def is the following..

 

    def convert_opportunity(self, cr, uid, ids, opportunity_summary=False, partner_id=False, planned_revenue=0.0, probability=0.0, context=None):
        partner = self.pool.get('res.partner')
        opportunity = self.pool.get('crm.lead')
        opportunity_dict = {}
        default_contact = False
        for call in self.browse(cr, uid, ids, context=context):
            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,
                        })
            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

0
abin c ibrahim
On 1/15/15, 12:09 AM

Thanks Atchuthan,

I already have the class "crm_phonecall" and def "convert_opportunity",

Can you plz tell in where the code should added in my def,

my def is the following..

 

    def convert_opportunity(self, cr, uid, ids, opportunity_summary=False, partner_id=False, planned_revenue=0.0, probability=0.0, context=None):
        partner = self.pool.get('res.partner')
        opportunity = self.pool.get('crm.lead')
        opportunity_dict = {}
        default_contact = False
        for call in self.browse(cr, uid, ids, context=context):
            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,
                        })
            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

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, 6:49 AM
Seen: 593 times
Last updated: 3/16/15, 8:10 AM