Subversion Repositories SmartDukaan

Rev

Rev 1251 | Rev 4014 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1251 Rev 1433
Line 13... Line 13...
13
from shop2020.logistics.service.impl.DataService import WarehouseAllocation
13
from shop2020.logistics.service.impl.DataService import WarehouseAllocation
14
from shop2020.thriftpy.logistics.ttypes import WarehouseLocation
14
from shop2020.thriftpy.logistics.ttypes import WarehouseLocation
15
 
15
 
16
def load_warehouse_allocations(filename):
16
def load_warehouse_allocations(filename):
17
    DataService.initialize('logistics')
17
    DataService.initialize('logistics')
18
    
-
 
19
    workbook = xlrd.open_workbook(filename)
18
    workbook = xlrd.open_workbook(filename)
20
    sheet = workbook.sheet_by_index(0)
19
    sheet = workbook.sheet_by_index(0)
21
    num_rows = sheet.nrows
20
    num_rows = sheet.nrows
22
    for rownum in range(1, num_rows):
21
    for rownum in range(1, num_rows):
23
        pincode, warehouse_loc = sheet.row_values(rownum)[0:2]
22
        pincode, warehouse_loc = sheet.row_values(rownum)[0:2]
-
 
23
        warehouse_allocation = None
-
 
24
        try:
-
 
25
            warehouse_allocation = WarehouseAllocation.query.filter_by(pincode = pincode).one()
-
 
26
        except:
24
        warehouse_allocation = WarehouseAllocation()
27
            warehouse_allocation = WarehouseAllocation()
25
        warehouse_allocation.pincode = str(int(pincode))
28
            warehouse_allocation.pincode = str(int(pincode))
-
 
29
            session.add(warehouse_allocation)
26
        warehouse_allocation.primary_warehouse_location = WarehouseLocation._NAMES_TO_VALUES[warehouse_loc]
30
        warehouse_allocation.primary_warehouse_location = WarehouseLocation._NAMES_TO_VALUES[warehouse_loc]
27
    session.commit()
31
    session.commit()
28
 
32
 
29
def main():
33
def main():
30
    parser = optparse.OptionParser()
34
    parser = optparse.OptionParser()