Skip to content

Commit

Permalink
parentId is required
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvolo committed Jan 6, 2025
1 parent 8cc6924 commit 42cfd4d
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions salesforce/management/commands/sync_thank_you_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Command(BaseCommand):
help = "update thank you note records with SF"

def handle(self, *args, **options):
new_thank_you_notes = ThankYouNote.objects.filter(salesforce_id__isnull=True)
new_thank_you_notes = ThankYouNote.objects.filter(salesforce_id="")
print(new_thank_you_notes)

with Salesforce() as sf:
# fetch schools to do a fuzzy match on with thank you note manually inputted names
Expand All @@ -21,23 +22,15 @@ def handle(self, *args, **options):
if note.institution:
best_match, score, _ = process.extractOne(note.institution, school_list.keys(), scorer=fuzz.WRatio)

if score < 80:
# TODO: log this somewhere better or just ignore it
self.stdout.write(self.style.WARNING("No good match for {} (highest match score: {}/{})".format(note.institution, best_match, score)))

if score > 80:
account_id = school_list[best_match]

response = sf.Note.create({'Title': f"{note.created} | {note.first_name} {note.last_name} | {note.contact_email_address} | {note.institution}",
'Body': f"Consent to share/be contacted? {note.consent_to_share_or_contact}\n\n{note.thank_you_note}",
'Body': f"Consent to share/be contacted? {note.consent_to_share_or_contact}\nSource: {note.source}\n\n{note.thank_you_note}",
'ParentId': account_id})

else: # can't find a school match, just upload as a general note
response = sf.Note.create({'Title': f"{note.created} | {note.first_name} {note.last_name} | {note.contact_email_address} | {note.institution}",
'Body': f"Consent to share/be contacted? {note.consent_to_share_or_contact}\n\n{note.thank_you_note}"})

note.salesforce_id = response['id']
note.save()
num_created += 1
note.salesforce_id = response['id']
note.save()
num_created += 1

response = self.style.SUCCESS("{} Salesforce Notes Created.".format(num_created))
self.stdout.write(response)
self.stdout.write(self.style.SUCCESS("{} Salesforce Notes Created.".format(num_created)))

0 comments on commit 42cfd4d

Please sign in to comment.