Subversion Repositories SmartDukaan

Rev

Rev 7644 | Blame | Compare with Previous | Last modification | View Log | RSS feed

from elixir import *
from shop2020.model.v1.order.impl import DataService
from shop2020.model.v1.order.impl.DataService import Order, AmazonOrder 
from datetime import datetime, timedelta, date ,time
import xlrd
from shop2020.clients.TransactionClient import TransactionClient 
from shop2020.config.client.ConfigClient import ConfigClient


config_client = ConfigClient()
host = config_client.get_property('transaction_service_db_hostname')
print "Selecting host: ",host
DataService.initialize(db_hostname=host)
directory = "/tmp/Amazon-shipping.xls"
amazonOrder = [[]]
sheet = xlrd.open_workbook(directory)
sh = sheet.sheet_by_index(0)    
def get_seconds(t_delta):
    return ((t_delta.microseconds + (t_delta.seconds + t_delta.days * 24 * 3600) * 10**6) / 10**6)
for i in range (0,sh.nrows):
    amazonOrder.append([sh.cell_value(i,0),sh.cell_value(i,1),sh.cell_value(i,2)])
for row in amazonOrder:
    if not len(row) == 0:
        amazonOrderCode = row[0]
        minDeliveryDate = row[1]
        maxDeliveryDate = row[2]
        print "=============================="
        print "OrderId",amazonOrderCode
        print "Minimum Delivery Date",minDeliveryDate
        print "Maxmium Delivery Date",maxDeliveryDate
        print "=============================="
        print "\n"
        print "Fetching OrderId's For Amazon Order Code"
        print "==============================="
        orders = AmazonOrder.query.filter(AmazonOrder.amazonOrderCode==amazonOrderCode).filter(AmazonOrder.status=='Order-Payment-Success').all()
        for order in orders:
            row = Order.query.filter(Order.id==order.orderId).first()
            if row is None:
                continue
            expectedDeliveryTime = row.expected_delivery_time
            promisedDeliveryTime = row.promised_delivery_time
            expectedShippingTime = row.expected_shipping_time
            promisedShippingTime = row.promised_shipping_time
            deltaTime = (expectedDeliveryTime-expectedShippingTime)
            
            
            print "+++++++++++++++++++++++"
            print "Expected Delivery Time : ",expectedDeliveryTime
            print "Promised Delivery Time : ",promisedDeliveryTime
            print "Expected Shipping Time : ",expectedShippingTime
            print "Promised Shipping Time : ",promisedShippingTime
            print "Delta Time : ", deltaTime
            print "=============================="
            
            newExpectedDeliveryTime=datetime.strptime(minDeliveryDate, "%d-%m-%Y")
            newTime = time(expectedDeliveryTime.hour, expectedDeliveryTime.minute, expectedDeliveryTime.second)
            newExpectedDeliveryTime = datetime.combine(newExpectedDeliveryTime, newTime)
            newPromisedDeliveryTime=datetime.strptime(minDeliveryDate, "%d-%m-%Y")
            newTime = time(promisedDeliveryTime.hour, promisedDeliveryTime.minute, promisedDeliveryTime.second)
            newPromisedDeliveryTime = datetime.combine(newPromisedDeliveryTime, newTime)
            newExpectedShippingTime=newExpectedDeliveryTime-deltaTime
            newPromisedShippingTime=newPromisedDeliveryTime-deltaTime
            
            
            
            print "######################"
            print "New Expected Delivery Time : ",newExpectedDeliveryTime
            print "New Promised Delivery Time : ",newPromisedDeliveryTime
            print "New Expected Shipping Time : ",newExpectedShippingTime
            print "New Promised Shipping Time : ",newPromisedShippingTime

            client = TransactionClient().get_client()
            client.updateTimestampForAmazonOrder(order.orderId, get_seconds((newExpectedDeliveryTime-datetime(1970,1,1))-timedelta(hours = 5,minutes=30)), get_seconds((newPromisedDeliveryTime-datetime(1970,1,1))-timedelta(hours = 5,minutes=30)), get_seconds((newExpectedShippingTime-datetime(1970,1,1))-timedelta(hours = 5,minutes=30)), get_seconds((newPromisedShippingTime-datetime(1970,1,1))-timedelta(hours = 5,minutes=30)))