Subversion Repositories SmartDukaan

Rev

Rev 7281 | Rev 7367 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 23-Mar-2010

@author: ashish
'''
from shop2020.model.v1.catalog.impl.DataService import Insurer
from shop2020.thriftpy.model.v1.catalog.ttypes import Item, Category, \
    SourceItemPricing, Source, ItemType, \
    ProductNotificationRequest as TProductNotificationRequest, \
    ProductNotificationRequestCount as TProductNotificationRequestCount, \
    VoucherItemMapping, EntityTag as TEntityTag, Banner as TBanner, BannerMap as TBannerMap, \
    Insurer as TInsurer, BrandInfo as TBrandInfo, Amazonlisted as TAmazonlisted
from shop2020.utils.Utils import to_java_date

def to_t_item(item):
    t_item = Item()
    if item is None:
        return t_item
    t_item.id = item.id
    t_item.productGroup = item.product_group
    t_item.brand = item.brand
    t_item.modelNumber = item.model_number
    t_item.modelName = item.model_name
    t_item.color = item.color
    t_item.category = item.category
    t_item.catalogItemId = item.catalog_item_id
    t_item.weight = item.weight
    t_item.featureId = item.feature_id
    t_item.featureDescription = item.feature_description
    if item.startDate:
        t_item.startDate = to_java_date(item.startDate)
    if item.comingSoonStartDate:
        t_item.comingSoonStartDate = to_java_date(item.comingSoonStartDate)
    if item.expectedArrivalDate:
        t_item.expectedArrivalDate = to_java_date(item.expectedArrivalDate)
    if item.addedOn:
        t_item.addedOn = to_java_date(item.addedOn)
    if item.updatedOn:
        t_item.updatedOn = to_java_date(item.updatedOn)
    t_item.itemStatus = item.status
    t_item.status_description = item.status_description
    if item.sellingPrice:
        t_item.sellingPrice = item.sellingPrice
    if item.mrp:
        t_item.mrp = item.mrp    
    
    if item.comments:
        t_item.comments = item.comments
    if item.bestDealText:
        t_item.bestDealText = item.bestDealText
    if item.bestDealsDetailsText:
        t_item.bestDealsDetailsText = item.bestDealsDetailsText
    if item.bestDealsDetailsLink:
        t_item.bestDealsDetailsLink = item.bestDealsDetailsLink 
    if item.bestDealValue:
        t_item.bestDealValue = item.bestDealValue
    if item.asin:
        t_item.asin = item.asin    
    t_item.defaultForEntity = item.defaultForEntity
    t_item.bestSellingRank = item.bestSellingRank
    t_item.risky = item.risky
    t_item.expectedDelay = item.expectedDelay
    t_item.isWarehousePreferenceSticky = item.isWarehousePreferenceSticky
    t_item.warrantyPeriod = item.warranty_period
    t_item.preferredVendor = item.preferredVendor
    t_item.type = ItemType._NAMES_TO_VALUES[item.type]
    t_item.hasItemNo = item.hasItemNo
    t_item.activeOnStore = item.activeOnStore
    t_item.showSellingPrice = item.showSellingPrice
    t_item.preferredInsurer = item.preferredInsurer
    t_item.holdInventory = item.holdInventory
    t_item.defaultInventory = item.defaultInventory
    return t_item

def to_t_insurer(insurer):
    t_insurer = TInsurer()
    t_insurer.id = insurer.id
    t_insurer.name = insurer.name 
    t_insurer.address = insurer.address
    t_insurer.declaredAmount = insurer.declaredAmount
    t_insurer.creditedAmount = insurer.creditedAmount
    return t_insurer

def to_t_voucher_item_mapping(voucher):
    t_voucher = VoucherItemMapping()
    t_voucher.voucherType = voucher.voucherType
    t_voucher.itemId = voucher.item.id
    t_voucher.amount = voucher.amount
    return t_voucher

def to_t_category(category):
    t_category = Category()
    t_category.id = category.id
    t_category.label = category.label
    t_category.description = category.description
    t_category.parent_category_id = category.parent_category_id
    t_category.display_name = category.display_name
    return t_category

def to_t_source_item_pricing(source_item_pricing):
    t_source_item_pricing = SourceItemPricing()
    t_source_item_pricing.sourceId = source_item_pricing.source.id
    t_source_item_pricing.itemId = source_item_pricing.item.id
    t_source_item_pricing.mrp = source_item_pricing.mrp
    t_source_item_pricing.sellingPrice = source_item_pricing.sellingPrice
    return t_source_item_pricing

def to_t_source(source):
    t_source = Source()
    t_source.id = source.id
    t_source.name = source.name
    t_source.identifier = source.identifier
    return t_source

def to_t_product_notification_request(product_notification_request):
    t_product_notification_request = TProductNotificationRequest()
    
    if product_notification_request:
        t_product_notification_request.item = to_t_item(product_notification_request.item)
        t_product_notification_request.email = product_notification_request.email
        t_product_notification_request.addedOn = to_java_date(product_notification_request.addedOn)
    
    return t_product_notification_request

def to_t_product_notification_request_count(product_notification_request_count):
    
    t_product_notification_request_count = TProductNotificationRequestCount()
    
    if product_notification_request_count:
        item, count = product_notification_request_count
        t_product_notification_request_count.item = to_t_item(item)
        t_product_notification_request_count.count = count
    
    return t_product_notification_request_count

def to_t_entity_tag(entity_tag):
    t_entity_tag = TEntityTag()
    t_entity_tag.entityId = entity_tag.entityId
    t_entity_tag.tag = entity_tag.tag
    
def to_t_banner(banner):
    t_banner = TBanner()
    t_banner.bannerName = banner.bannerName
    t_banner.imageName = banner.imageName
    t_banner.link = banner.link
    t_banner.priority = banner.priority
    t_banner.isActive = banner.isActive
    t_banner.hasMap = banner.hasMap
    return t_banner

def to_t_banner_map(banner_map):
    t_banner_map = TBannerMap()
    t_banner_map.bannerName = banner_map.bannerName
    t_banner_map.mapLink = banner_map.mapLink
    t_banner_map.coordinates = banner_map.coordinates
    return t_banner_map

def to_t_Amazonlisted(Amazonlisted):
    t_amazonlisted = TAmazonlisted()
    t_amazonlisted.asin = Amazonlisted.asin
    t_amazonlisted.brand = Amazonlisted.brand 
    t_amazonlisted.itemid = Amazonlisted.itemId
    t_amazonlisted.model = Amazonlisted.model
    t_amazonlisted.manufacturer_name = Amazonlisted.manufacturer_name
    t_amazonlisted.upc = Amazonlisted.upc
    t_amazonlisted.part_number = Amazonlisted.part_number
    t_amazonlisted.name = Amazonlisted.name
    t_amazonlisted.ean = Amazonlisted.ean
    t_amazonlisted.fbaPrice = Amazonlisted.fbaPrice
    t_amazonlisted.sellingPrice = Amazonlisted.sellingPrice
    t_amazonlisted.isFba = Amazonlisted.isFba
    t_amazonlisted.isNonFba = Amazonlisted.isNonFba
    t_amazonlisted.isInventoryOverride = Amazonlisted.isInventoryOverride
    t_amazonlisted.color = Amazonlisted.color
    t_amazonlisted.category = Amazonlisted.category
    return t_amazonlisted