Subversion Repositories SmartDukaan

Rev

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