| 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 |
|
|
|
16 |
def move_out_of_stock_orders_to_pending_queue(days):
|
| 1251 |
chandransh |
17 |
DataService.initialize('transaction')
|
| 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")
|
|
|
33 |
(options, args) = parser.parse_args()
|
|
|
34 |
if len(args) != 0:
|
|
|
35 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
36 |
move_out_of_stock_orders_to_pending_queue(options.days)
|
|
|
37 |
|
|
|
38 |
if __name__ == '__main__':
|
|
|
39 |
main()
|