Subversion Repositories SmartDukaan

Rev

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

Rev 1248 Rev 1504
Line 4... Line 4...
4
@author: rajveer
4
@author: rajveer
5
'''
5
'''
6
 
6
 
7
from shop2020.logistics.service.impl import DataService
7
from shop2020.logistics.service.impl import DataService
8
from shop2020.logistics.service.impl.DataService import Awb, AwbUpdate, Provider, \
8
from shop2020.logistics.service.impl.DataService import Awb, AwbUpdate, Provider, \
9
     DeliveryEstimate, WarehouseAllocation
9
     DeliveryEstimate, WarehouseAllocation, DestinationProviderAllocation
10
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException
10
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException
11
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
11
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
12
from elixir import session
12
from elixir import session
13
import datetime
13
import datetime
-
 
14
import sys
14
 
15
 
15
def initialize(dbname="logistics"):
16
def initialize(dbname="logistics"):
16
    log_entry("initialize@DataAccessor", "Initializing data service")
17
    log_entry("initialize@DataAccessor", "Initializing data service")
17
    DataService.initialize(dbname)
18
    DataService.initialize(dbname)
18
 
19
 
Line 22... Line 23...
22
 
23
 
23
def get_providers():
24
def get_providers():
24
    providers = Provider.query.all()
25
    providers = Provider.query.all()
25
    return providers 
26
    return providers 
26
 
27
 
27
def get_logistics_estimation(destination_pin):
28
def get_logistics_estimation(destination_pin, item_selling_price):
28
    try:
29
    try:
29
        warehouse_location = WarehouseAllocation.get_by(pincode = destination_pin).primary_warehouse_location
30
        warehouse_location = WarehouseAllocation.get_by(pincode = destination_pin).primary_warehouse_location
30
    except:
31
    except:
-
 
32
        print "Unexpected error:", sys.exc_info()[0]
31
        raise LogisticsServiceException(101, "No Warehouse assigned to this pincode: " + destination_pin)
33
        raise LogisticsServiceException(101, "No Warehouse assigned to this pincode: " + destination_pin)
-
 
34
    
-
 
35
    query_provider = DestinationProviderAllocation.query.filter_by(destination_pin = destination_pin)
-
 
36
    query_provider = query_provider.filter_by(warehouse_location = warehouse_location)
32
        
37
    try:
-
 
38
        if (item_selling_price <= 5000):
-
 
39
            provider = query_provider.one().provider_less_amount
-
 
40
        else:
-
 
41
            provider = query_provider.one().provider_more_amount
-
 
42
    except Exception as ex:
-
 
43
        print ex
-
 
44
        print "Unexpected error:", sys.exc_info()[0]
-
 
45
        raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin) + \
-
 
46
                                        ", and warehouse location: " + str(warehouse_location))
-
 
47
    
33
    query = DeliveryEstimate.query.filter_by(warehouse_location = warehouse_location)
48
    query = DeliveryEstimate.query.filter_by(warehouse_location = warehouse_location)
34
    query = query.filter_by(destination_pin = destination_pin)
49
    query = query.filter_by(destination_pin = destination_pin)
35
    query = query.order_by(DeliveryEstimate.delivery_time)
50
    query = query.filter_by(provider = provider)
36
    try:
51
    try:
37
        return query.first()
52
        return query.first()
-
 
53
    except Exception as ex:
38
    except:
54
        print ex
39
        raise LogisticsServiceException(103, "No Logistics partner listed for this destination pincode and the primary warehouse")
55
        raise LogisticsServiceException(103, "No Logistics partner listed for this destination pincode and the primary warehouse")
40
        
56
        
41
def add_empty_AWBs(numbers, provider_id, type):
57
def add_empty_AWBs(numbers, provider_id, type):
42
    for number in numbers:
58
    for number in numbers:
43
        query = Awb.query.filter_by(awb_number = number, provider_id = provider_id)
59
        query = Awb.query.filter_by(awb_number = number, provider_id = provider_id)