Subversion Repositories SmartDukaan

Rev

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