Subversion Repositories SmartDukaan

Rev

Rev 1940 | Rev 4032 | 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
25
    session.commit()
26
 
27
def main():
28
    parser = optparse.OptionParser()
29
    parser.add_option("-d", "--days", dest="days",
30
                   default=2, type="int",
31
                   help="move orders marked as out of stock in last NUM days",
32
                   metavar="NUM")
4016 chandransh 33
    parser.add_option("-H", "--host", dest="hostname",
34
                      default="localhost",
35
                      type="string", help="The HOST where the DB server is running",
36
                      metavar="HOST")
1216 chandransh 37
    (options, args) = parser.parse_args()
38
    if len(args) != 0:
39
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
4016 chandransh 40
    move_out_of_stock_orders_to_pending_queue(options.days, options.hostname)
1216 chandransh 41
 
42
if __name__ == '__main__':
43
    main()