| 3657 |
vikas |
1 |
#!/usr/bin/python
|
|
|
2 |
|
|
|
3 |
'''
|
|
|
4 |
Created on 12-Oct-2011
|
|
|
5 |
|
|
|
6 |
@author: Vikas
|
|
|
7 |
'''
|
|
|
8 |
|
|
|
9 |
import optparse
|
|
|
10 |
import xlrd
|
|
|
11 |
import datetime
|
| 6481 |
rajveer |
12 |
from shop2020.model.v1.user.impl.UserDataAccessors import add_address_for_user
|
|
|
13 |
from shop2020.thriftpy.model.v1.user.ttypes import Address
|
| 12163 |
kshitij.so |
14 |
from shop2020.thriftpy.model.v1.order.ttypes import LineItem
|
| 3657 |
vikas |
15 |
|
| 4031 |
chandransh |
16 |
if __name__ == '__main__' and __package__ is None:
|
|
|
17 |
import sys
|
|
|
18 |
import os
|
|
|
19 |
sys.path.insert(0, os.getcwd())
|
|
|
20 |
|
| 3657 |
vikas |
21 |
from shop2020.clients.UserClient import UserClient
|
|
|
22 |
from shop2020.model.v1.user.impl.CartDataAccessors import create_line_item, create_order
|
|
|
23 |
from shop2020.model.v1.user.impl import Dataservice
|
|
|
24 |
from shop2020.clients.TransactionClient import TransactionClient
|
|
|
25 |
from shop2020.clients.PaymentClient import PaymentClient
|
| 7293 |
anupam.sin |
26 |
from shop2020.thriftpy.model.v1.order.ttypes import Transaction, TransactionStatus, OrderSource
|
| 3657 |
vikas |
27 |
from shop2020.thriftpy.payments.ttypes import Attribute, PaymentStatus
|
|
|
28 |
from shop2020.utils.Utils import to_java_date
|
|
|
29 |
|
|
|
30 |
RTGS_GATEWAY_ID = 6
|
|
|
31 |
PAYMETHOD_ATTR = 'payMethod'
|
|
|
32 |
RTGS_ID_ATTR = 'rtgsId'
|
|
|
33 |
RTGS_BANK_ATTR = 'rtgsBank'
|
|
|
34 |
RTGS_BRANCH_ATTR = 'rtgsBranch'
|
|
|
35 |
IFSC_ATTR = 'ifscCode'
|
|
|
36 |
|
| 3666 |
vikas |
37 |
ITEM_ID_KEY = 'itemId'
|
|
|
38 |
ITEM_DESC_KEY = 'itemDesc'
|
|
|
39 |
PRICE_KEY = 'price'
|
|
|
40 |
QUANTITY_KEY = 'quantity'
|
|
|
41 |
AMOUNT_KEY = 'amount'
|
| 6481 |
rajveer |
42 |
ADDRESS_KEY = 'address'
|
| 3666 |
vikas |
43 |
|
| 3657 |
vikas |
44 |
user_client = UserClient().get_client()
|
|
|
45 |
transaction_client = TransactionClient().get_client()
|
|
|
46 |
payment_client = PaymentClient().get_client()
|
|
|
47 |
|
|
|
48 |
def create_orders(user, items):
|
|
|
49 |
orders = []
|
|
|
50 |
for item in items:
|
| 12163 |
kshitij.so |
51 |
t_lineitem = LineItem()
|
|
|
52 |
t_lineitem.item_id=item[ITEM_ID_KEY]
|
|
|
53 |
line_item = create_line_item(t_lineitem, item[PRICE_KEY], item[QUANTITY_KEY])
|
| 6481 |
rajveer |
54 |
addressId = add_address_for_user(item[ADDRESS_KEY], user.userId, False)
|
| 12163 |
kshitij.so |
55 |
orders.append(create_order(user.userId, addressId, line_item, 0, 0, 0, 0, None, 0, 0,1,0))
|
| 3657 |
vikas |
56 |
return orders
|
|
|
57 |
|
|
|
58 |
|
| 3666 |
vikas |
59 |
def create_transaction(user, items):
|
| 3657 |
vikas |
60 |
txn = Transaction()
|
|
|
61 |
txn.shoppingCartid = user.activeCartId
|
|
|
62 |
txn.customer_id = user.userId
|
|
|
63 |
txn.createdOn = to_java_date(datetime.datetime.now())
|
|
|
64 |
txn.transactionStatus = TransactionStatus.INIT
|
|
|
65 |
txn.statusDescription = "New Order"
|
| 3666 |
vikas |
66 |
txn.orders = create_orders(user, items)
|
| 3657 |
vikas |
67 |
transaction_client = TransactionClient().get_client()
|
|
|
68 |
txn_id = transaction_client.createTransaction(txn)
|
|
|
69 |
return txn_id
|
|
|
70 |
|
|
|
71 |
def create_payment(user, amount , txn_id, rtgs_id, rtgs_bank, rtgs_branch, ifsc):
|
| 6487 |
rajveer |
72 |
payment_id = payment_client.createPayment(user.userId, amount, RTGS_GATEWAY_ID, txn_id, False)
|
| 3657 |
vikas |
73 |
payment_client.getPayment(payment_id)
|
|
|
74 |
attributes = []
|
| 3724 |
vikas |
75 |
attributes.append(Attribute(PAYMETHOD_ATTR, '4000'))
|
| 3657 |
vikas |
76 |
attributes.append(Attribute(RTGS_ID_ATTR, str(rtgs_id)))
|
|
|
77 |
attributes.append(Attribute(RTGS_BANK_ATTR, rtgs_bank))
|
|
|
78 |
attributes.append(Attribute(RTGS_BRANCH_ATTR, rtgs_branch))
|
|
|
79 |
attributes.append(Attribute(IFSC_ATTR, str(ifsc)))
|
|
|
80 |
payment_client.updatePaymentDetails(payment_id, None, None, None, None, None, None, None, None, PaymentStatus.SUCCESS, None, attributes)
|
|
|
81 |
|
|
|
82 |
def load_orders(file):
|
| 10698 |
manish.sha |
83 |
workbook = xlrd.open_workbook(file, encoding_override="UTF-8")
|
| 3657 |
vikas |
84 |
sheet = workbook.sheet_by_index(0)
|
|
|
85 |
num_rows = sheet.nrows
|
|
|
86 |
|
|
|
87 |
email, rtgs_id, rtgs_bank, rtgs_branch, ifsc, amount = sheet.col_values(1)[0:6]
|
|
|
88 |
|
|
|
89 |
user = user_client.getUserByEmail(email)
|
|
|
90 |
if user.userId == -1:
|
|
|
91 |
print "The email is not registered with us : " + email
|
|
|
92 |
return
|
|
|
93 |
|
|
|
94 |
items = []
|
|
|
95 |
total_amount = 0
|
|
|
96 |
for rownum in range(10, num_rows):
|
| 3666 |
vikas |
97 |
item = {}
|
|
|
98 |
item[ITEM_ID_KEY], item[ITEM_DESC_KEY], item[PRICE_KEY], item[QUANTITY_KEY], item[AMOUNT_KEY] = sheet.row_values(rownum)[0:5]
|
| 6481 |
rajveer |
99 |
name, line1, city, state, pin, phone = sheet.row_values(rownum)[5:11]
|
| 3666 |
vikas |
100 |
total_amount += item[AMOUNT_KEY]
|
|
|
101 |
items.append(item)
|
| 3657 |
vikas |
102 |
|
| 6481 |
rajveer |
103 |
address = Address()
|
|
|
104 |
address.name = name
|
|
|
105 |
address.line1 = line1
|
|
|
106 |
address.city = city
|
|
|
107 |
address.state = state
|
| 6487 |
rajveer |
108 |
address.pin = str(int(pin))
|
|
|
109 |
address.phone = str(int(phone))
|
| 6481 |
rajveer |
110 |
item[ADDRESS_KEY] = address
|
|
|
111 |
|
| 3657 |
vikas |
112 |
if amount != total_amount:
|
|
|
113 |
print "Amount paid is not equal to the total amount of bulk order."
|
|
|
114 |
return
|
|
|
115 |
|
| 3666 |
vikas |
116 |
txn_id = create_transaction(user, items)
|
| 3657 |
vikas |
117 |
create_payment(user, amount, txn_id, rtgs_id, rtgs_bank, rtgs_branch, ifsc)
|
| 7293 |
anupam.sin |
118 |
transaction_client.changeTransactionStatus(txn_id, TransactionStatus.AUTHORIZED, "Payment received for the order", 0, 0, OrderSource.WEBSITE);
|
|
|
119 |
transaction_client.changeTransactionStatus(txn_id, TransactionStatus.IN_PROCESS, "RTGS Payment accepted", 0, 0, OrderSource.WEBSITE);
|
| 3657 |
vikas |
120 |
|
|
|
121 |
def main():
|
| 10698 |
manish.sha |
122 |
|
| 3657 |
vikas |
123 |
parser = optparse.OptionParser()
|
|
|
124 |
parser.add_option("-f", "--file", dest="file",
|
|
|
125 |
help="Excel file with bulk orders.")
|
| 3768 |
vikas |
126 |
parser.add_option("-d", "--db_server", dest="host",
|
|
|
127 |
default="localhost",
|
|
|
128 |
help="Database server.")
|
| 3657 |
vikas |
129 |
(options, args) = parser.parse_args()
|
|
|
130 |
if len(args) != 0:
|
|
|
131 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
| 3815 |
vikas |
132 |
if options.file == None:
|
|
|
133 |
parser.error("Excel File with bulk orders not supplied.")
|
| 10698 |
manish.sha |
134 |
|
| 3768 |
vikas |
135 |
Dataservice.initialize(db_hostname=options.host)
|
| 3657 |
vikas |
136 |
|
| 3815 |
vikas |
137 |
load_orders(options.file)
|
| 10698 |
manish.sha |
138 |
#load_orders('/home/manish/Downloads/Eveready_BulkOrder.xls')
|
| 3657 |
vikas |
139 |
|
|
|
140 |
if __name__ == '__main__':
|
| 3815 |
vikas |
141 |
main()
|