Subversion Repositories SmartDukaan

Rev

Rev 4016 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1216 chandransh 1
#!/usr/bin/python 
2
 
3
import datetime
4
import optparse
5
import sys
6
 
7
if __name__ == '__main__' and __package__ is None:
8
    import os
9
    sys.path.insert(0, os.getcwd())
10
 
11
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus
12
from shop2020.model.v1.order.impl import DataService
13
from shop2020.model.v1.order.impl.DataService import Order
1940 chandransh 14
from elixir import session
1216 chandransh 15
 
4016 chandransh 16
def move_out_of_stock_orders_to_pending_queue(days, db_hostname):
17
    DataService.initialize(db_hostname=db_hostname, echoOn=True)
1217 chandransh 18
    current_time = datetime.datetime.now()
19
    to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
20
    to_datetime = to_datetime - datetime.timedelta(days-1)
21
    from_datetime = to_datetime - datetime.timedelta(1)
22
    orders = Order.query.filter_by(status=OrderStatus.INVENTORY_LOW).filter(Order.outofstock_timestamp >= from_datetime).filter(Order.outofstock_timestamp <= to_datetime).all()
1216 chandransh 23
    for order in orders:
24
        order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
4032 chandransh 25
        order.statusDescription = 'Moved back to pending queue'
1216 chandransh 26
    session.commit()
27
 
28
def main():
29
    parser = optparse.OptionParser()
30
    parser.add_option("-d", "--days", dest="days",
31
                   default=2, type="int",
32
                   help="move orders marked as out of stock in last NUM days",
33
                   metavar="NUM")
4016 chandransh 34
    parser.add_option("-H", "--host", dest="hostname",
35
                      default="localhost",
36
                      type="string", help="The HOST where the DB server is running",
37
                      metavar="HOST")
1216 chandransh 38
    (options, args) = parser.parse_args()
39
    if len(args) != 0:
40
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
4016 chandransh 41
    move_out_of_stock_orders_to_pending_queue(options.days, options.hostname)
1216 chandransh 42
 
43
if __name__ == '__main__':
44
    main()