From 42cfd4d5f67a6c43b707b7eff8569d554c6778bb Mon Sep 17 00:00:00 2001 From: Michael Volo Date: Mon, 6 Jan 2025 17:35:03 -0600 Subject: [PATCH] parentId is required --- .../commands/sync_thank_you_notes.py | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/salesforce/management/commands/sync_thank_you_notes.py b/salesforce/management/commands/sync_thank_you_notes.py index 59bddc27..65af478c 100644 --- a/salesforce/management/commands/sync_thank_you_notes.py +++ b/salesforce/management/commands/sync_thank_you_notes.py @@ -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 @@ -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)))