Subversion Repositories SmartDukaan

Rev

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

Rev 4031 Rev 6481
Line 7... Line 7...
7
'''
7
'''
8
 
8
 
9
import optparse
9
import optparse
10
import xlrd
10
import xlrd
11
import datetime
11
import datetime
-
 
12
from shop2020.model.v1.user.impl.UserDataAccessors import add_address_for_user
-
 
13
from shop2020.thriftpy.model.v1.user.ttypes import Address
12
 
14
 
13
if __name__ == '__main__' and __package__ is None:
15
if __name__ == '__main__' and __package__ is None:
14
    import sys
16
    import sys
15
    import os
17
    import os
16
    sys.path.insert(0, os.getcwd())
18
    sys.path.insert(0, os.getcwd())
Line 34... Line 36...
34
ITEM_ID_KEY = 'itemId'
36
ITEM_ID_KEY = 'itemId'
35
ITEM_DESC_KEY = 'itemDesc'
37
ITEM_DESC_KEY = 'itemDesc'
36
PRICE_KEY = 'price'
38
PRICE_KEY = 'price'
37
QUANTITY_KEY = 'quantity'
39
QUANTITY_KEY = 'quantity'
38
AMOUNT_KEY = 'amount'
40
AMOUNT_KEY = 'amount'
-
 
41
ADDRESS_KEY = 'address'
39
 
42
 
40
user_client = UserClient().get_client()
43
user_client = UserClient().get_client()
41
transaction_client = TransactionClient().get_client()
44
transaction_client = TransactionClient().get_client()
42
payment_client = PaymentClient().get_client()
45
payment_client = PaymentClient().get_client()
43
 
46
 
44
def create_orders(user, items):
47
def create_orders(user, items):
45
    orders = []
48
    orders = []
46
    for item in items:
49
    for item in items:
47
        line_item = create_line_item(int(item[ITEM_ID_KEY]), item[PRICE_KEY], item[QUANTITY_KEY])
50
        line_item = create_line_item(int(item[ITEM_ID_KEY]), item[PRICE_KEY], item[QUANTITY_KEY])
-
 
51
        addressId = add_address_for_user(item[ADDRESS_KEY], user.userId, False)
48
        orders.append(create_order(user.userId, user.defaultAddressId, line_item))
52
        orders.append(create_order(user.userId, addressId, line_item, 0, 0))
49
    return orders
53
    return orders
50
    
54
    
51
 
55
 
52
def create_transaction(user, items):
56
def create_transaction(user, items):
53
    txn = Transaction()
57
    txn = Transaction()
Line 81... Line 85...
81
    
85
    
82
    user = user_client.getUserByEmail(email)
86
    user = user_client.getUserByEmail(email)
83
    if user.userId == -1:
87
    if user.userId == -1:
84
        print "The email is not registered with us : " + email
88
        print "The email is not registered with us : " + email
85
        return
89
        return
86
    if user.defaultAddressId == 0:
-
 
87
        print "No default address for this user : " + email
-
 
88
        return
-
 
89
    
90
    
90
    items = []
91
    items = []
91
    total_amount = 0
92
    total_amount = 0
92
    for rownum in range(10, num_rows):
93
    for rownum in range(10, num_rows):
93
        item = {}
94
        item = {}
94
        item[ITEM_ID_KEY], item[ITEM_DESC_KEY], item[PRICE_KEY], item[QUANTITY_KEY], item[AMOUNT_KEY] = sheet.row_values(rownum)[0:5]
95
        item[ITEM_ID_KEY], item[ITEM_DESC_KEY], item[PRICE_KEY], item[QUANTITY_KEY], item[AMOUNT_KEY] = sheet.row_values(rownum)[0:5]
-
 
96
        name, line1, city, state, pin, phone  = sheet.row_values(rownum)[5:11]
95
        total_amount += item[AMOUNT_KEY]
97
        total_amount += item[AMOUNT_KEY]
96
        items.append(item)
98
        items.append(item)
97
        
99
        
-
 
100
        address = Address()
-
 
101
        address.name = name
-
 
102
        address.line1 = line1
-
 
103
        address.city = city
-
 
104
        address.state = state
-
 
105
        address.pin = str(pin)
-
 
106
        address.phone = str(phone)
-
 
107
        item[ADDRESS_KEY] = address
-
 
108
        
98
    if amount != total_amount:
109
    if amount != total_amount:
99
        print "Amount paid is not equal to the total amount of bulk order."
110
        print "Amount paid is not equal to the total amount of bulk order."
100
        return
111
        return
101
    
112
    
102
    txn_id = create_transaction(user, items)
113
    txn_id = create_transaction(user, items)