|
7 | 7 | from datahub.core.queues.scheduler import LONG_RUNNING_QUEUE
|
8 | 8 | from datahub.interaction.models import Interaction
|
9 | 9 | from datahub.investment.project.models import InvestmentProject
|
| 10 | +from datahub.investment_lead.models import EYBLead |
10 | 11 | from datahub.omis.order.models import Order
|
11 | 12 |
|
12 | 13 |
|
|
15 | 16 |
|
16 | 17 | def relate_company_activity_to_interactions(batch_size=500):
|
17 | 18 | """
|
18 |
| - Grabs all interactions so they can be related to in the |
| 19 | + Grabs all interactions so they can be related to the |
19 | 20 | `CompanyActivity` model with bulk_create. Excludes any
|
20 | 21 | interactions already associated in the CompanyActivity model.
|
21 | 22 |
|
@@ -46,7 +47,7 @@ def relate_company_activity_to_interactions(batch_size=500):
|
46 | 47 |
|
47 | 48 | def relate_company_activity_to_referrals(batch_size=500):
|
48 | 49 | """
|
49 |
| - Grabs all referrals so they can be related to in the |
| 50 | + Grabs all referrals so they can be related to the |
50 | 51 | `CompanyActivity` model with a bulk_create. Excludes any
|
51 | 52 | referrals already associated in the CompanyActivity model.
|
52 | 53 |
|
@@ -76,7 +77,7 @@ def relate_company_activity_to_referrals(batch_size=500):
|
76 | 77 |
|
77 | 78 | def relate_company_activity_to_investment_projects(batch_size=500):
|
78 | 79 | """
|
79 |
| - Grabs all investment projects so they can be related to in the |
| 80 | + Grabs all investment projects so they can be related to the |
80 | 81 | `CompanyActivity` model with a bulk_create. Excludes any
|
81 | 82 | investment projects already associated in the CompanyActivity model.
|
82 | 83 | """
|
@@ -106,7 +107,7 @@ def relate_company_activity_to_investment_projects(batch_size=500):
|
106 | 107 |
|
107 | 108 | def relate_company_activity_to_orders(batch_size=500):
|
108 | 109 | """
|
109 |
| - Grabs all omis orders so they can be related to in the |
| 110 | + Grabs all omis orders so they can be related to the |
110 | 111 | `CompanyActivity` model with a bulk_create. Excludes any
|
111 | 112 | order projects already associated in the CompanyActivity model.
|
112 | 113 | """
|
@@ -136,7 +137,7 @@ def relate_company_activity_to_orders(batch_size=500):
|
136 | 137 |
|
137 | 138 | def relate_company_activity_to_great(batch_size=500):
|
138 | 139 | """
|
139 |
| - Grabs all great export enquiry so they can be related to in the |
| 140 | + Grabs all great export enquiry so they can be related to the |
140 | 141 | `CompanyActivity` model with a bulk_create. Excludes any
|
141 | 142 | great export enquiry already associated in the CompanyActivity model.
|
142 | 143 | """
|
@@ -164,6 +165,36 @@ def relate_company_activity_to_great(batch_size=500):
|
164 | 165 | bulk_create_activity(objs, batch_size)
|
165 | 166 |
|
166 | 167 |
|
| 168 | +def relate_company_activity_to_eyb_lead(batch_size=500): |
| 169 | + """ |
| 170 | + Grabs all EYB leads so they can be related to the |
| 171 | + `CompanyActivity` model with a bulk_create. Excludes any |
| 172 | + EYB leads already associated in the CompanyActivity model. |
| 173 | + """ |
| 174 | + activity = set( |
| 175 | + CompanyActivity.objects.filter( |
| 176 | + eyb_lead__isnull=False, |
| 177 | + ).values_list('eyb_lead', flat=True), |
| 178 | + ) |
| 179 | + |
| 180 | + eyb_leads = EYBLead.objects.filter( |
| 181 | + company__isnull=False, |
| 182 | + ).values('id', 'created_on', 'company_id') |
| 183 | + |
| 184 | + objs = [ |
| 185 | + CompanyActivity( |
| 186 | + eyb_lead_id=eyb_lead['id'], |
| 187 | + date=eyb_lead['created_on'], |
| 188 | + company_id=eyb_lead['company_id'], |
| 189 | + activity_source=CompanyActivity.ActivitySource.eyb_lead, |
| 190 | + ) |
| 191 | + for eyb_lead in eyb_leads |
| 192 | + if eyb_lead['id'] not in activity |
| 193 | + ] |
| 194 | + |
| 195 | + bulk_create_activity(objs, batch_size) |
| 196 | + |
| 197 | + |
167 | 198 | def schedule_sync_data_to_company_activity(relate_function):
|
168 | 199 | """
|
169 | 200 | Schedules a task for the given function.
|
|
0 commit comments