Subversion Repositories SmartDukaan

Rev

Rev 23135 | Rev 23218 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23135 Rev 23140
Line 404... Line 404...
404
    
404
    
405
    additionalQuery = query
405
    additionalQuery = query
406
    query = query.filter_by(awbUsedFor=0)
406
    query = query.filter_by(awbUsedFor=0)
407
    
407
    
408
    try:
408
    try:
-
 
409
        success = True
409
        awb = query.first()
410
        awb = query.first()
410
        if awb is None:
411
        if awb is None:
411
            additionalQuery = additionalQuery.filter_by(awbUsedFor=2)
412
            additionalQuery = additionalQuery.filter_by(awbUsedFor=2)
412
            awb = additionalQuery.first()
413
            awb = additionalQuery.first()
413
        print "-------", awb.awb_number, awb.is_available
414
        print "-------", awb.awb_number, awb.is_available
414
        awb.is_available = False
415
        awb.is_available = False
415
        if provider_id==49:
416
        if provider_id==49:
416
            success = EcomExpressService.forward_request(awb.awb_number, logisticsTransactionId)
417
            success = EcomExpressService.forward_request(awb.awb_number, logisticsTransactionId)
417
            if not success:
-
 
418
                raise LogisticsServiceException(103, "Unable to forward shipment for the given Provider: " + str(provider_id))
-
 
419
        #Commit only if everything works fine
418
        #Commit only if everything works fine
-
 
419
        if success:
420
        session.commit()
420
            session.commit()
421
        return awb.awb_number
421
            return awb.awb_number
-
 
422
        else:
-
 
423
            raise 
422
    except:
424
    except:
-
 
425
        traceback.print_exc()
423
        session.close()
426
        session.close()
424
        print "oops"
-
 
425
        #In case of missing awb for EComExpress fetch new awbs using their api
-
 
426
        if provider_id==49:
-
 
427
            awbs = EcomExpressService.generate_awb(type)
-
 
428
            #add_new_awbs(provider_id, isCod, awbs, awbUsedFor)
-
 
429
            add_empty_AWBs(awbs, provider_id, DeliveryType._VALUES_TO_NAMES[type])
-
 
430
            return get_awb(provider_id, logisticsTransactionId, type)
-
 
431
        return
-
 
432
            
-
 
433
            
-
 
434
        raise LogisticsServiceException(103, "Unable to get an AWB for the given Provider: " + str(provider_id))
427
        raise LogisticsServiceException(103, "Unable to get an AWB for the given Provider: " + str(provider_id))
435
 
428
 
436
def get_empty_AWB(provider_id, logisticsTransactionId):
429
def get_empty_AWB(provider_id, logisticsTransactionId):
437
    try:
430
    try:
438
        if logisticsTransactionId is None:
431
        if logisticsTransactionId is None: