Subversion Repositories SmartDukaan

Rev

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

'''
Created on 23-Mar-2010

@author: ashish
'''
from shop2020.thriftpy.model.v1.catalog.ttypes import  Item,\
    ItemInventory, Warehouse
import time
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.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
    
    if item.sellingPrice:
        t_item.sellingPrice = item.sellingPrice
    if item.dealerPrice:
        t_item.dealerPrice = item.dealerPrice    
    if item.mrp:
        t_item.mrp = item.mrp    
    if item.mop:
        t_item.mop = item.mop
    if item.transfer_price:
        t_item.transferPrice = item.transfer_price
    t_item.itemInventory = to_t_item_inventory(item.currentInventory, item.id)
    
    if item.bestDealText:
        t_item.bestDealText = item.bestDealText
    if item.bestDealValue:
        t_item.bestDealValue = item.bestDealValue
    
    t_item.otherInfo = to_t_other_info(item)
    return t_item

def to_t_other_info(item):
    t_other_info = {}
    for item_info in item.iteminfo:
        t_other_info[item_info.key] = item_info.value
    
def to_t_item_inventory(item_inventory_list, item_id):
    t_item_inventory = ItemInventory()
    t_item_inventory.id = item_id
    t_item_inventory.availability = {}
    for inventory_item in item_inventory_list:
        t_item_inventory.availability[inventory_item.warehouse.id] = inventory_item.availibility
#        need review again        
#        if inventory_item.checkedOn:
#            t_item_inventory.lastCheckedOn = to_java_date(inventory_item.checkedOn)
    return t_item_inventory

def to_t_warehouse(warehouse):
    t_warehouse = Warehouse()
    t_warehouse.id = warehouse.id
    t_warehouse.displayName = warehouse.displayName
    t_warehouse.location = warehouse.location
    t_warehouse.warehouseStatus = warehouse.status
    t_warehouse.tinNumber = warehouse.tinNumber
    t_warehouse.pincode = warehouse.pincode
    t_warehouse.vendor = warehouse.vendor.name
    if warehouse.vendorString:
        t_warehouse.vendorString = warehouse.vendorString
    if warehouse.addedOn:
        t_warehouse.addedOn = to_java_date(warehouse.addedOn)
    if warehouse.lastCheckedOn:
        t_warehouse.lastCheckedOn = to_java_date(warehouse.lastCheckedOn)
    return t_warehouse