| 94 |
ashish |
1 |
'''
|
|
|
2 |
Created on 23-Mar-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
from shop2020.thriftpy.model.v1.catalog.ttypes import Category, Item,\
|
| 103 |
ashish |
7 |
ItemInventory, Warehouse, Vendor
|
| 94 |
ashish |
8 |
import time
|
|
|
9 |
|
|
|
10 |
def to_t_category(category):
|
|
|
11 |
t_category = Category()
|
|
|
12 |
t_category.id = category.id
|
|
|
13 |
t_category.name = category.name
|
|
|
14 |
t_category.isTopLevel = False
|
|
|
15 |
if category.isRoot == 1:
|
|
|
16 |
t_category.isTopLevel = True
|
| 100 |
ashish |
17 |
t_category.addedOn = int(time.mktime(category.addedOn.timetuple()))
|
| 94 |
ashish |
18 |
|
|
|
19 |
if category.parent:
|
|
|
20 |
t_category.parent_id = category.parent.id
|
|
|
21 |
if category.children:
|
|
|
22 |
t_category.childCategories = []
|
|
|
23 |
for child in category.children:
|
|
|
24 |
t_category.childCategories.append(child.id)
|
|
|
25 |
return t_category
|
|
|
26 |
|
|
|
27 |
def to_t_item(item):
|
|
|
28 |
t_item = Item()
|
|
|
29 |
t_item.id = item.id
|
|
|
30 |
t_item.category_id = item.category.id
|
|
|
31 |
t_item.itemInventory = to_t_item_inventory(item.currentInventory, item.id)
|
|
|
32 |
return t_item
|
|
|
33 |
|
|
|
34 |
def to_t_item_inventory(item_inventory_list, item_id):
|
|
|
35 |
t_item_inventory = ItemInventory()
|
|
|
36 |
t_item_inventory.id = item_id
|
|
|
37 |
t_item_inventory.availability = {}
|
|
|
38 |
for inventory_item in item_inventory_list:
|
|
|
39 |
t_item_inventory.availability[inventory_item.Warehouse.id] = inventory_item.availibility
|
|
|
40 |
#TODO:- populate itemattribs here
|
|
|
41 |
return t_item_inventory
|
|
|
42 |
|
|
|
43 |
def to_t_warehouse(warehouse):
|
|
|
44 |
t_warehouse = Warehouse()
|
|
|
45 |
t_warehouse.id = warehouse.id
|
|
|
46 |
t_warehouse.location = warehouse.location
|
|
|
47 |
#todo - add vendors as well here
|
|
|
48 |
|
| 103 |
ashish |
49 |
def to_t_vendor(vendor):
|
|
|
50 |
t_vendor = Vendor()
|
|
|
51 |
t_vendor.id = vendor.id
|
|
|
52 |
t_vendor.name = vendor.name
|
|
|
53 |
|