| 442 |
rajveer |
1 |
'''
|
|
|
2 |
Created on 13-Sep-2010
|
|
|
3 |
|
|
|
4 |
@author: rajveer
|
|
|
5 |
'''
|
|
|
6 |
|
|
|
7 |
from shop2020.logistics.service.impl import DataService
|
| 644 |
chandransh |
8 |
from shop2020.logistics.service.impl.DataService import Awb, AwbUpdate, Provider, \
|
|
|
9 |
DeliveryEstimate, WarehouseAllocation
|
| 483 |
rajveer |
10 |
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException
|
| 442 |
rajveer |
11 |
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
|
|
|
12 |
from elixir import session
|
|
|
13 |
import datetime
|
|
|
14 |
|
|
|
15 |
def initialize():
|
|
|
16 |
log_entry("initialize@DataAccessor", "Initializing data service")
|
|
|
17 |
DataService.initialize()
|
|
|
18 |
|
| 644 |
chandransh |
19 |
def get_provider(provider_id):
|
|
|
20 |
return Provider.get_by(id=provider_id)
|
|
|
21 |
|
|
|
22 |
def get_providers():
|
|
|
23 |
return Provider.query.all()
|
|
|
24 |
|
|
|
25 |
def get_logistics_estimation(destination_pin):
|
| 483 |
rajveer |
26 |
try:
|
| 644 |
chandransh |
27 |
warehouse_location = WarehouseAllocation.get_by(pincode = destination_pin).primary_warehouse_location
|
| 483 |
rajveer |
28 |
except:
|
| 644 |
chandransh |
29 |
raise LogisticsServiceException(101, "No Warehouse assigned to this pincode.")
|
| 483 |
rajveer |
30 |
|
| 644 |
chandransh |
31 |
query = DeliveryEstimate.query.filter_by(warehouse_location = warehouse_location)
|
|
|
32 |
query = query.filter_by(destination_pin = destination_pin)
|
|
|
33 |
query = query.order_by(DeliveryEstimate.delivery_time)
|
|
|
34 |
try:
|
|
|
35 |
return query.first()
|
| 483 |
rajveer |
36 |
except:
|
| 644 |
chandransh |
37 |
raise LogisticsServiceException(103, "No Logistics partner listed for this destination pincode and the primary warehouse")
|
| 483 |
rajveer |
38 |
|
| 644 |
chandransh |
39 |
def add_empty_AWBs(numbers, provider_id, type):
|
| 442 |
rajveer |
40 |
for number in numbers:
|
| 644 |
chandransh |
41 |
query = Awb.query.filter_by(awb_number = number, provider_id = provider_id)
|
| 444 |
rajveer |
42 |
try:
|
|
|
43 |
query.one()
|
|
|
44 |
except:
|
| 644 |
chandransh |
45 |
awb = Awb()
|
| 444 |
rajveer |
46 |
awb.awb_number = number
|
| 644 |
chandransh |
47 |
awb.provider_id = provider_id
|
| 444 |
rajveer |
48 |
awb.is_available = True
|
| 644 |
chandransh |
49 |
awb.type = type
|
|
|
50 |
session.commit()
|
| 442 |
rajveer |
51 |
|
| 444 |
rajveer |
52 |
def set_AWB_as_used(awb_number):
|
| 644 |
chandransh |
53 |
query = Awb.query.filter_by(awb_number = awb_number)
|
| 444 |
rajveer |
54 |
awb = query.one()
|
|
|
55 |
awb.is_available=False
|
|
|
56 |
session.commit()
|
|
|
57 |
|
| 442 |
rajveer |
58 |
def get_empty_AWB(provider_id):
|
| 644 |
chandransh |
59 |
query = Awb.query.filter_by(provider_id = provider_id, is_available = True) #check the provider thing
|
| 442 |
rajveer |
60 |
try:
|
| 644 |
chandransh |
61 |
awb = query.first()
|
|
|
62 |
awb.is_available = False
|
|
|
63 |
session.commit()
|
| 444 |
rajveer |
64 |
return awb.awb_number
|
| 442 |
rajveer |
65 |
except:
|
| 644 |
chandransh |
66 |
raise LogisticsServiceException(103, "Unable to get an AWB for the given Provider: " + str(provider_id))
|
| 442 |
rajveer |
67 |
|
| 644 |
chandransh |
68 |
def get_shipment_info(awb_number, provider_id):
|
|
|
69 |
awb = Awb.get_by(awb_number = awb_number, provider_id = provider_id)
|
|
|
70 |
query = AwbUpdate.query.filter_by(awb = awb)
|
|
|
71 |
return query.all()
|