@@ -97,94 +97,70 @@ def process_pending_fulfillment(self, ftp_id):
97
97
)
98
98
row = cur .fetchone ()
99
99
if row is not None :
100
- if self ._is_subscription (row ):
101
- subscription_id = \
102
- self ._create_subscription (row ['email' ],
103
- row ['transaction_id' ],
104
- row ['ftp_id' ])
105
- else :
106
- subscription_id = None
107
-
108
- # If there are any FFQs attached to the perk, immediately
109
- # fulfill the first one
110
- if row ['ffq_quantity' ] > 0 :
111
- # If the perk is a kit or subscription, send thank you
112
- # email with kit content. Otherwise, send thank you
113
- # for FFQ only
114
- if row ['kit_quantity' ] > 0 :
115
- template = "thank_you_with_kit"
100
+ for perk_qty in range (row ['quantity' ]):
101
+ if self ._is_subscription (row ):
102
+ subscription_id = \
103
+ self ._create_subscription (row ['email' ],
104
+ row ['transaction_id' ],
105
+ row ['ftp_id' ])
116
106
else :
117
- template = "thank_you_no_kit"
118
-
119
- error_info = self ._fulfill_ffq (
120
- row ['ftp_id' ],
121
- template ,
122
- row ['email' ],
123
- row ['first_name' ],
124
- subscription_id
125
- )
126
- if error_info is not None :
127
- error_report .append (
128
- f"Error sending FFQ email for ftp_id "
129
- f"{ row ['ftp_id' ]} : { error_info } "
130
- )
107
+ subscription_id = None
108
+
109
+ # If there are any FFQs attached to the perk, immediately
110
+ # fulfill the first one
111
+ if row ['ffq_quantity' ] > 0 :
112
+ # If the perk is a kit or subscription, send thank you
113
+ # email with kit content. Otherwise, send thank you
114
+ # for FFQ only
115
+ if row ['kit_quantity' ] > 0 :
116
+ template = "thank_you_with_kit"
117
+ else :
118
+ template = "thank_you_no_kit"
131
119
132
- # Then, if there are more FFQs, schedule/fulfill them as
133
- # appropriate based on fulfillment_spacing_number
134
- for x in range (1 , row ['ffq_quantity' ]):
135
- if row ['fulfillment_spacing_number' ] > 0 :
136
- fulfillment_date = \
137
- self ._future_fulfillment_date (
138
- row ['fulfillment_spacing_number' ],
139
- row ['fulfillment_spacing_unit' ],
140
- x
141
- )
142
- self ._schedule_ffq (
143
- subscription_id ,
144
- fulfillment_date ,
145
- False
146
- )
147
- else :
148
120
error_info = self ._fulfill_ffq (
149
121
row ['ftp_id' ],
150
- row [ 'kit_quantity' ] ,
122
+ template ,
151
123
row ['email' ],
152
- row ['first_name' ]
124
+ row ['first_name' ],
125
+ subscription_id
153
126
)
154
127
if error_info is not None :
155
128
error_report .append (
156
129
f"Error sending FFQ email for ftp_id "
157
130
f"{ row ['ftp_id' ]} : { error_info } "
158
131
)
159
132
160
- # If there are any kits attached to the perk, immediately
161
- # fulfill the first one
162
- if row ['kit_quantity' ] > 0 :
163
- status , return_val = self ._fulfill_kit (
164
- row ,
165
- 1 ,
166
- subscription_id
167
- )
168
- if not status :
169
- # Daklapack order failed, let the error percolate
170
- error_report .append (
171
- f"Error placing Daklapack order for ftp_id "
172
- f"{ row ['ftp_id' ]} : { return_val } "
173
- )
174
-
175
- for x in range (1 , row ['kit_quantity' ]):
176
- if row ['fulfillment_spacing_number' ] > 0 :
177
- fulfillment_date = \
178
- self ._future_fulfillment_date (
179
- row ['fulfillment_spacing_number' ],
180
- row ['fulfillment_spacing_unit' ],
181
- x
133
+ # Then, if there are more FFQs, schedule/fulfill them as
134
+ # appropriate based on fulfillment_spacing_number
135
+ for x in range (1 , row ['ffq_quantity' ]):
136
+ if row ['fulfillment_spacing_number' ] > 0 :
137
+ fulfillment_date = \
138
+ self ._future_fulfillment_date (
139
+ row ['fulfillment_spacing_number' ],
140
+ row ['fulfillment_spacing_unit' ],
141
+ x
142
+ )
143
+ self ._schedule_ffq (
144
+ subscription_id ,
145
+ fulfillment_date ,
146
+ fulfilled = False
182
147
)
183
- self ._schedule_kit (subscription_id ,
184
- fulfillment_date ,
185
- row ['dak_article_code' ],
186
- False )
187
- else :
148
+ else :
149
+ error_info = self ._fulfill_ffq (
150
+ row ['ftp_id' ],
151
+ row ['kit_quantity' ],
152
+ row ['email' ],
153
+ row ['first_name' ]
154
+ )
155
+ if error_info is not None :
156
+ error_report .append (
157
+ f"Error sending FFQ email for ftp_id "
158
+ f"{ row ['ftp_id' ]} : { error_info } "
159
+ )
160
+
161
+ # If there are any kits attached to the perk, immediately
162
+ # fulfill the first one
163
+ if row ['kit_quantity' ] > 0 :
188
164
status , return_val = self ._fulfill_kit (
189
165
row ,
190
166
1 ,
@@ -197,6 +173,34 @@ def process_pending_fulfillment(self, ftp_id):
197
173
f"{ row ['ftp_id' ]} : { return_val } "
198
174
)
199
175
176
+ for x in range (1 , row ['kit_quantity' ]):
177
+ if row ['fulfillment_spacing_number' ] > 0 :
178
+ fulfillment_date = \
179
+ self ._future_fulfillment_date (
180
+ row ['fulfillment_spacing_number' ],
181
+ row ['fulfillment_spacing_unit' ],
182
+ x
183
+ )
184
+ self ._schedule_kit (subscription_id ,
185
+ fulfillment_date ,
186
+ row ['dak_article_code' ],
187
+ fulfilled = False )
188
+ else :
189
+ # We hard-code a quantity of 1 here because
190
+ # the actual quantity is controlled by
191
+ # row['quantity'] and row['kit_quantity'].
192
+ status , return_val = self ._fulfill_kit (
193
+ row ,
194
+ 1 ,
195
+ subscription_id
196
+ )
197
+ if not status :
198
+ # Dak order failed, let the error percolate
199
+ error_report .append (
200
+ f"Error placing Daklapack order for "
201
+ f"ftp_id { row ['ftp_id' ]} : { return_val } "
202
+ )
203
+
200
204
cur .execute (
201
205
"UPDATE campaign.fundrazr_transaction_perk "
202
206
"SET processed = true "
0 commit comments