Add a CrmLead opportunity on Partner creation

51 views Asked by At

i just started studing Odoo 13 making some customizations.

I need to create a new Crm Opportunity when i create new contact.

from odoo import models, fields, api, crmlead
from datetime import datetime

class ResPartner(models.Model):
    _inherit = 'res.partner'


    @api.model
    def create(self, values):
        result = super(ResPartner, self).create(values)
        CrmLead.create({
            'company_id': 1,
            'priority': '0',
            'name': 'murri',
            'partner_id': 3705,
            'planned_revenue': 0,
            'date_deadline': datetime.date(2020, 10, 26)
        })
        return result

I tried to extend ResPartner but i give an error

ImportError: cannot import name 'crmlead' from 'odoo

2

There are 2 answers

0
Dipen Shah On BEST ANSWER

Define the destination model which you creating from the source model.

@api.model
def create(self, values):
    CrmLead = self.env['crm.lead'] // Destination Object Environment Create
    result = super(ResPartner, self).create(values)
    CrmLead.create({
        'company_id': 1,
        'priority': '0',
        'name': 'murri',
        'partner_id': 3705,
        'planned_revenue': 0,
        'date_deadline': datetime.date(2020, 10, 26)
    })
return result
0
Adam Strauss On

Because Odoo don't know what is meant by CrmLead for that you can do these things to get rid from this error.

@api.model
def create(self, values):
    CrmLead = self.env['crm.lead']    // Creating an object of 'crm.lead' model
    result = super(ResPartner, self).create(values)
    CrmLead.create({
        'company_id': 1,
        'priority': '0',
        'name': 'murri',
        'partner_id': 3705,
        'planned_revenue': 0,
        'date_deadline': datetime.date(2020, 10, 26)
    })
    return result

Or

@api.model
def create(self, values):
    result = super(ResPartner, self).create(values)
    self.env['crm.lead'].create({
        'company_id': 1,
        'priority': '0',
        'name': 'murri',
        'partner_id': 3705,
        'planned_revenue': 0,
        'date_deadline': datetime.date(2020, 10, 26)
    })
    return result