| 644 |
chandransh |
1 |
#!/usr/bin/python
|
|
|
2 |
|
|
|
3 |
import optparse
|
|
|
4 |
import xlrd
|
|
|
5 |
from elixir import *
|
|
|
6 |
|
|
|
7 |
if __name__ == '__main__' and __package__ is None:
|
|
|
8 |
import sys
|
|
|
9 |
import os
|
|
|
10 |
sys.path.insert(0, os.getcwd())
|
|
|
11 |
|
|
|
12 |
from shop2020.logistics.service.impl import DataService
|
|
|
13 |
from shop2020.logistics.service.impl.DataService import WarehouseAllocation
|
|
|
14 |
from shop2020.thriftpy.logistics.ttypes import WarehouseLocation
|
|
|
15 |
|
|
|
16 |
def load_warehouse_allocations(filename):
|
| 1251 |
chandransh |
17 |
DataService.initialize('logistics')
|
| 644 |
chandransh |
18 |
|
|
|
19 |
workbook = xlrd.open_workbook(filename)
|
|
|
20 |
sheet = workbook.sheet_by_index(0)
|
|
|
21 |
num_rows = sheet.nrows
|
|
|
22 |
for rownum in range(1, num_rows):
|
|
|
23 |
pincode, warehouse_loc = sheet.row_values(rownum)[0:2]
|
|
|
24 |
warehouse_allocation = WarehouseAllocation()
|
|
|
25 |
warehouse_allocation.pincode = str(int(pincode))
|
|
|
26 |
warehouse_allocation.primary_warehouse_location = WarehouseLocation._NAMES_TO_VALUES[warehouse_loc]
|
|
|
27 |
session.commit()
|
|
|
28 |
|
|
|
29 |
def main():
|
|
|
30 |
parser = optparse.OptionParser()
|
|
|
31 |
parser.add_option("-f", "--file", dest="filename",
|
|
|
32 |
type="string", help="Read the serviceable location list from FILE",
|
|
|
33 |
metavar="FILE")
|
|
|
34 |
(options, args) = parser.parse_args()
|
|
|
35 |
if len(args) != 0:
|
|
|
36 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
37 |
filename = options.filename
|
|
|
38 |
if filename is None:
|
|
|
39 |
parser.error("A filename must be provided. Use -h for more details.")
|
|
|
40 |
load_warehouse_allocations(filename)
|
|
|
41 |
|
|
|
42 |
if __name__ == '__main__':
|
|
|
43 |
main()
|