Skip to content

Commit

Permalink
use custom object for thank you note
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvolo committed Jan 7, 2025
1 parent 42cfd4d commit 28a06cb
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions salesforce/management/commands/sync_thank_you_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from salesforce.models import School
from donations.models import ThankYouNote
from salesforce.salesforce import Salesforce
from rapidfuzz import process, fuzz
from rapidfuzz import process, fuzz, utils


class Command(BaseCommand):
Expand All @@ -20,17 +20,28 @@ def handle(self, *args, **options):

for note in new_thank_you_notes:
if note.institution:
best_match, score, _ = process.extractOne(note.institution, school_list.keys(), scorer=fuzz.WRatio)
best_match, score, _ = process.extractOne(note.institution, school_list.keys(), scorer=fuzz.WRatio, processor=utils.default_process)

if score > 80:
account_id = school_list["Find Me A Home"]
if score > 90: # found a good match on school name, use that to populate related school in SF
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}\nSource: {note.source}\n\n{note.thank_you_note}",
'ParentId': account_id})

note.salesforce_id = response['id']
note.save()
num_created += 1
response = sf.Thank_You_Note__c.create(
{'Name': f"{note.first_name} {note.last_name} - {note.created}",
'Message__c': note.thank_you_note,
'First_Name__c': note.first_name,
'Last_Name__c': note.last_name,
'Email_Address__c': note.contact_email_address,
'Institution__c': note.institution,
'Source__c': note.source,
'Consent_to_Share__c': note.consent_to_share_or_contact,
'Submitted_Date__c': note.created.strftime('%Y-%m-%d'),
'Related_Account__c': account_id
}
)

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

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

0 comments on commit 28a06cb

Please sign in to comment.