-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add management command to upload thank you notes * fix school sync * parentId is required * use custom object for thank you note * remove debug print statements * higher confidence, add cron * fix processor call * school admin layout and filters * error handling * add opp id to update (prevent IntegreityError) * remove unused imports/calls in mapbox MC * formatting * remove approx enrollment * use SF native lat/long fields * use bulk query (to get all records) + create/mod dates * remove unneeded comment
- Loading branch information
Showing
12 changed files
with
135 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 5.1.1 on 2025-01-06 23:16 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("donations", "0008_thankyounote_source"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="thankyounote", | ||
name="salesforce_id", | ||
field=models.CharField( | ||
blank=True, default="", help_text="Not null if uploaded to Salesforce", max_length=255 | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from django.core.management.base import BaseCommand | ||
from salesforce.models import School | ||
from donations.models import ThankYouNote | ||
from salesforce.salesforce import Salesforce | ||
from rapidfuzz import process, fuzz, utils | ||
|
||
|
||
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="") | ||
|
||
# fetch schools to do a fuzzy match on with thank you note manually inputted names | ||
school_list = {school.name: school.salesforce_id for school in School.objects.all()} | ||
|
||
with Salesforce() as sf: | ||
num_created = 0 | ||
for note in new_thank_you_notes: | ||
account_id = school_list["Find Me A Home"] | ||
|
||
# If note has a school name, see if we can match it and use that account id when creating | ||
if note.institution: | ||
school_string = note.institution | ||
filtered_choices = [name for name in school_list.keys() if name.lower().startswith(school_string.lower())] | ||
if filtered_choices: | ||
best_match, score, match_key = process.extractOne(school_string, filtered_choices, scorer=fuzz.partial_ratio, processor=utils.default_process) | ||
|
||
if score > 99: # found a good match on school name, use that to populate related school in SF | ||
account_id = school_list[best_match] | ||
|
||
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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
salesforce/migrations/0113_school_created_school_updated.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 5.1.1 on 2025-01-08 20:09 | ||
|
||
import django.utils.timezone | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("salesforce", "0112_remove_adoptionopportunityrecord_fall_student_number_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="school", | ||
name="created", | ||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name="school", | ||
name="updated", | ||
field=models.DateTimeField(auto_now=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters