Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
12790 amit.gupta 1
from shop2020.thriftpy.model.v1.user.ttypes import Address as TAddress, \
2
    UserCommunication as TUserCommunication, User as TUser, Cart as TCart, \
3
    Line as TLine, MasterAffiliate as TMasterAffiliate, Affiliate as TAffiliate, \
4
    Tracker as TTracker, TrackLog as TTrackLog, Promotion as TPromotion, \
5
    Coupon as TCoupon, Discount as TDiscount, \
6
    ItemCouponDiscount as TItemCouponDiscount, Voucher, CouponCategory, \
18530 manish.sha 7
    PrivateDealUser as TPrivateDealUser, Counter as TCounter, AccessTokenizer as TAccessTokenizer, \
20874 kshitij.so 8
    CounterOnlineInfo as TCounterOnlineInfo
12790 amit.gupta 9
from shop2020.utils.Utils import to_java_date
4189 varun.gupt 10
 
130 ashish 11
 
18742 manish.sha 12
def to_t_address(address, taxInvoice=False, credit_available=False):
130 ashish 13
    t_address = TAddress()
14
    t_address.id = address.id
15
    t_address.line1 = address.line_1
16
    t_address.line2 = address.line_2
17
    t_address.landmark = address.landmark
18
    t_address.city = address.city
19
    t_address.state = address.state
20
    t_address.pin = address.pin
21
    t_address.country = address.country
22
    t_address.enabled = address.enabled
23
    t_address.type = address.type
24
    t_address.addedOn = to_java_date(address.added_on)
414 ashish 25
    t_address.name = address.name
26
    t_address.phone = address.phone
18735 manish.sha 27
    t_address.taxInvoiceAvailable = taxInvoice
28
    t_address.creditOptionAvailable = credit_available
557 chandransh 29
    return t_address    
130 ashish 30
 
557 chandransh 31
def to_t_user(user):
32
    t_user = TUser()
576 chandransh 33
    if user is None:
34
        t_user.userId = -1
35
        return t_user
36
 
557 chandransh 37
    t_user.userId = user.id
38
    t_user.name = user.name
39
    t_user.email = user.email
619 rajveer 40
    t_user.password = user.password
557 chandransh 41
    t_user.sex = user.sex
42
 
43
    t_user.communicationEmail = user.communication_email
44
    t_user.defaultAddressId = user.default_address_id
45
    t_user.isAnonymous = user.is_anonymous
46
    t_user.activeCartId = user.active_cart_id
567 rajveer 47
    t_user.dateOfBirth = user.date_of_birth
48
    t_user.mobileNumber = user.mobile_number
2020 vikas 49
    t_user.source = user.source
2815 vikas 50
    t_user.sourceStartTime = to_java_date(user.source_start_time)
3499 mandeep.dh 51
    t_user.trustLevel = user.trust_level
5326 rajveer 52
    t_user.lastLogin = to_java_date(user.last_login)
53
    t_user.lastLogout = to_java_date(user.last_logout)
54
    t_user.activeSince = to_java_date(user.active_since)
7883 rajveer 55
    t_user.isFacebookUser = False
56
    if user.fbusers and user.fbusers[0]:
57
        t_user.isFacebookUser = True
58
        t_user.facebookAccessToken = user.fbusers[0].facebook_access_token
59
        t_user.facebookId = user.fbusers[0].facebook_id
8201 rajveer 60
 
61
    t_user.sourceId = 1
62
    #put source
63
    if user.sources and user.sources[0]:
64
        t_user.sourceId = user.sources[0].source_id
65
 
130 ashish 66
    #put all addresses
557 chandransh 67
    if user.addresses:
68
        t_user.addresses = list()
69
        for address in user.addresses:
70
            t_user.addresses.append(to_t_address(address))
71
    return t_user
513 rajveer 72
 
557 chandransh 73
def to_t_cart(cart):
74
    t_cart = TCart()
75
    if cart:
76
        t_cart.id = cart.id
77
        t_cart.status = cart.cart_status
78
        lines = []
79
        if cart.lines:
80
            for line in cart.lines:
81
                lines.append(to_t_line(line))
82
        t_cart.lines = lines
1976 varun.gupt 83
        t_cart.totalPrice = cart.total_price
84
        t_cart.discountedPrice = cart.discounted_price
85
        t_cart.couponCode = cart.coupon_code
557 chandransh 86
        t_cart.createdOn = to_java_date(cart.created_on)
87
        t_cart.updatedOn = to_java_date(cart.updated_on)
88
        t_cart.addressId = cart.address_id
690 chandransh 89
        t_cart.checkedOutOn = to_java_date(cart.checked_out_on)
5555 rajveer 90
        t_cart.pickupStoreId = cart.pickupStoreId
557 chandransh 91
    return t_cart
92
 
612 chandransh 93
def to_t_line(line):
94
    t_line = TLine()
95
    if line:
643 chandransh 96
        t_line.cartId = line.cart_id
612 chandransh 97
        t_line.itemId = line.item_id
98
        t_line.quantity = line.quantity
99
        t_line.estimate = line.estimate
1976 varun.gupt 100
        t_line.actualPrice = line.actual_price
101
        t_line.discountedPrice = line.discounted_price
3554 varun.gupt 102
        t_line.discounts = [to_t_discount(discount) for discount in line.discounts]
612 chandransh 103
        t_line.createdOn = to_java_date(line.created_on)
104
        t_line.updatedOn = to_java_date(line.updated_on)
105
        t_line.lineStatus = line.line_status
6903 anupam.sin 106
        t_line.insurer = line.insurer
107
        t_line.insuranceAmount = line.insuranceAmount
9299 kshitij.so 108
        t_line.dataProtectionInsurer = line.dataProtectionInsurer
109
        t_line.dataProtectionAmount = line.dataProtectionAmount
11656 amit.gupta 110
        t_line.freebieId = line.freebieId
111
        t_line.dealText = line.dealText
612 chandransh 112
    return t_line
1583 varun.gupt 113
 
3554 varun.gupt 114
def to_t_discount(discount):
115
    t_discount = TDiscount()
116
 
117
    if discount:
118
        t_discount.cart_id = discount.line_cart_id
119
        t_discount.item_id = discount.line_item_id
120
        t_discount.discount = discount.discount
121
        t_discount.quantity = discount.quantity
122
 
123
    return t_discount
124
 
1583 varun.gupt 125
def to_t_user_communication(user_communication):
126
    t_user_communication = TUserCommunication()
127
 
128
    if user_communication:
129
        t_user_communication.id = user_communication.id
1603 varun.gupt 130
        t_user_communication.userId = user_communication.user_id
131
        t_user_communication.communicationType = user_communication.communication_type
132
        t_user_communication.orderId = user_communication.order_id
133
        t_user_communication.airwaybillNo = user_communication.airwaybill_no
134
        t_user_communication.replyTo = user_communication.reply_to
135
        t_user_communication.productName = user_communication.product_name
1583 varun.gupt 136
        t_user_communication.subject = user_communication.subject
137
        t_user_communication.message = user_communication.message
138
        t_user_communication.communication_timestamp = to_java_date(user_communication.communication_timestamp)
139
 
1845 vikas 140
    return t_user_communication
141
 
142
def to_t_master_affiliate(master_affiliate):
143
    t_master_affiliate = TMasterAffiliate()
144
 
145
    if master_affiliate:
146
        t_master_affiliate.id = master_affiliate.id
147
        t_master_affiliate.name = master_affiliate.name
1859 vikas 148
        t_master_affiliate.addedOn = to_java_date(master_affiliate.added_on)
1845 vikas 149
 
150
    return t_master_affiliate
151
 
152
def to_t_affiliate(affiliate):
153
    t_affiliate = TAffiliate()
154
 
155
    if affiliate:
156
        t_affiliate.id = affiliate.id
157
        t_affiliate.name = affiliate.name
158
        t_affiliate.url = affiliate.url
159
        t_affiliate.masterAffiliateId = affiliate.master_affiliate_id
1859 vikas 160
        t_affiliate.addedOn = to_java_date(affiliate.added_on)
1845 vikas 161
 
162
    return t_affiliate
163
 
164
def to_t_tracker(tracker):
165
    t_tracker = TTracker()
166
 
167
    if tracker:
168
        t_tracker.id = tracker.id
169
        t_tracker.affiliateId = tracker.affiliate_id
1997 vikas 170
        t_tracker.addedOn = to_java_date(tracker.added_on)
171
 
1845 vikas 172
    return t_tracker
173
 
174
def to_t_track_log(track_log):
175
    t_track_log = TTrackLog()
176
 
177
    if track_log:
178
        t_track_log.id = track_log.id
1996 vikas 179
        t_track_log.affiliateId = track_log.affiliate_id
1845 vikas 180
        t_track_log.userId = track_log.user_id
3378 vikas 181
        t_track_log.eventType = track_log.event_id
1845 vikas 182
        t_track_log.url = track_log.url
183
        t_track_log.data = track_log.data
1859 vikas 184
        t_track_log.addedOn = to_java_date(track_log.added_on)
1845 vikas 185
 
1976 varun.gupt 186
    return t_track_log
187
 
188
def to_t_promotion(promotion):
189
    t_promotion = TPromotion()
190
 
191
    if promotion:
192
        t_promotion.id = promotion.id
193
        t_promotion.name = promotion.name
194
        t_promotion.ruleExecutionSrc = promotion.rule_execution_src
195
        t_promotion.startOn = to_java_date(promotion.start_on)
6367 amit.gupta 196
        t_promotion.type = promotion.type
1976 varun.gupt 197
        t_promotion.endOn = to_java_date(promotion.end_on)
198
 
199
        #if promotion.coupons:
200
        #    t_promotion.coupons = [to_t_coupon(coupon) for coupon in promotion.coupons]
201
 
202
        t_promotion.createdOn = to_java_date(promotion.created_on)
203
    return t_promotion
204
 
205
def to_t_coupon(coupon):
206
    t_coupon = TCoupon()
207
 
208
    if coupon:
3386 varun.gupt 209
        t_coupon.couponCode = coupon.coupon_code
210
        t_coupon.promotion = to_t_promotion(coupon.promotion)
6571 amit.gupta 211
        t_coupon.arguments = coupon.arguments
8707 manish.sha 212
        if coupon.coupon_category:
213
            t_coupon.coupon_category = CouponCategory._NAMES_TO_VALUES[coupon.coupon_category]
1976 varun.gupt 214
 
1997 vikas 215
    return t_coupon
2641 varun.gupt 216
 
4189 varun.gupt 217
def to_t_item_coupon_discount(item_coupon_discount):
218
    t_item_coupon_discount = TItemCouponDiscount()
219
 
220
    if item_coupon_discount:
221
        t_item_coupon_discount.itemId = item_coupon_discount[0]
222
        t_item_coupon_discount.couponCode = item_coupon_discount[1]
223
        t_item_coupon_discount.discount = item_coupon_discount[2]
224
 
5469 rajveer 225
    return t_item_coupon_discount
226
 
227
def to_t_voucher(voucher):
228
    t_voucher = Voucher()
229
 
230
    if voucher:
231
        t_voucher.id = voucher.id
232
        t_voucher.voucherCode = voucher.voucherCode
233
        t_voucher.voucherType = voucher.voucherType
234
        t_voucher.issuedOn = to_java_date(voucher.issuedOn)
235
        t_voucher.expiredOn = to_java_date(voucher.expiredOn)
236
        t_voucher.amount = voucher.amount
237
        t_voucher.userEmail = voucher.email
11890 kshitij.so 238
    return t_voucher
239
 
12790 amit.gupta 240
def to_t_private_deal_user(privateDealUser):
241
    t_private_deal_user = TPrivateDealUser()
242
    if privateDealUser is not None:
243
        t_private_deal_user.userId = privateDealUser.id
244
        t_private_deal_user.addedOn = to_java_date(privateDealUser.created_on)
245
        t_private_deal_user.isActive = privateDealUser.isActive
246
        t_private_deal_user.tin = privateDealUser.tin
13007 amit.gupta 247
        if privateDealUser.counter is not None:
248
            t_private_deal_user.counterId = privateDealUser.counter.id
13146 manish.sha 249
        if privateDealUser.bulkShipmentAmountLimit:
250
            t_private_deal_user.bulkShipmentAmountLimit = privateDealUser.bulkShipmentAmountLimit
18590 manish.sha 251
        t_private_deal_user.creditorAssigned = privateDealUser.creditorAssigned
18735 manish.sha 252
        t_private_deal_user.tinVerified = privateDealUser.tinVerified
12790 amit.gupta 253
    return t_private_deal_user
12722 amit.gupta 254
 
255
def to_t_counter(counter):
18980 amit.gupta 256
    t_counter = TCounter()
18977 amit.gupta 257
    if counter:
258
        t_counter.code = counter.code
259
        t_counter.addedOn = to_java_date(counter.createdOn)
260
        t_counter.alternateMobile = counter.alternateMobile
261
        t_counter.mobile = counter.mobile
262
        t_counter.dob = counter.dob
263
        t_counter.name  = counter.name
264
        t_counter.ownerName = counter.ownerName
265
        t_counter.id = counter.id
266
        t_counter.address = counter.addressId
267
        t_counter.email = counter.email
268
        t_counter.fpCounterSize = counter.fpCounterSize
269
        t_counter.spCounterSize = counter.spCounterSize
270
        t_counter.striker  = counter.striker
271
        t_counter.tin = counter.tin
21908 amit.gupta 272
        t_counter.gstin = counter.gstin
18977 amit.gupta 273
        t_counter.documentVerified = counter.documentVerified
274
        t_counter.verificationType = counter.verificationType
275
        t_counter.verifiedOn = to_java_date(counter.verifiedOn)
276
    else:
18980 amit.gupta 277
        t_counter.id = -1
278
    return t_counter
15251 manish.sha 279
 
280
def to_t_accessTokenizer(accessTokenizer):
281
    t_accessTokenizer = TAccessTokenizer()
282
    if accessTokenizer is None:
283
        return t_accessTokenizer
284
    t_accessTokenizer.id = accessTokenizer.id
285
    t_accessTokenizer.userId = accessTokenizer.userId
286
    t_accessTokenizer.source = accessTokenizer.source
287
    t_accessTokenizer.tokenString = accessTokenizer.tokenString
288
    t_accessTokenizer.expiredTime = to_java_date(accessTokenizer.expiredTime)
289
    t_accessTokenizer.expired = accessTokenizer.expired
18530 manish.sha 290
    return t_accessTokenizer
291
 
292
def to_t_counterOnlineInfo(counterInfo):
293
    t_counterOnlineInfo = TCounterOnlineInfo()
294
    t_counterOnlineInfo.counterId = counterInfo.counterId
295
    t_counterOnlineInfo.cstNumber = counterInfo.cstNumber
296
    t_counterOnlineInfo.dealerAddress = counterInfo.dealerAddress
297
    t_counterOnlineInfo.dealerName = counterInfo.dealerName
298
    t_counterOnlineInfo.pan = counterInfo.pan
299
    t_counterOnlineInfo.registrationDate = to_java_date(counterInfo.registrationDate)
300
    t_counterOnlineInfo.registrationStatus = counterInfo.registrationStatus
301
    t_counterOnlineInfo.state = counterInfo.state
302
    t_counterOnlineInfo.tinNumber = counterInfo.tinNumber
303
    t_counterOnlineInfo.validatedTill = to_java_date(counterInfo.validatedTill)
18634 manish.sha 304
    t_counterOnlineInfo.created = to_java_date(counterInfo.created)
20873 kshitij.so 305
    return t_counterOnlineInfo