Subversion Repositories SmartDukaan

Rev

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

Rev 12895 Rev 13146
Line 14... Line 14...
14
from sqlalchemy.sql import or_
14
from sqlalchemy.sql import or_
15
from elixir import session
15
from elixir import session
16
import datetime, time
16
import datetime, time
17
import sys
17
import sys
18
import logging
18
import logging
-
 
19
import os
19
from shop2020.clients.CatalogClient import CatalogClient
20
from shop2020.clients.CatalogClient import CatalogClient
20
logging.basicConfig(level=logging.DEBUG)
21
logging.basicConfig(level=logging.DEBUG)
21
 
22
 
22
warehouse_allocation_cache = {}
23
warehouse_allocation_cache = {}
23
serviceable_location_cache = {}
24
serviceable_location_cache = {}
Line 268... Line 269...
268
    serviceableLocationDetails.exp = exp
269
    serviceableLocationDetails.exp = exp
269
    serviceableLocationDetails.cod = cod
270
    serviceableLocationDetails.cod = cod
270
    serviceableLocationDetails.otgAvailable = otgAvailable
271
    serviceableLocationDetails.otgAvailable = otgAvailable
271
    session.commit()
272
    session.commit()
272
 
273
 
273
def add_new_awbs(provider_id, isCod, awbs):
274
def add_new_awbs(provider_id, isCod, awbs, awbUsedFor):
274
    provider = get_provider(provider_id)
275
    provider = get_provider(provider_id)
275
    if isCod:
276
    if isCod:
276
        dtype = 'Cod'
277
        dtype = 'Cod'
277
    else:
278
    else:
278
        dtype = 'Prepaid'
279
        dtype = 'Prepaid'
279
    for awb in awbs:
280
    for awb in awbs:
280
        a = Awb()
281
        a = Awb()
281
        a.type =  dtype
282
        a.type =  dtype
282
        a.is_available = True
283
        a.is_available = True
283
        a.awb_number = awb
284
        a.awb_number = awb
-
 
285
        a.awbUsedFor = awbUsedFor
284
        a.provider = provider 
286
        a.provider = provider 
285
    session.commit()
287
    session.commit()
286
    return True
288
    return True
287
    
289
    
288
def adjust_delivery_time(start_time, delivery_days):
290
def adjust_delivery_time(start_time, delivery_days):
Line 373... Line 375...
373
    delEstimate = DeliveryEstimate.query.filter(DeliveryEstimate.destination_pin == pincode).filter(DeliveryEstimate.warehouse_location == whLocation).first()
375
    delEstimate = DeliveryEstimate.query.filter(DeliveryEstimate.destination_pin == pincode).filter(DeliveryEstimate.warehouse_location == whLocation).first()
374
    if delEstimate is None:
376
    if delEstimate is None:
375
        return -1
377
        return -1
376
    else:
378
    else:
377
        return 1
379
        return 1
378
    
-
 
379
380
    
-
 
381
def get_provider_limit_details_for_pincode(provider, pincode):
-
 
382
    serviceAbleDetails = ServiceableLocationDetails.get_by(provider_id = provider, dest_pincode = pincode)
-
 
383
    returnDataMap = {}
-
 
384
    if serviceAbleDetails:
-
 
385
        returnDataMap["websiteCodLimit"] = str(serviceAbleDetails.websiteCodLimit)
-
 
386
        returnDataMap["providerPrepaidLimit"] = str(serviceAbleDetails.providerPrepaidLimit)
-
 
387
    
-
 
388
    return returnDataMap
-
 
389
 
-
 
390
def get_new_empty_awb(providerId, type, orderQuantity):
-
 
391
    query = Awb.query.with_lockmode("update").filter_by(provider_id = providerId, is_available = True)  #check the provider thing
-
 
392
    if type == DeliveryType.PREPAID:
-
 
393
        query = query.filter_by(type="Prepaid")
-
 
394
    if type == DeliveryType.COD:
-
 
395
        query = query.filter_by(type="COD")
-
 
396
        
-
 
397
    additionalQuery = query
-
 
398
    if orderQuantity == 1:
-
 
399
        query = query.filter_by(awbUsedFor=0)
-
 
400
    if orderQuantity >1:
-
 
401
        query = query.filter_by(awbUsedFor=1) 
-
 
402
    
-
 
403
    try:
-
 
404
        awb = query.first()
-
 
405
        if awb is None:
-
 
406
            additionalQuery = additionalQuery.filter_by(awbUsedFor=2)
-
 
407
            awb = additionalQuery.first()
-
 
408
        awb.is_available = False
-
 
409
        session.commit()
-
 
410
        return awb.awb_number
-
 
411
    except:
-
 
412
        raise LogisticsServiceException(103, "Unable to get an AWB for the given Provider: " + str(providerId))
-
 
413
        
-
 
414
380
415