| Line 5... |
Line 5... |
| 5 |
'''
|
5 |
'''
|
| 6 |
|
6 |
|
| 7 |
from elixir import session
|
7 |
from elixir import session
|
| 8 |
from shop2020.clients.CatalogClient import CatalogClient
|
8 |
from shop2020.clients.CatalogClient import CatalogClient
|
| 9 |
from shop2020.clients.InventoryClient import InventoryClient
|
9 |
from shop2020.clients.InventoryClient import InventoryClient
|
| - |
|
10 |
from shop2020.clients.TransactionClient import TransactionClient
|
| 10 |
from shop2020.logistics.service.impl import DataService
|
11 |
from shop2020.logistics.service.impl import DataService
|
| - |
|
12 |
from shop2020.logistics.service.impl import BluedartService
|
| 11 |
from shop2020.logistics.service.impl.DataService import Awb, AwbUpdate, Provider, \
|
13 |
from shop2020.logistics.service.impl.DataService import Awb, AwbUpdate, Provider, \
|
| 12 |
DeliveryEstimate, WarehouseAllocation, PublicHolidays, \
|
14 |
DeliveryEstimate, WarehouseAllocation, PublicHolidays, \
|
| 13 |
ServiceableLocationDetails, PickupStore, Locations, ProviderCosting
|
15 |
ServiceableLocationDetails, PickupStore, Locations, ProviderCosting
|
| 14 |
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException, \
|
16 |
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException, \
|
| 15 |
DeliveryType, LogisticsLocationInfo, LocationInfo, ProviderInfo, DeliveryEstimateAndCosting
|
17 |
DeliveryType, LogisticsLocationInfo, LocationInfo, ProviderInfo, DeliveryEstimateAndCosting
|
| Line 22... |
Line 24... |
| 22 |
import os
|
24 |
import os
|
| 23 |
import sys
|
25 |
import sys
|
| 24 |
import time
|
26 |
import time
|
| 25 |
from collections import namedtuple
|
27 |
from collections import namedtuple
|
| 26 |
import math
|
28 |
import math
|
| - |
|
29 |
import traceback
|
| 27 |
|
30 |
|
| 28 |
logging.basicConfig(level=logging.DEBUG)
|
31 |
logging.basicConfig(level=logging.DEBUG)
|
| 29 |
|
32 |
|
| 30 |
PincodeProvider = namedtuple("PincodeProvider", ["dest_pin", "provider"])
|
33 |
PincodeProvider = namedtuple("PincodeProvider", ["dest_pin", "provider"])
|
| 31 |
|
34 |
|
| Line 355... |
Line 358... |
| 355 |
query = Awb.query.filter_by(awb_number = awb_number)
|
358 |
query = Awb.query.filter_by(awb_number = awb_number)
|
| 356 |
awb = query.one()
|
359 |
awb = query.one()
|
| 357 |
awb.is_available=False
|
360 |
awb.is_available=False
|
| 358 |
session.commit()
|
361 |
session.commit()
|
| 359 |
|
362 |
|
| 360 |
def get_empty_AWB(provider_id, type = DeliveryType.PREPAID):
|
363 |
#def get_empty_AWB(provider_id, logisticsTransactionId):
|
| 361 |
query = Awb.query.with_lockmode("update").filter_by(provider_id = provider_id, is_available = True) #check the provider thing
|
364 |
# query = Awb.query.with_lockmode("update").filter_by(provider_id = provider_id, is_available = True) #check the provider thing
|
| 362 |
if type == DeliveryType.PREPAID:
|
365 |
# if type == DeliveryType.PREPAID:
|
| 363 |
query = query.filter_by(type="Prepaid")
|
366 |
# query = query.filter_by(type="Prepaid")
|
| 364 |
if type == DeliveryType.COD:
|
367 |
# if type == DeliveryType.COD:
|
| 365 |
query = query.filter_by(type="COD")
|
368 |
# query = query.filter_by(type="COD")
|
| 366 |
|
369 |
#
|
| 367 |
additionalQuery = query
|
370 |
# additionalQuery = query
|
| 368 |
query = query.filter_by(awbUsedFor=0)
|
371 |
# query = query.filter_by(awbUsedFor=0)
|
| 369 |
|
372 |
#
|
| - |
|
373 |
# try:
|
| - |
|
374 |
# awb = query.first()
|
| - |
|
375 |
# if awb is None:
|
| - |
|
376 |
# additionalQuery = additionalQuery.filter_by(awbUsedFor=2)
|
| - |
|
377 |
# awb = additionalQuery.first()
|
| - |
|
378 |
# awb.is_available = False
|
| - |
|
379 |
# session.commit()
|
| - |
|
380 |
# return awb.awb_number
|
| - |
|
381 |
# except:
|
| - |
|
382 |
# raise LogisticsServiceException(103, "Unable to get an AWB for the given Provider: " + str(provider_id))
|
| - |
|
383 |
|
| - |
|
384 |
def get_empty_AWB(provider_id, logisticsTransactionId):
|
| 370 |
try:
|
385 |
try:
|
| 371 |
awb = query.first()
|
386 |
if logisticsTransactionId is None:
|
| 372 |
if awb is None:
|
387 |
return ""
|
| 373 |
additionalQuery = additionalQuery.filter_by(awbUsedFor=2)
|
388 |
if provider_id ==1:
|
| 374 |
awb = additionalQuery.first()
|
389 |
client = TransactionClient().get_client()
|
| 375 |
awb.is_available = False
|
- |
|
| 376 |
session.commit()
|
390 |
orders_list = client.getGroupOrdersByLogisticsTxnId(logisticsTransactionId)
|
| 377 |
return awb.awb_number
|
391 |
return BluedartService.generate_awb(orders_list)
|
| 378 |
except:
|
392 |
except:
|
| - |
|
393 |
traceback.print_exc()
|
| 379 |
raise LogisticsServiceException(103, "Unable to get an AWB for the given Provider: " + str(provider_id))
|
394 |
raise LogisticsServiceException(103, "Unable to get an AWB for the given Provider: " + str(provider_id))
|
| - |
|
395 |
|
| 380 |
|
396 |
|
| 381 |
def get_free_awb_count(provider_id, type):
|
397 |
def get_free_awb_count(provider_id, type):
|
| 382 |
count = Awb.query.filter_by(provider_id = provider_id, is_available = True, type=type).count()
|
398 |
count = Awb.query.filter_by(provider_id = provider_id, is_available = True, type=type).count()
|
| 383 |
if count == None:
|
399 |
if count == None:
|
| 384 |
count = 0
|
400 |
count = 0
|