Subversion Repositories SmartDukaan

Rev

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

Rev 472 Rev 477
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, Provider, Shipment,\
8
from shop2020.logistics.service.impl.DataService import AWB, Provider, Shipment,\
9
    ShipmentUpdate, DeliveryEstimate
9
    ShipmentUpdate, DeliveryEstimate, PincodeWarehouseMapping
10
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
10
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
11
from elixir import session
11
from elixir import session
12
import datetime
12
import datetime
13
 
13
 
14
def initialize():
14
def initialize():
Line 133... Line 133...
133
    to_datetime = datetime.datetime(to_date.year, to_date.month, to_date.day)
133
    to_datetime = datetime.datetime(to_date.year, to_date.month, to_date.day)
134
 
134
 
135
    return get_shipments(warehouse_id, from_datetime, to_datetime, provider_id)
135
    return get_shipments(warehouse_id, from_datetime, to_datetime, provider_id)
136
 
136
 
137
def get_logistics_estimation(item_id, destination_pin, provider_id):
137
def get_logistics_estimation(item_id, destination_pin, provider_id):
-
 
138
    query = PincodeWarehouseMapping.query.filter_by(pincode = destination_pin)
-
 
139
    try:
-
 
140
        warehouse = query.one()
-
 
141
    except:
-
 
142
        warehouse = None
-
 
143
        #need to throw exception
-
 
144
            
-
 
145
    warehouse_pin = warehouse.warehouse_pin
-
 
146
    query = DeliveryEstimate.query.filter_by(source_pin = warehouse_pin)
138
    query = DeliveryEstimate.query.filter_by(destination_pin = destination_pin)
147
    query = query.filter_by(destination_pin = destination_pin)
139
    query = query.filter_by(provider_id = provider_id)
148
    query = query.filter_by(provider_id = provider_id)
140
    try:
149
    try:
141
        return query.one()
150
        return query.one(), warehouse.warehouse_id
142
    except:
151
    except:
143
        return None
152
        return None
144
    # need to check the availability in another service before returning estimation.
153
    # need to check the availability in another service before returning estimation.
145
    
154
    
146
def add_delivery_estimate(warahouse_id, destination_pin, provider_id, delivery_time):
155
def add_delivery_estimate(warehouse_id, destination_pin, provider_id, delivery_time, reliability):
147
    query = Provider.query.filter_by(id=provider_id)
156
    query = Provider.query.filter_by(id=provider_id)
148
    try:
157
    try:
149
        provider = query.one()
158
        provider = query.one()
150
    except:
159
    except:
151
        print "provide not found"
160
        print "provider not found"
-
 
161
 
-
 
162
    query = PincodeWarehouseMapping.query.filter_by(warehouse_id = warehouse_id)
-
 
163
    try:
-
 
164
        warehouse = query.one()
-
 
165
        warehouse_pin = warehouse.warehouse_pin
152
            
166
    except:
-
 
167
        warehouse_pin = 0
-
 
168
        print "warehouse pin not found"
-
 
169
 
153
    delivery_estimate = DeliveryEstimate()
170
    delivery_estimate = DeliveryEstimate()
154
    delivery_estimate.warehouse_id = warahouse_id
171
    delivery_estimate.source_pin = warehouse_pin
155
    delivery_estimate.destination_pin = destination_pin
172
    delivery_estimate.destination_pin = destination_pin
156
    delivery_estimate.provider = provider
173
    delivery_estimate.provider = provider
157
    delivery_estimate.delivery_time = delivery_time
174
    delivery_estimate.delivery_time = delivery_time
158
    session.commit()
-
 
159
175
    delivery_estimate.relibility = reliability
-
 
176
    session.commit()
-
 
177
    
-
 
178
def add_pincode_warehouse_mapping(pincode, warehouse_id, warehouse_pin):
-
 
179
    mapper = PincodeWarehouseMapping()
-
 
180
    mapper.pincode = pincode
-
 
181
    mapper.warehouse_id = warehouse_id
-
 
182
    if warehouse_pin:
-
 
183
        mapper.warehouse_name = warehouse_pin
-
 
184
    session.commit()    
-
 
185
160
186