Subversion Repositories SmartDukaan

Rev

Rev 9431 | Rev 9805 | 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
 
9486 rajveer 45
 
9431 rajveer 46
            item = Item()
47
            item.productGroup = product_group
48
            item.brand = brand
49
            item.modelNumber = model_number
50
            item.modelName = model_name
51
            item.color = color
52
            item.mrp = round(mrp)
53
            item.sellingPrice = round(sp)
54
            item.startDate = long(to_java_date(datetime.datetime(1899, 12, 30) + timedelta(days=int(start_date))))
55
            item.preferredInsurer = preferred_vendor
56
            item.risky = risky
57
            item.weight = weight
58
            item.updatedOn = updatedOn
59
            item.type = int(item_type)
60
            item_id = cclient.addItem(item)
1080 chandransh 61
 
9431 rajveer 62
            vip = VendorItemPricing()
63
            vip.itemId = item_id
64
            vip.dealerPrice = round(dp)
65
            vip.mop = round(mop)
66
            vip.nlc = round(nlc)
67
            vip.transferPrice = round(tp)
68
            vip.vendorId = preferred_vendor
4717 phani.kuma 69
 
9431 rajveer 70
            iclient.addVendorItemPricing(vip)
9486 rajveer 71
        except Exception as e:
72
            cclient = CatalogClient().get_client()
73
            iclient = InventoryClient().get_client()
74
            message = message + "\t" + str(brand) + "\t" + str(model_name) + "\t" + str(model_number) + "\t" + str(e.message) + "\n"
1080 chandransh 75
 
9431 rajveer 76
    mail("build@shop2020.in", "cafe@nes", ["rajveer.singh@shop2020.in", "chandan.kumar@shop2020.in"], "Problem while adding items", message, [], [], [])    
626 chandransh 77
    print "Successfully updated the item list information."
78
 
4725 phani.kuma 79
 
626 chandransh 80
def main():
81
    parser = optparse.OptionParser()
82
    parser.add_option("-f", "--file", dest="filename",
83
                   default="ItemList.xls", type="string",
84
                   help="Read the item list from FILE",
85
                   metavar="FILE")
86
    (options, args) = parser.parse_args()
87
    if len(args) != 0:
88
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
89
    filename = options.filename
9431 rajveer 90
    load_item_data(filename)
626 chandransh 91
 
92
if __name__ == '__main__':
9431 rajveer 93
    main()