Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
626 chandransh 1
#!/usr/bin/python
5440 phani.kuma 2
# coding: ascii
4090 chandransh 3
'''
4
This script is used to load item details in the catalog database.
5
It's now mostly used for Accessories since they come in huge numbers.
1080 chandransh 6
 
4090 chandransh 7
@author: Chandranshu
8
'''
5971 mandeep.dh 9
from elixir import *
9431 rajveer 10
from shop2020.thriftpy.model.v1.catalog.ttypes import Item
5971 mandeep.dh 11
import csv
12
import datetime
9431 rajveer 13
from datetime import timedelta
626 chandransh 14
import optparse
15
import xlrd
9431 rajveer 16
from shop2020.clients.CatalogClient import CatalogClient
17
from shop2020.clients.InventoryClient import InventoryClient
18
from shop2020.thriftpy.model.v1.inventory.ttypes import VendorItemPricing
19
from shop2020.utils.Utils import to_java_date
20
from shop2020.utils.EmailAttachmentSender import mail
626 chandransh 21
 
22
if __name__ == '__main__' and __package__ is None:
23
    import sys
24
    import os
25
    sys.path.insert(0, os.getcwd())
26
 
27
 
9431 rajveer 28
def load_item_data(filename):
626 chandransh 29
    workbook = xlrd.open_workbook(filename)
30
    sheet = workbook.sheet_by_index(0)
31
    num_rows = sheet.nrows
9431 rajveer 32
    updatedOn = to_java_date(datetime.datetime.now())
33
    cclient = CatalogClient().get_client()
34
    iclient = InventoryClient().get_client()
35
 
626 chandransh 36
    for rownum in range(1, num_rows):
1833 chandransh 37
        print sheet.row_values(rownum)
9431 rajveer 38
        message = ""
39
        try:
40
            product_group, brand, model_number, model_name, color, mrp, sp, mop, dp, tp, nlc, start_date, preferred_vendor, risky, weight, item_type = sheet.row_values(rownum)[0:16]
1356 chandransh 41
 
9431 rajveer 42
            if isinstance(model_number, float):
43
                model_number = str(int(model_number))
5440 phani.kuma 44
 
9431 rajveer 45
            item = Item()
46
            item.productGroup = product_group
47
            item.brand = brand
48
            item.modelNumber = model_number
49
            item.modelName = model_name
50
            item.color = color
51
            item.mrp = round(mrp)
52
            item.sellingPrice = round(sp)
53
            item.startDate = long(to_java_date(datetime.datetime(1899, 12, 30) + timedelta(days=int(start_date))))
54
            item.preferredInsurer = preferred_vendor
55
            item.risky = risky
56
            item.weight = weight
57
            item.updatedOn = updatedOn
58
            item.type = int(item_type)
59
            item_id = cclient.addItem(item)
1080 chandransh 60
 
9431 rajveer 61
            vip = VendorItemPricing()
62
            vip.itemId = item_id
63
            vip.dealerPrice = round(dp)
64
            vip.mop = round(mop)
65
            vip.nlc = round(nlc)
66
            vip.transferPrice = round(tp)
67
            vip.vendorId = preferred_vendor
4717 phani.kuma 68
 
9431 rajveer 69
            iclient.addVendorItemPricing(vip)
70
        except:
71
            message = message + "\t" + str(brand) + "\t" + str(model_name) + "\t" + str(model_number) + "\n"
1080 chandransh 72
 
9431 rajveer 73
    mail("build@shop2020.in", "cafe@nes", ["rajveer.singh@shop2020.in", "chandan.kumar@shop2020.in"], "Problem while adding items", message, [], [], [])    
626 chandransh 74
    print "Successfully updated the item list information."
75
 
4725 phani.kuma 76
 
626 chandransh 77
def main():
78
    parser = optparse.OptionParser()
79
    parser.add_option("-f", "--file", dest="filename",
80
                   default="ItemList.xls", type="string",
81
                   help="Read the item list from FILE",
82
                   metavar="FILE")
83
    (options, args) = parser.parse_args()
84
    if len(args) != 0:
85
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
86
    filename = options.filename
9431 rajveer 87
    load_item_data(filename)
626 chandransh 88
 
89
if __name__ == '__main__':
9431 rajveer 90
    main()