| 94 |
ashish |
1 |
'''
|
|
|
2 |
Created on 22-Mar-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
from elixir import *
|
|
|
7 |
from elixir.entity import Entity
|
|
|
8 |
from elixir.fields import Field
|
|
|
9 |
from sqlalchemy.types import Integer
|
|
|
10 |
from elixir.relationships import OneToMany, ManyToOne
|
|
|
11 |
import datetime
|
|
|
12 |
|
|
|
13 |
|
| 103 |
ashish |
14 |
|
| 94 |
ashish |
15 |
class Warehouse(Entity):
|
| 122 |
ashish |
16 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 94 |
ashish |
17 |
location = Field(String(20))
|
| 103 |
ashish |
18 |
status = Field(Integer)
|
| 122 |
ashish |
19 |
addedOn = Field(DateTime)
|
| 94 |
ashish |
20 |
inventory = OneToMany('CurrentInventorySnapshot')
|
|
|
21 |
inventoryHistory = OneToMany('ItemInventoryHistory')
|
|
|
22 |
|
|
|
23 |
def __repr__(self):
|
|
|
24 |
return "<warehouse>%s</warehouse>" %(self.location)
|
|
|
25 |
|
| 122 |
ashish |
26 |
@property
|
|
|
27 |
def all_items(self):
|
|
|
28 |
items = []
|
|
|
29 |
for ci in self.inventory:
|
|
|
30 |
items.append(ci.item)
|
|
|
31 |
return items
|
|
|
32 |
|
| 94 |
ashish |
33 |
class Item(Entity):
|
| 122 |
ashish |
34 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
35 |
catalog_item_id = Field(Integer)
|
|
|
36 |
vendor_item_id = Field(Integer)
|
|
|
37 |
feature_id = Field(Integer)
|
|
|
38 |
feature_description = Field(String(200))
|
|
|
39 |
addedOn = Field(DateTime)
|
| 103 |
ashish |
40 |
status = Field(Integer)
|
| 122 |
ashish |
41 |
initDate = Field(DateTime)
|
|
|
42 |
startDate = Field(DateTime)
|
|
|
43 |
retireDate = Field(DateTime)
|
|
|
44 |
weight = Field(Float)
|
|
|
45 |
prices = OneToMany("Price")
|
| 94 |
ashish |
46 |
currentInventory = OneToMany('CurrentInventorySnapshot')
|
|
|
47 |
inventoryHistory = OneToMany('ItemInventoryHistory')
|
| 103 |
ashish |
48 |
iteminfo = OneToMany("ItemInfo")
|
|
|
49 |
statusChangeLog = OneToMany("ItemChangeLog")
|
|
|
50 |
|
| 94 |
ashish |
51 |
def __repr__(self):
|
| 122 |
ashish |
52 |
return "<Item>%d</item>" % (self.id)
|
| 94 |
ashish |
53 |
|
| 122 |
ashish |
54 |
@property
|
| 94 |
ashish |
55 |
def get_total_inventory(self):
|
|
|
56 |
if self.currentInventory:
|
|
|
57 |
i = 0
|
|
|
58 |
for entry in self.currentInventory:
|
|
|
59 |
i += entry.availability
|
|
|
60 |
return i
|
|
|
61 |
|
|
|
62 |
else:
|
|
|
63 |
return 0;
|
| 103 |
ashish |
64 |
|
| 122 |
ashish |
65 |
@property
|
| 94 |
ashish |
66 |
def get_all_warehouses(self):
|
|
|
67 |
warehouses = []
|
| 122 |
ashish |
68 |
for ci in self.currentInventory:
|
|
|
69 |
warehouses.append(ci.warehouse)
|
| 94 |
ashish |
70 |
return warehouses
|
| 122 |
ashish |
71 |
|
|
|
72 |
|
|
|
73 |
class Price(Entity):
|
|
|
74 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
75 |
price = Field(Float)
|
|
|
76 |
warehouse_id = Field(Integer)
|
|
|
77 |
item = ManyToOne("Item")
|
| 94 |
ashish |
78 |
|
| 122 |
ashish |
79 |
def __repr__(self):
|
|
|
80 |
return "<price><item_id> %d </item_id><warehouse_id> %d </warehouse_id><val> %f </val> </price>" % (self.item.id, self.warehouse_id, self.price)
|
|
|
81 |
|
| 115 |
ashish |
82 |
|
| 103 |
ashish |
83 |
class ItemInfo(Entity):
|
| 122 |
ashish |
84 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 103 |
ashish |
85 |
key = Field(String(30))
|
|
|
86 |
value = Field(String(100))
|
|
|
87 |
item = ManyToOne("Item")
|
|
|
88 |
|
|
|
89 |
def __repr__(self):
|
|
|
90 |
return "<ItemInfo><key>%s</key><value>%s</value></ItemInfo>" % (self.key, self.value)
|
| 115 |
ashish |
91 |
|
| 94 |
ashish |
92 |
|
|
|
93 |
class CurrentInventorySnapshot(Entity):
|
| 115 |
ashish |
94 |
#id = Field(Integer, primary_key=True)
|
| 122 |
ashish |
95 |
checkedOn = Field(DateTime, default=datetime.datetime.now())
|
| 94 |
ashish |
96 |
availibility = Field(Integer)
|
|
|
97 |
item = ManyToOne("Item")
|
|
|
98 |
warehouse = ManyToOne("Warehouse")
|
|
|
99 |
|
|
|
100 |
def __repr__(self):
|
|
|
101 |
return "<current inventory><availability> %s </availability><time>%s</time><item>%s</item><warehouse>%s</warehouse></current inventory>" %(self.availibility, self.checkedOn, self.item, self.warehouse)
|
|
|
102 |
|
|
|
103 |
class ItemInventoryHistory(Entity):
|
| 122 |
ashish |
104 |
id = Field(Integer, primary_key=True, autoincrement = True)
|
| 94 |
ashish |
105 |
timestamp = Field(DateTime, default=datetime.datetime.now())
|
|
|
106 |
availibility = Field(Integer)
|
|
|
107 |
item = ManyToOne("Item")
|
|
|
108 |
warehouse = ManyToOne("Warehouse")
|
|
|
109 |
|
|
|
110 |
def __repr__(self):
|
|
|
111 |
pass
|
| 103 |
ashish |
112 |
|
|
|
113 |
class ItemChangeLog(Entity):
|
| 122 |
ashish |
114 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 103 |
ashish |
115 |
old_status = Field(Integer)
|
|
|
116 |
new_status = Field(Integer)
|
| 122 |
ashish |
117 |
timestamp = Field(DateTime, default=datetime.datetime.now())
|
| 103 |
ashish |
118 |
item = ManyToOne("Item")
|
| 94 |
ashish |
119 |
|
| 103 |
ashish |
120 |
def __repr__(self):
|
|
|
121 |
return "<Log><id>%d</id><item>%d</item><old_status>%d</old_status><new_status>%d</new_status></Log>" %(self.id,self.item.id, self.old_status, self.new_status)
|
| 94 |
ashish |
122 |
|
| 103 |
ashish |
123 |
|
| 94 |
ashish |
124 |
def initialize():
|
| 384 |
ashish |
125 |
metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
|
| 94 |
ashish |
126 |
metadata.bind.echo = True
|
|
|
127 |
setup_all(True)
|
| 115 |
ashish |
128 |
|
|
|
129 |
if __name__=="__main__":
|
|
|
130 |
initialize()
|