Subversion Repositories SmartDukaan

Rev

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

Rev 3044 Rev 3064
Line 5... Line 5...
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, DestinationProviderAllocation,\
9
     DeliveryEstimate, WarehouseAllocation, DestinationProviderAllocation,\
10
    PublicHolidays
10
    PublicHolidays, ServiceableLocationDetails
11
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException,\
11
from shop2020.thriftpy.logistics.ttypes import LogisticsServiceException,\
12
    DeliveryType
12
    DeliveryType
13
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
13
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
14
from elixir import session
14
from elixir import session
15
import datetime, time
15
import datetime, time
Line 25... Line 25...
25
 
25
 
26
def get_providers():
26
def get_providers():
27
    providers = Provider.query.all()
27
    providers = Provider.query.all()
28
    return providers 
28
    return providers 
29
 
29
 
-
 
30
def is_cod_allowed(destination_pin):
-
 
31
    try:
-
 
32
        sld = ServiceableLocationDetails.get_by(dest_pincode = destination_pin, cod = True)
-
 
33
    except Exception as ex:
-
 
34
        print "Unexpected error:", sys.exc_info()[0]
-
 
35
    
-
 
36
    if sld:
-
 
37
        return True
-
 
38
    else:
-
 
39
        return False
-
 
40
    
-
 
41
 
30
def get_logistics_estimation(destination_pin, item_selling_price, warehouse_location=None):
42
def get_logistics_estimation(destination_pin, item_selling_price, warehouse_location=None, type=DeliveryType.PREPAID):
31
    if warehouse_location is None:
43
    if warehouse_location is None:
32
        try:
44
        try:
33
            warehouse_location = WarehouseAllocation.get_by(pincode = destination_pin).primary_warehouse_location
45
            warehouse_location = WarehouseAllocation.get_by(pincode = destination_pin).primary_warehouse_location
34
        except:
46
        except:
35
            print "Unexpected error:", sys.exc_info()[0]
47
            print "Unexpected error:", sys.exc_info()[0]
36
            raise LogisticsServiceException(101, "No Warehouse assigned to this pincode: " + destination_pin)
48
            raise LogisticsServiceException(101, "No Warehouse locations assigned to this pincode: " + destination_pin)
37
    
49
    
38
    query_provider = DestinationProviderAllocation.query.filter_by(destination_pin = destination_pin)
-
 
39
    query_provider = query_provider.filter_by(warehouse_location = warehouse_location)
-
 
40
    try:
50
    try:
-
 
51
        sld = ServiceableLocationDetails.get_by(dest_pincode = destination_pin)
41
        if (item_selling_price <= 5000):
52
        if type == DeliveryType.PREPAID and sld.exp:
42
            provider = query_provider.one().provider_less_amount
53
            provider = sld.provider
43
        else:
54
        if type == DeliveryType.COD and sld.cod:
44
            provider = query_provider.one().provider_more_amount
55
            provider = sld.provider
45
    except Exception as ex:
56
    except Exception as ex:
46
        print ex
-
 
47
        print "Unexpected error:", sys.exc_info()[0]
57
        print "Unexpected error:", sys.exc_info()[0]
-
 
58
    
-
 
59
    if not provider:
48
        raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin) + \
60
        raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin) + \
49
                                        ", and warehouse location: " + str(warehouse_location))
61
                                        ", and warehouse location: " + str(warehouse_location))
-
 
62
        
-
 
63
#    query_provider = DestinationProviderAllocation.query.filter_by(destination_pin = destination_pin)
-
 
64
#    query_provider = query_provider.filter_by(warehouse_location = warehouse_location)
-
 
65
#    try:
-
 
66
#        if (item_selling_price <= 5000):
-
 
67
#            provider = query_provider.one().provider_less_amount
-
 
68
#        else:
-
 
69
#            provider = query_provider.one().provider_more_amount
-
 
70
#    except Exception as ex:
-
 
71
#        print ex
-
 
72
#        print "Unexpected error:", sys.exc_info()[0]
-
 
73
#        raise LogisticsServiceException(101, "No provider assigned for pincode: " + str(destination_pin) + \
-
 
74
#                                        ", and warehouse location: " + str(warehouse_location))
50
    
75
    
51
    query = DeliveryEstimate.query.filter_by(warehouse_location = warehouse_location)
76
    query = DeliveryEstimate.query.filter_by(warehouse_location = warehouse_location)
52
    query = query.filter_by(destination_pin = destination_pin)
77
    query = query.filter_by(destination_pin = destination_pin)
53
    query = query.filter_by(provider = provider)
78
    query = query.filter_by(provider = provider)
54
    try:
79
    try: