Subversion Repositories SmartDukaan

Rev

Rev 103 | Rev 386 | 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()
    t_item.id = item.id
    t_item.catalogItemId = item.catalog_item_id
    t_item.vendorItemId = item.vendor_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)
    t_item.itemStatus = item.status
    t_item.itemInventory = to_t_item_inventory(item.currentInventory, item.id)
    
    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
        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.location = warehouse.location
    t_warehouse.warehouseStatus = warehouse.status
    if warehouse.addedOn:
        t_warehouse.addedOn = to_java_date(warehouse.addedOn)
    return t_warehouse