| 5944 |
mandeep.dh |
1 |
#!/usr/bin/python
|
|
|
2 |
'''
|
|
|
3 |
It processes the Hotspot procurement Report containing the response of the procurement
|
|
|
4 |
report sent to hotspot. It reads the response and populates the database.
|
|
|
5 |
|
|
|
6 |
@author: Rajveer
|
|
|
7 |
'''
|
|
|
8 |
import time
|
|
|
9 |
import datetime
|
|
|
10 |
import optparse
|
|
|
11 |
import sys
|
|
|
12 |
import xlrd
|
|
|
13 |
import traceback
|
|
|
14 |
|
|
|
15 |
if __name__ == '__main__' and __package__ is None:
|
|
|
16 |
import os
|
|
|
17 |
sys.path.insert(0, os.getcwd())
|
|
|
18 |
|
|
|
19 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
|
|
20 |
from shop2020.clients.TransactionClient import TransactionClient
|
|
|
21 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException
|
|
|
22 |
from shop2020.utils.EmailAttachmentDownloader import download_attachment
|
|
|
23 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
|
|
24 |
from shop2020.utils.Utils import to_py_date
|
|
|
25 |
|
|
|
26 |
from_user = 'cnc.center@shop2020.in'
|
|
|
27 |
from_pwd = '5h0p2o2o'
|
|
|
28 |
to = ['cnc.center@shop2020.in', "suraj.sharma@shop2020.in", "sandeep.sachdeva@shop2020.in", "parmod.kumar@shop2020.in"]
|
|
|
29 |
|
|
|
30 |
def process_procurement_report(vendor):
|
|
|
31 |
try:
|
|
|
32 |
#filename = "./hotspot-procurement-report-2012-1-10.xls"
|
|
|
33 |
filename = fetch_report('UPDATED')
|
|
|
34 |
print "Reading procurement report from:" + filename
|
|
|
35 |
workbook = xlrd.open_workbook(filename)
|
|
|
36 |
sheet = workbook.sheet_by_index(0)
|
|
|
37 |
num_rows = sheet.nrows
|
|
|
38 |
txnClient = TransactionClient().get_client()
|
|
|
39 |
for rownum in range(1, num_rows):
|
|
|
40 |
item_id = sheet.row_values(rownum)[0]
|
|
|
41 |
po_raised = sheet.row_values(rownum)[15]
|
|
|
42 |
po_estimate = sheet.row_values(rownum)[16]
|
|
|
43 |
reversal = sheet.row_values(rownum)[17]
|
|
|
44 |
reversal_estimate = sheet.row_values(rownum)[18]
|
|
|
45 |
not_available = sheet.row_values(rownum)[19]
|
|
|
46 |
|
|
|
47 |
#item_id, category, brand, model_name, model_number, color, total_requirement, po_raised, po_estimate, reversal, reversal_estimate, not_available, deficit, remarks = sheet.row_values(rownum)[0:13]
|
|
|
48 |
|
|
|
49 |
if po_raised > 0:
|
|
|
50 |
try:
|
|
|
51 |
txnClient.markOrdersAsPORaised(vendor, item_id, po_raised, po_estimate, False)
|
|
|
52 |
except TransactionServiceException as tex:
|
|
|
53 |
print tex.message
|
|
|
54 |
|
|
|
55 |
if reversal > 0:
|
|
|
56 |
try:
|
|
|
57 |
txnClient.markOrdersAsReversalInitiated(vendor, item_id, reversal, reversal_estimate, False)
|
|
|
58 |
except TransactionServiceException as tex:
|
|
|
59 |
print tex.message
|
|
|
60 |
|
|
|
61 |
if not_available > 0:
|
|
|
62 |
try:
|
|
|
63 |
txnClient.markOrdersAsNotAvailabke(vendor, item_id, not_available, 0, False)
|
|
|
64 |
except TransactionServiceException as tex:
|
|
|
65 |
print tex.message
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
sheet = workbook.sheet_by_index(1)
|
|
|
69 |
num_rows = sheet.nrows
|
|
|
70 |
|
|
|
71 |
for rownum in range(1, num_rows):
|
|
|
72 |
item_id = sheet.row_values(rownum)[0]
|
|
|
73 |
po_raised = sheet.row_values(rownum)[10]
|
|
|
74 |
po_estimate = sheet.row_values(rownum)[11]
|
|
|
75 |
reversal = sheet.row_values(rownum)[12]
|
|
|
76 |
reversal_estimate = sheet.row_values(rownum)[13]
|
|
|
77 |
not_available = sheet.row_values(rownum)[14]
|
|
|
78 |
|
|
|
79 |
if po_raised > 0:
|
|
|
80 |
try:
|
|
|
81 |
txnClient.markOrdersAsPORaised(vendor, item_id, po_raised, po_estimate, True)
|
|
|
82 |
except TransactionServiceException as tex:
|
|
|
83 |
print tex.message
|
|
|
84 |
|
|
|
85 |
if reversal > 0:
|
|
|
86 |
try:
|
|
|
87 |
txnClient.markOrdersAsReversalInitiated(vendor, item_id, reversal, reversal_estimate, True)
|
|
|
88 |
except TransactionServiceException as tex:
|
|
|
89 |
print tex.message
|
|
|
90 |
|
|
|
91 |
if not_available > 0:
|
|
|
92 |
try:
|
|
|
93 |
txnClient.markOrdersAsNotAvailabke(vendor, item_id, not_available, 0, True)
|
|
|
94 |
except TransactionServiceException as tex:
|
|
|
95 |
print tex.message
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
finally:
|
|
|
99 |
#print filename
|
|
|
100 |
os.remove(filename)
|
|
|
101 |
|
|
|
102 |
def fetch_report(type):
|
|
|
103 |
filename = download_attachment(type, todays_date_string())
|
|
|
104 |
if filename is None:
|
|
|
105 |
sys.exit("The " + type + " report is not yet available.")
|
|
|
106 |
return filename
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
def todays_date_string():
|
|
|
110 |
today_date = time.strftime("%d-%b-%Y")
|
|
|
111 |
return '"' + today_date + '"'
|
|
|
112 |
|
|
|
113 |
def get_py_datetime(date, timeval):
|
|
|
114 |
# This should be a command line argument.
|
|
|
115 |
# Refer http://docs.python.org/library/time.html#time.strftime to
|
|
|
116 |
# get a complete list of format specifiers available for date time.
|
|
|
117 |
time_format = "%d-%b-%y %H%M"
|
|
|
118 |
if timeval is None or timeval == '--':
|
|
|
119 |
timeval='0000'
|
|
|
120 |
time_string = date + " " + timeval
|
|
|
121 |
mytime = time.strptime(time_string, time_format)
|
|
|
122 |
return datetime.datetime(*mytime[:6])
|
|
|
123 |
|
|
|
124 |
def main():
|
|
|
125 |
parser = optparse.OptionParser()
|
|
|
126 |
parser.add_option("-V", "--vendor", dest="vendor",
|
|
|
127 |
default=1, type="int",
|
|
|
128 |
help="The VENDOR is ",
|
|
|
129 |
metavar="PROVIDER")
|
|
|
130 |
(options, args) = parser.parse_args()
|
|
|
131 |
if len(args) != 0:
|
|
|
132 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
133 |
|
|
|
134 |
if options.vendor:
|
|
|
135 |
process_procurement_report(options.vendor)
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
if __name__ == '__main__':
|
|
|
139 |
main()
|