Example #1
0
 def test_lead_conversion(self):
     """
     Create a Lead object within Salesforce and try to
     convert it, convert/merge it with the information from a duplicit Lead,
     then clean all the generated objects.
     """
     lead = Lead(FirstName="Foo",
                 LastName="Bar",
                 Company="django-salesforce",
                 Street='Test Avenue 45')
     lead.save()
     lead2 = Lead(FirstName="Foo",
                  LastName="Bar",
                  Company="django-salesforce",
                  Phone='123456789')
     lead2.save()
     ret = None
     try:
         # convert the first Lead
         ret = convert_lead(lead, doNotCreateOpportunity=True)
         # print("Response from convertLead: " +
         #       ', '.join('%s: %s' % (k, v) for k, v in sorted(ret.items())))
         expected_names = set(('accountId', 'contactId', 'leadId',
                               'opportunityId', 'success'))
         self.assertEqual(set(ret), expected_names)
         self.assertEqual(ret['success'], 'true')
         # merge the new Account with the second Lead
         ret2 = convert_lead(lead2,
                             doNotCreateOpportunity=True,
                             accountId=ret['accountId'])
         account = Account.objects.get(pk=ret['accountId'])
         # verify that account is merged
         self.assertEqual(ret2['accountId'], account.pk)
         self.assertEqual(account.BillingStreet, 'Test Avenue 45')
         self.assertEqual(account.Phone, '123456789')
     finally:
         # Cleaning up...
         if ret:
             # Deleting the Account object will also delete the related Contact
             # and Opportunity objects.
             try:
                 account = Account.objects.get(pk=ret['accountId'])
             except Exception:  # pylint:disable=broad-except
                 # this allows to recycle the account even if the queryset code is broken
                 account = Account(pk=ret['accountId'])
                 account._state.db = lead._state.db
             account.delete()
         lead.delete()  # FYI, ret['leadId'] == lead.pk
         lead2.delete()
Example #2
0
    def test_lead_conversion(self):
        """
        Create a Lead object within Salesforce and try to
        convert it, then clean all the generated objects.
        """
        lead = Lead(FirstName="Foo", LastName="Bar", Company="django-salesforce")
        lead.save()

        # Get a status name setting for converted Leads
        cur = connections['salesforce'].cursor()
        cur.execute("SELECT MasterLabel FROM LeadStatus WHERE IsConverted=true")
        converted_status = cur.fetchone()['MasterLabel']

        ret = convert_lead(lead, converted_status=converted_status)
        print("Response from convertLead: " +
                ', '.join('%s: %s' % (k, v) for k, v in sorted(ret.items())))
        expected_names = set(('accountId', 'contactId', 'leadId', 'opportunityId', 'success'))
        self.assertEqual(set(ret), expected_names)
        self.assertEqual(ret['success'], 'true')

        # Cleaning up...
        # Deleting the Account object will also delete the related Contact
        # and Opportunity objects.
        account = Account.objects.get(pk=ret['accountId'])
        account.delete()

        lead.delete()   # FYI, ret['leadId'] == lead.pk
 def test_lead_conversion(self):
     """
     Create a Lead object within Salesforce and try to
     convert it, convert/merge it with the information from a duplicit Lead,
     then clean all the generated objects.
     """
     lead = Lead(FirstName="Foo", LastName="Bar", Company="django-salesforce",
                 Street='Test Avenue 45')
     lead.save()
     lead2 = Lead(FirstName="Foo", LastName="Bar", Company="django-salesforce",
                  Phone='123456789')
     lead2.save()
     ret = None
     try:
         # convert the first Lead
         ret = convert_lead(lead, doNotCreateOpportunity=True)
         # print("Response from convertLead: " +
         #       ', '.join('%s: %s' % (k, v) for k, v in sorted(ret.items())))
         expected_names = set(('accountId', 'contactId', 'leadId', 'opportunityId', 'success'))
         self.assertEqual(set(ret), expected_names)
         self.assertEqual(ret['success'], 'true')
         # merge the new Account with the second Lead
         ret2 = convert_lead(lead2, doNotCreateOpportunity=True, accountId=ret['accountId'])
         account = Account.objects.get(pk=ret['accountId'])
         # verify that account is merged
         self.assertEqual(ret2['accountId'], account.pk)
         self.assertEqual(account.BillingStreet, 'Test Avenue 45')
         self.assertEqual(account.Phone, '123456789')
     finally:
         # Cleaning up...
         if ret:
             # Deleting the Account object will also delete the related Contact
             # and Opportunity objects.
             try:
                 account = Account.objects.get(pk=ret['accountId'])
             except Exception:  # pylint:disable=broad-except
                 # this allows to recycle the account even if the queryset code is broken
                 account = Account(pk=ret['accountId'])
                 account._state.db = lead._state.db
             account.delete()
         lead.delete()   # FYI, ret['leadId'] == lead.pk
         lead2.delete()
Example #4
0
    def test_lead_conversion(self):
        """
        Create a Lead object within Salesforce and try to
        convert it, then clean all the generated objects.
        """
        lead = Lead(FirstName="Foo", LastName="Bar", Company="django-salesforce")
        lead.save()
        r = convert_lead(lead)
        print("Response from convertLead: " + str(r))
        print("Account ID: " + str(r[0]))
        print("Contact ID: " + str(r[1]))
        print("Opportunity ID: " + str(r[3]))

        # Cleaning up...
        # Deleting the Account object will also delete the related Contact
        # and Opportunity objects.
        account = Account.objects.get(pk=str(r[0]))
        account.delete()
        
        lead.delete()   # FYI, r[2] == lead.pk
    def _convert_lead(self, lead):
        """
        Converts Lead to Contact and Account objects in Salesforce. Salesforce does not
        automatically populate custom fields on the Contact object with data from the
        Lead object, so we must do that here.
        """
        _ = convert_lead(lead, doNotCreateOpportunity=True)
        lead = Lead.objects.get(username=lead.username)

        contact = lead.converted_contact
        contact.language = lead.language
        contact.country = lead.country
        contact.year_of_birth = lead.year_of_birth
        contact.pi_utm_campaign = lead.pi_utm_campaign
        contact.pi_utm_content = lead.pi_utm_content
        contact.pi_utm_medium = lead.pi_utm_medium
        contact.pi_utm_source = lead.pi_utm_source
        contact.pi_utm_term = lead.pi_utm_term
        contact.save()

        return lead
Example #6
0
    def test_lead_conversion(self):
        """
        Create a Lead object within Salesforce and try to
        convert it, then clean all the generated objects.
        """
        lead = Lead(FirstName="Foo",
                    LastName="Bar",
                    Company="django-salesforce")
        lead.save()
        r = convert_lead(lead)
        print("Response from convertLead: " + str(r))
        print("Account ID: " + str(r[0]))
        print("Contact ID: " + str(r[1]))
        print("Opportunity ID: " + str(r[3]))

        # Cleaning up...
        # Deleting the Account object will also delete the related Contact
        # and Opportunity objects.
        account = Account.objects.get(pk=str(r[0]))
        account.delete()

        lead.delete()  # FYI, r[2] == lead.pk