'Set lead against new opportunity'

def make_new_lead_if_required(self):

    if ((not (self.lead or self.customer)) and self.contact_email):
        lead_name = frappe.db.get_value(u'Lead', {u'email_id': self.contact_email})
        if (not lead_name):
            sender_name = get_fullname(self.contact_email)
            if (sender_name == self.contact_email):
                sender_name = None
            if ((not sender_name) and (u'@' in self.contact_email)):
                email_name = self.contact_email.split(u'@')[0]
                email_split = email_name.split(u'.')
                sender_name = u''
                for s in email_split:
                    sender_name += (s.capitalize() + u'    ')
            lead = frappe.get_doc({u'doctype': u'Lead', u'email_id': self.contact_email, u'lead_name': (sender_name or u'Unknown')})
            lead.flags.ignore_email_validation = True
            lead.insert(ignore_permissions=True)
            lead_name = lead.name
        self.enquiry_from = u'Lead'
        self.lead = lead_name
