Add better kurjerzy error reporting
parent
f8454892b3
commit
e5aa270391
|
@ -92,7 +92,7 @@ class FaceshieldRequestAdmin(ModelView):
|
|||
|
||||
form_overrides = {'entity_info': TextAreaField, 'extra': TextAreaField, 'remarks': TextAreaField}
|
||||
form_args = {
|
||||
'shipping_name': {'validators': [validators.Length(max=30)]},
|
||||
'shipping_name': {'validators': [validators.Length(max=35)]},
|
||||
}
|
||||
|
||||
form_excluded_columns = ('changelog', 'postalcode_info')
|
||||
|
@ -324,11 +324,22 @@ class FaceshieldRequestAdmin(ModelView):
|
|||
k = Kurjerzy(current_app)
|
||||
k.authenticate()
|
||||
|
||||
created = 0
|
||||
for model in models:
|
||||
k.create_shipment(model)
|
||||
db.session.commit()
|
||||
try:
|
||||
if model.shipping_id is not None or model.shipping_provider is not None:
|
||||
if k.shipment_info(model.shipping_id):
|
||||
flash('Ignoring #%s (shipment already created)' % (model.id,), 'warning')
|
||||
continue
|
||||
k.create_shipment(model)
|
||||
db.session.commit()
|
||||
created += 1
|
||||
except Exception as exc:
|
||||
flash('Shipment creation failed for #%s: %s' % (model.id, exc), 'error')
|
||||
return
|
||||
|
||||
flash('Shipments created')
|
||||
if created:
|
||||
flash('%d shipments created' % (created,), 'info')
|
||||
|
||||
class FilteredFaceshieldRequestAdmin(FaceshieldRequestAdmin):
|
||||
def get_query(self):
|
||||
|
|
|
@ -56,6 +56,9 @@ class Kurjerzy:
|
|||
return resp['data']['createToken']
|
||||
|
||||
def create_shipment(self, model):
|
||||
if not model.shipping_street:
|
||||
raise Exception('Invalid shipping_street')
|
||||
|
||||
street, _, street_number = model.shipping_street.rpartition(' ')
|
||||
if not street:
|
||||
street = street_number
|
||||
|
@ -133,7 +136,7 @@ class Kurjerzy:
|
|||
print('fetching shipment_info(%r)' % (id,))
|
||||
return self.send_query(r'query($id: Int) { shipments(ids:[$id]) { id, labelRef, labelSource, status, tracking { statuses } } }', {
|
||||
'id': id,
|
||||
})
|
||||
})['data']['shipments']
|
||||
|
||||
if __name__ == '__main__':
|
||||
k = Kurjerzy({})
|
||||
|
|
Loading…
Reference in New Issue