diff --git a/salesforce/management/commands/update_opportunities.py b/salesforce/management/commands/update_opportunities.py index 60c6971e..3fa0a69c 100644 --- a/salesforce/management/commands/update_opportunities.py +++ b/salesforce/management/commands/update_opportunities.py @@ -41,15 +41,15 @@ def handle(self, *args, **options): "AND Opportunity__r.Contact__r.Adoption_Status__c != 'Current Adopter'").format(base_year) # This generally returns more than 2,000 records (the SF limit) - # See simplate_salesforce documentation for query_all: https://github.com/simple-salesforce/simple-salesforce?tab=readme-ov-file#queries - response = sf.query_all(query) - records = response['records'] + # See simplate_salesforce documentation for query_all: https://github.com/simple-salesforce/simple-salesforce?tab=readme-ov-file#using-bulk + results = sf.bulk.Adoption__c.query(query) # TODO: this doesn't need to be updating on the opp id, the info never changes - for record in records: + for i, record in enumerate(results): opportunity, created = AdoptionOpportunityRecord.objects.update_or_create( - opportunity_id=record['Id'], - defaults={'account_uuid': uuid.UUID(record['Opportunity__r']['Contact__r']['Accounts_UUID__c']), + account_uuid=uuid.UUID(record['Opportunity__r']['Contact__r']['Accounts_UUID__c']), + book_name=record['Opportunity__r']['Book__r']['Name'], + defaults={'opportunity_id': record['Id'], 'opportunity_stage': record['Opportunity__r']['StageName'], 'adoption_type': record['Adoption_Type__c'], 'base_year': record['Base_Year__c'], @@ -57,8 +57,7 @@ def handle(self, *args, **options): 'confirmation_type': record['Confirmation_Type__c'], 'how_using': record['How_Using__c'], 'savings': record['Savings__c'], - 'students': record['Students__c'], - 'book_name': record['Opportunity__r']['Book__r']['Name'], + 'students': record['Students__c'] } ) opportunity.save()