Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
5326 rajveer 1
from shop2020.thriftpy.model.v1.user.ttypes import Address as TAddress, UserCommunication as TUserCommunication, \
2
    User as TUser, Cart as TCart, Line as TLine, MasterAffiliate as TMasterAffiliate, \
4189 varun.gupt 3
    Affiliate as TAffiliate, Tracker as TTracker, TrackLog as TTrackLog, Promotion as TPromotion, \
6394 amit.gupta 4
    Coupon as TCoupon, Discount as TDiscount, ItemCouponDiscount as TItemCouponDiscount,\
5469 rajveer 5
    Voucher
4189 varun.gupt 6
 
130 ashish 7
from shop2020.utils.Utils import to_java_date
8
 
9
def to_t_address(address):
10
    t_address = TAddress()
11
    t_address.id = address.id
12
    t_address.line1 = address.line_1
13
    t_address.line2 = address.line_2
14
    t_address.landmark = address.landmark
15
    t_address.city = address.city
16
    t_address.state = address.state
17
    t_address.pin = address.pin
18
    t_address.country = address.country
19
    t_address.enabled = address.enabled
20
    t_address.type = address.type
21
    t_address.addedOn = to_java_date(address.added_on)
414 ashish 22
    t_address.name = address.name
23
    t_address.phone = address.phone
557 chandransh 24
    return t_address    
130 ashish 25
 
557 chandransh 26
def to_t_user(user):
27
    t_user = TUser()
576 chandransh 28
    if user is None:
29
        t_user.userId = -1
30
        return t_user
31
 
557 chandransh 32
    t_user.userId = user.id
33
    t_user.name = user.name
34
    t_user.email = user.email
619 rajveer 35
    t_user.password = user.password
557 chandransh 36
    t_user.sex = user.sex
37
 
38
    t_user.communicationEmail = user.communication_email
39
    t_user.defaultAddressId = user.default_address_id
40
    t_user.isAnonymous = user.is_anonymous
41
    t_user.activeCartId = user.active_cart_id
567 rajveer 42
    t_user.dateOfBirth = user.date_of_birth
43
    t_user.mobileNumber = user.mobile_number
2020 vikas 44
    t_user.source = user.source
2815 vikas 45
    t_user.sourceStartTime = to_java_date(user.source_start_time)
3499 mandeep.dh 46
    t_user.trustLevel = user.trust_level
5326 rajveer 47
    t_user.lastLogin = to_java_date(user.last_login)
48
    t_user.lastLogout = to_java_date(user.last_logout)
49
    t_user.activeSince = to_java_date(user.active_since)
130 ashish 50
    #put all addresses
557 chandransh 51
    if user.addresses:
52
        t_user.addresses = list()
53
        for address in user.addresses:
54
            t_user.addresses.append(to_t_address(address))
55
    return t_user
513 rajveer 56
 
557 chandransh 57
def to_t_cart(cart):
58
    t_cart = TCart()
59
    if cart:
60
        t_cart.id = cart.id
61
        t_cart.status = cart.cart_status
62
        lines = []
63
        if cart.lines:
64
            for line in cart.lines:
65
                lines.append(to_t_line(line))
66
        t_cart.lines = lines
1976 varun.gupt 67
        t_cart.totalPrice = cart.total_price
68
        t_cart.discountedPrice = cart.discounted_price
69
        t_cart.couponCode = cart.coupon_code
557 chandransh 70
        t_cart.createdOn = to_java_date(cart.created_on)
71
        t_cart.updatedOn = to_java_date(cart.updated_on)
72
        t_cart.addressId = cart.address_id
690 chandransh 73
        t_cart.checkedOutOn = to_java_date(cart.checked_out_on)
5555 rajveer 74
        t_cart.pickupStoreId = cart.pickupStoreId
557 chandransh 75
    return t_cart
76
 
612 chandransh 77
def to_t_line(line):
78
    t_line = TLine()
79
    if line:
643 chandransh 80
        t_line.cartId = line.cart_id
612 chandransh 81
        t_line.itemId = line.item_id
82
        t_line.quantity = line.quantity
83
        t_line.estimate = line.estimate
1976 varun.gupt 84
        t_line.actualPrice = line.actual_price
85
        t_line.discountedPrice = line.discounted_price
3554 varun.gupt 86
        t_line.discounts = [to_t_discount(discount) for discount in line.discounts]
612 chandransh 87
        t_line.createdOn = to_java_date(line.created_on)
88
        t_line.updatedOn = to_java_date(line.updated_on)
89
        t_line.lineStatus = line.line_status
6903 anupam.sin 90
        t_line.insurer = line.insurer
91
        t_line.insuranceAmount = line.insuranceAmount
612 chandransh 92
    return t_line
1583 varun.gupt 93
 
3554 varun.gupt 94
def to_t_discount(discount):
95
    t_discount = TDiscount()
96
 
97
    if discount:
98
        t_discount.cart_id = discount.line_cart_id
99
        t_discount.item_id = discount.line_item_id
100
        t_discount.discount = discount.discount
101
        t_discount.quantity = discount.quantity
102
 
103
    return t_discount
104
 
1583 varun.gupt 105
def to_t_user_communication(user_communication):
106
    t_user_communication = TUserCommunication()
107
 
108
    if user_communication:
109
        t_user_communication.id = user_communication.id
1603 varun.gupt 110
        t_user_communication.userId = user_communication.user_id
111
        t_user_communication.communicationType = user_communication.communication_type
112
        t_user_communication.orderId = user_communication.order_id
113
        t_user_communication.airwaybillNo = user_communication.airwaybill_no
114
        t_user_communication.replyTo = user_communication.reply_to
115
        t_user_communication.productName = user_communication.product_name
1583 varun.gupt 116
        t_user_communication.subject = user_communication.subject
117
        t_user_communication.message = user_communication.message
118
        t_user_communication.communication_timestamp = to_java_date(user_communication.communication_timestamp)
119
 
1845 vikas 120
    return t_user_communication
121
 
122
def to_t_master_affiliate(master_affiliate):
123
    t_master_affiliate = TMasterAffiliate()
124
 
125
    if master_affiliate:
126
        t_master_affiliate.id = master_affiliate.id
127
        t_master_affiliate.name = master_affiliate.name
1859 vikas 128
        t_master_affiliate.addedOn = to_java_date(master_affiliate.added_on)
1845 vikas 129
 
130
    return t_master_affiliate
131
 
132
def to_t_affiliate(affiliate):
133
    t_affiliate = TAffiliate()
134
 
135
    if affiliate:
136
        t_affiliate.id = affiliate.id
137
        t_affiliate.name = affiliate.name
138
        t_affiliate.url = affiliate.url
139
        t_affiliate.masterAffiliateId = affiliate.master_affiliate_id
1859 vikas 140
        t_affiliate.addedOn = to_java_date(affiliate.added_on)
1845 vikas 141
 
142
    return t_affiliate
143
 
144
def to_t_tracker(tracker):
145
    t_tracker = TTracker()
146
 
147
    if tracker:
148
        t_tracker.id = tracker.id
149
        t_tracker.affiliateId = tracker.affiliate_id
1997 vikas 150
        t_tracker.addedOn = to_java_date(tracker.added_on)
151
 
1845 vikas 152
    return t_tracker
153
 
154
def to_t_track_log(track_log):
155
    t_track_log = TTrackLog()
156
 
157
    if track_log:
158
        t_track_log.id = track_log.id
1996 vikas 159
        t_track_log.affiliateId = track_log.affiliate_id
1845 vikas 160
        t_track_log.userId = track_log.user_id
3378 vikas 161
        t_track_log.eventType = track_log.event_id
1845 vikas 162
        t_track_log.url = track_log.url
163
        t_track_log.data = track_log.data
1859 vikas 164
        t_track_log.addedOn = to_java_date(track_log.added_on)
1845 vikas 165
 
1976 varun.gupt 166
    return t_track_log
167
 
168
def to_t_promotion(promotion):
169
    t_promotion = TPromotion()
170
 
171
    if promotion:
172
        t_promotion.id = promotion.id
173
        t_promotion.name = promotion.name
174
        t_promotion.ruleExecutionSrc = promotion.rule_execution_src
175
        t_promotion.startOn = to_java_date(promotion.start_on)
6367 amit.gupta 176
        t_promotion.type = promotion.type
1976 varun.gupt 177
        t_promotion.endOn = to_java_date(promotion.end_on)
178
 
179
        #if promotion.coupons:
180
        #    t_promotion.coupons = [to_t_coupon(coupon) for coupon in promotion.coupons]
181
 
182
        t_promotion.createdOn = to_java_date(promotion.created_on)
183
    return t_promotion
184
 
185
def to_t_coupon(coupon):
186
    t_coupon = TCoupon()
187
 
188
    if coupon:
3386 varun.gupt 189
        t_coupon.couponCode = coupon.coupon_code
190
        t_coupon.promotion = to_t_promotion(coupon.promotion)
6571 amit.gupta 191
        t_coupon.arguments = coupon.arguments
1976 varun.gupt 192
 
1997 vikas 193
    return t_coupon
2641 varun.gupt 194
 
4189 varun.gupt 195
def to_t_item_coupon_discount(item_coupon_discount):
196
    t_item_coupon_discount = TItemCouponDiscount()
197
 
198
    if item_coupon_discount:
199
        t_item_coupon_discount.itemId = item_coupon_discount[0]
200
        t_item_coupon_discount.couponCode = item_coupon_discount[1]
201
        t_item_coupon_discount.discount = item_coupon_discount[2]
202
 
5469 rajveer 203
    return t_item_coupon_discount
204
 
205
def to_t_voucher(voucher):
206
    t_voucher = Voucher()
207
 
208
    if voucher:
209
        t_voucher.id = voucher.id
210
        t_voucher.voucherCode = voucher.voucherCode
211
        t_voucher.voucherType = voucher.voucherType
212
        t_voucher.issuedOn = to_java_date(voucher.issuedOn)
213
        t_voucher.expiredOn = to_java_date(voucher.expiredOn)
214
        t_voucher.amount = voucher.amount
215
        t_voucher.userEmail = voucher.email
216
    return t_voucher