Subversion Repositories SmartDukaan

Rev

Rev 21908 | Blame | Compare with Previous | Last modification | View Log | RSS feed

from shop2020.thriftpy.model.v1.user.ttypes import Address as TAddress, \
    UserCommunication as TUserCommunication, User as TUser, Cart as TCart, \
    Line as TLine, MasterAffiliate as TMasterAffiliate, Affiliate as TAffiliate, \
    Tracker as TTracker, TrackLog as TTrackLog, Promotion as TPromotion, \
    Coupon as TCoupon, Discount as TDiscount, \
    ItemCouponDiscount as TItemCouponDiscount, Voucher, CouponCategory, \
    PrivateDealUser as TPrivateDealUser, Counter as TCounter, AccessTokenizer as TAccessTokenizer, \
    CounterOnlineInfo as TCounterOnlineInfo
from shop2020.utils.Utils import to_java_date
    

def to_t_address(address, taxInvoice=False, credit_available=False):
    t_address = TAddress()
    t_address.id = address.id
    t_address.line1 = address.line_1
    t_address.line2 = address.line_2
    t_address.landmark = address.landmark
    t_address.city = address.city
    t_address.state = address.state
    t_address.pin = address.pin
    t_address.country = address.country
    t_address.enabled = address.enabled
    t_address.type = address.type
    t_address.addedOn = to_java_date(address.added_on)
    t_address.name = address.name
    t_address.phone = address.phone
    t_address.taxInvoiceAvailable = taxInvoice
    t_address.creditOptionAvailable = credit_available
    return t_address    

def to_t_user(user):
    t_user = TUser()
    if user is None:
        t_user.userId = -1
        return t_user
    
    t_user.userId = user.id
    t_user.name = user.name
    t_user.email = user.email
    t_user.password = user.password
    t_user.sex = user.sex

    t_user.communicationEmail = user.communication_email
    t_user.defaultAddressId = user.default_address_id
    t_user.isAnonymous = user.is_anonymous
    t_user.activeCartId = user.active_cart_id
    t_user.dateOfBirth = user.date_of_birth
    t_user.mobileNumber = user.mobile_number
    t_user.source = user.source
    t_user.sourceStartTime = to_java_date(user.source_start_time)
    t_user.trustLevel = user.trust_level
    t_user.lastLogin = to_java_date(user.last_login)
    t_user.lastLogout = to_java_date(user.last_logout)
    t_user.activeSince = to_java_date(user.active_since)
    t_user.isFacebookUser = False
    if user.fbusers and user.fbusers[0]:
        t_user.isFacebookUser = True
        t_user.facebookAccessToken = user.fbusers[0].facebook_access_token
        t_user.facebookId = user.fbusers[0].facebook_id
    
    t_user.sourceId = 1
    #put source
    if user.sources and user.sources[0]:
        t_user.sourceId = user.sources[0].source_id
        
    #put all addresses
    if user.addresses:
        t_user.addresses = list()
        for address in user.addresses:
            t_user.addresses.append(to_t_address(address))
    return t_user

def to_t_cart(cart):
    t_cart = TCart()
    if cart:
        t_cart.id = cart.id
        t_cart.status = cart.cart_status
        lines = []
        if cart.lines:
            for line in cart.lines:
                lines.append(to_t_line(line))
        t_cart.lines = lines
        t_cart.totalPrice = cart.total_price
        t_cart.discountedPrice = cart.discounted_price
        t_cart.couponCode = cart.coupon_code
        t_cart.createdOn = to_java_date(cart.created_on)
        t_cart.updatedOn = to_java_date(cart.updated_on)
        t_cart.addressId = cart.address_id
        t_cart.checkedOutOn = to_java_date(cart.checked_out_on)
        t_cart.pickupStoreId = cart.pickupStoreId
    return t_cart
    
def to_t_line(line):
    t_line = TLine()
    if line:
        t_line.cartId = line.cart_id
        t_line.itemId = line.item_id
        t_line.quantity = line.quantity
        t_line.estimate = line.estimate
        t_line.actualPrice = line.actual_price
        t_line.discountedPrice = line.discounted_price
        t_line.discounts = [to_t_discount(discount) for discount in line.discounts]
        t_line.createdOn = to_java_date(line.created_on)
        t_line.updatedOn = to_java_date(line.updated_on)
        t_line.lineStatus = line.line_status
        t_line.insurer = line.insurer
        t_line.insuranceAmount = line.insuranceAmount
        t_line.dataProtectionInsurer = line.dataProtectionInsurer
        t_line.dataProtectionAmount = line.dataProtectionAmount
        t_line.freebieId = line.freebieId
        t_line.dealText = line.dealText
    return t_line

def to_t_discount(discount):
    t_discount = TDiscount()
    
    if discount:
        t_discount.cart_id = discount.line_cart_id
        t_discount.item_id = discount.line_item_id
        t_discount.discount = discount.discount
        t_discount.quantity = discount.quantity
    
    return t_discount

def to_t_user_communication(user_communication):
    t_user_communication = TUserCommunication()
    
    if user_communication:
        t_user_communication.id = user_communication.id
        t_user_communication.userId = user_communication.user_id
        t_user_communication.communicationType = user_communication.communication_type
        t_user_communication.orderId = user_communication.order_id
        t_user_communication.airwaybillNo = user_communication.airwaybill_no
        t_user_communication.replyTo = user_communication.reply_to
        t_user_communication.productName = user_communication.product_name
        t_user_communication.subject = user_communication.subject
        t_user_communication.message = user_communication.message
        t_user_communication.communication_timestamp = to_java_date(user_communication.communication_timestamp)
        
    return t_user_communication

def to_t_master_affiliate(master_affiliate):
    t_master_affiliate = TMasterAffiliate()
    
    if master_affiliate:
        t_master_affiliate.id = master_affiliate.id
        t_master_affiliate.name = master_affiliate.name
        t_master_affiliate.addedOn = to_java_date(master_affiliate.added_on)

    return t_master_affiliate

def to_t_affiliate(affiliate):
    t_affiliate = TAffiliate()
    
    if affiliate:
        t_affiliate.id = affiliate.id
        t_affiliate.name = affiliate.name
        t_affiliate.url = affiliate.url
        t_affiliate.masterAffiliateId = affiliate.master_affiliate_id
        t_affiliate.addedOn = to_java_date(affiliate.added_on)
        
    return t_affiliate

def to_t_tracker(tracker):
    t_tracker = TTracker()
    
    if tracker:
        t_tracker.id = tracker.id
        t_tracker.affiliateId = tracker.affiliate_id
        t_tracker.addedOn = to_java_date(tracker.added_on)
    
    return t_tracker

def to_t_track_log(track_log):
    t_track_log = TTrackLog()
    
    if track_log:
        t_track_log.id = track_log.id
        t_track_log.affiliateId = track_log.affiliate_id
        t_track_log.userId = track_log.user_id
        t_track_log.eventType = track_log.event_id
        t_track_log.url = track_log.url
        t_track_log.data = track_log.data
        t_track_log.addedOn = to_java_date(track_log.added_on)

    return t_track_log

def to_t_promotion(promotion):
    t_promotion = TPromotion()
    
    if promotion:
        t_promotion.id = promotion.id
        t_promotion.name = promotion.name
        t_promotion.ruleExecutionSrc = promotion.rule_execution_src
        t_promotion.startOn = to_java_date(promotion.start_on)
        t_promotion.type = promotion.type
        t_promotion.endOn = to_java_date(promotion.end_on)
        
        #if promotion.coupons:
        #    t_promotion.coupons = [to_t_coupon(coupon) for coupon in promotion.coupons]
        
        t_promotion.createdOn = to_java_date(promotion.created_on)
    return t_promotion

def to_t_coupon(coupon):
    t_coupon = TCoupon()

    if coupon:
        t_coupon.couponCode = coupon.coupon_code
        t_coupon.promotion = to_t_promotion(coupon.promotion)
        t_coupon.arguments = coupon.arguments
        if coupon.coupon_category:
            t_coupon.coupon_category = CouponCategory._NAMES_TO_VALUES[coupon.coupon_category]
    
    return t_coupon

def to_t_item_coupon_discount(item_coupon_discount):
    t_item_coupon_discount = TItemCouponDiscount()
    
    if item_coupon_discount:
        t_item_coupon_discount.itemId = item_coupon_discount[0]
        t_item_coupon_discount.couponCode = item_coupon_discount[1]
        t_item_coupon_discount.discount = item_coupon_discount[2]
    
    return t_item_coupon_discount

def to_t_voucher(voucher):
    t_voucher = Voucher()
    
    if voucher:
        t_voucher.id = voucher.id
        t_voucher.voucherCode = voucher.voucherCode
        t_voucher.voucherType = voucher.voucherType
        t_voucher.issuedOn = to_java_date(voucher.issuedOn)
        t_voucher.expiredOn = to_java_date(voucher.expiredOn)
        t_voucher.amount = voucher.amount
        t_voucher.userEmail = voucher.email
    return t_voucher

def to_t_private_deal_user(privateDealUser):
    t_private_deal_user = TPrivateDealUser()
    if privateDealUser is not None:
        t_private_deal_user.userId = privateDealUser.id
        t_private_deal_user.addedOn = to_java_date(privateDealUser.created_on)
        t_private_deal_user.isActive = privateDealUser.isActive
        t_private_deal_user.tin = privateDealUser.tin
        if privateDealUser.counter is not None:
            t_private_deal_user.counterId = privateDealUser.counter.id
        if privateDealUser.bulkShipmentAmountLimit:
            t_private_deal_user.bulkShipmentAmountLimit = privateDealUser.bulkShipmentAmountLimit
        t_private_deal_user.creditorAssigned = privateDealUser.creditorAssigned
        t_private_deal_user.tinVerified = privateDealUser.tinVerified
        t_private_deal_user.isFofo = privateDealUser.isFofo
    return t_private_deal_user

def to_t_counter(counter):
    t_counter = TCounter()
    if counter:
        t_counter.code = counter.code
        t_counter.addedOn = to_java_date(counter.createdOn)
        t_counter.alternateMobile = counter.alternateMobile
        t_counter.mobile = counter.mobile
        t_counter.dob = counter.dob
        t_counter.name  = counter.name
        t_counter.ownerName = counter.ownerName
        t_counter.id = counter.id
        t_counter.address = counter.addressId
        t_counter.email = counter.email
        t_counter.fpCounterSize = counter.fpCounterSize
        t_counter.spCounterSize = counter.spCounterSize
        t_counter.striker  = counter.striker
        t_counter.tin = counter.tin
        t_counter.gstin = counter.gstin
        t_counter.documentVerified = counter.documentVerified
        t_counter.verificationType = counter.verificationType
        t_counter.verifiedOn = to_java_date(counter.verifiedOn)
    else:
        t_counter.id = -1
    return t_counter

def to_t_accessTokenizer(accessTokenizer):
    t_accessTokenizer = TAccessTokenizer()
    if accessTokenizer is None:
        return t_accessTokenizer
    t_accessTokenizer.id = accessTokenizer.id
    t_accessTokenizer.userId = accessTokenizer.userId
    t_accessTokenizer.source = accessTokenizer.source
    t_accessTokenizer.tokenString = accessTokenizer.tokenString
    t_accessTokenizer.expiredTime = to_java_date(accessTokenizer.expiredTime)
    t_accessTokenizer.expired = accessTokenizer.expired
    return t_accessTokenizer

def to_t_counterOnlineInfo(counterInfo):
    t_counterOnlineInfo = TCounterOnlineInfo()
    t_counterOnlineInfo.counterId = counterInfo.counterId
    t_counterOnlineInfo.cstNumber = counterInfo.cstNumber
    t_counterOnlineInfo.dealerAddress = counterInfo.dealerAddress
    t_counterOnlineInfo.dealerName = counterInfo.dealerName
    t_counterOnlineInfo.pan = counterInfo.pan
    t_counterOnlineInfo.registrationDate = to_java_date(counterInfo.registrationDate)
    t_counterOnlineInfo.registrationStatus = counterInfo.registrationStatus
    t_counterOnlineInfo.state = counterInfo.state
    t_counterOnlineInfo.tinNumber = counterInfo.tinNumber
    t_counterOnlineInfo.validatedTill = to_java_date(counterInfo.validatedTill)
    t_counterOnlineInfo.created = to_java_date(counterInfo.created)
    return t_counterOnlineInfo