| 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)
|
| 483 |
rajveer |
17 |
location = Field(String(200))
|
| 103 |
ashish |
18 |
status = Field(Integer)
|
| 122 |
ashish |
19 |
addedOn = Field(DateTime)
|
| 483 |
rajveer |
20 |
lastCheckedOn = Field(DateTime)
|
|
|
21 |
tinNumber = Field(String(50))
|
|
|
22 |
pincode = Field(String(10))
|
|
|
23 |
vendorString = Field(String(50))
|
| 94 |
ashish |
24 |
inventory = OneToMany('CurrentInventorySnapshot')
|
|
|
25 |
inventoryHistory = OneToMany('ItemInventoryHistory')
|
|
|
26 |
|
|
|
27 |
def __repr__(self):
|
|
|
28 |
return "<warehouse>%s</warehouse>" %(self.location)
|
|
|
29 |
|
| 122 |
ashish |
30 |
@property
|
|
|
31 |
def all_items(self):
|
|
|
32 |
items = []
|
|
|
33 |
for ci in self.inventory:
|
|
|
34 |
items.append(ci.item)
|
|
|
35 |
return items
|
|
|
36 |
|
| 94 |
ashish |
37 |
class Item(Entity):
|
| 122 |
ashish |
38 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 483 |
rajveer |
39 |
manufacturer_name = Field(String(100))
|
|
|
40 |
model_number = Field(String(50))
|
|
|
41 |
model_name = Field(String(50))
|
|
|
42 |
category = Field(String(50))
|
|
|
43 |
comments = Field(String(200))
|
| 122 |
ashish |
44 |
catalog_item_id = Field(Integer)
|
| 483 |
rajveer |
45 |
vendor_item_id = Field(String(50))
|
| 122 |
ashish |
46 |
feature_id = Field(Integer)
|
|
|
47 |
feature_description = Field(String(200))
|
| 483 |
rajveer |
48 |
mrp = Field(Float)
|
|
|
49 |
mop = Field(Float)
|
|
|
50 |
sellingPrice = Field(Float)
|
|
|
51 |
weight = Field(Float)
|
| 122 |
ashish |
52 |
addedOn = Field(DateTime)
|
|
|
53 |
startDate = Field(DateTime)
|
|
|
54 |
retireDate = Field(DateTime)
|
| 483 |
rajveer |
55 |
status = Field(Integer)
|
| 94 |
ashish |
56 |
currentInventory = OneToMany('CurrentInventorySnapshot')
|
|
|
57 |
inventoryHistory = OneToMany('ItemInventoryHistory')
|
| 103 |
ashish |
58 |
iteminfo = OneToMany("ItemInfo")
|
|
|
59 |
statusChangeLog = OneToMany("ItemChangeLog")
|
|
|
60 |
|
| 94 |
ashish |
61 |
def __repr__(self):
|
| 122 |
ashish |
62 |
return "<Item>%d</item>" % (self.id)
|
| 94 |
ashish |
63 |
|
| 122 |
ashish |
64 |
@property
|
| 94 |
ashish |
65 |
def get_total_inventory(self):
|
|
|
66 |
if self.currentInventory:
|
|
|
67 |
i = 0
|
|
|
68 |
for entry in self.currentInventory:
|
|
|
69 |
i += entry.availability
|
|
|
70 |
return i
|
|
|
71 |
|
|
|
72 |
else:
|
|
|
73 |
return 0;
|
| 103 |
ashish |
74 |
|
| 122 |
ashish |
75 |
@property
|
| 94 |
ashish |
76 |
def get_all_warehouses(self):
|
|
|
77 |
warehouses = []
|
| 122 |
ashish |
78 |
for ci in self.currentInventory:
|
|
|
79 |
warehouses.append(ci.warehouse)
|
| 94 |
ashish |
80 |
return warehouses
|
| 122 |
ashish |
81 |
|
|
|
82 |
|
|
|
83 |
class Price(Entity):
|
|
|
84 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
85 |
price = Field(Float)
|
|
|
86 |
warehouse_id = Field(Integer)
|
|
|
87 |
item = ManyToOne("Item")
|
| 94 |
ashish |
88 |
|
| 122 |
ashish |
89 |
def __repr__(self):
|
|
|
90 |
return "<price><item_id> %d </item_id><warehouse_id> %d </warehouse_id><val> %f </val> </price>" % (self.item.id, self.warehouse_id, self.price)
|
|
|
91 |
|
| 115 |
ashish |
92 |
|
| 103 |
ashish |
93 |
class ItemInfo(Entity):
|
| 122 |
ashish |
94 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 103 |
ashish |
95 |
key = Field(String(30))
|
|
|
96 |
value = Field(String(100))
|
|
|
97 |
item = ManyToOne("Item")
|
|
|
98 |
|
|
|
99 |
def __repr__(self):
|
|
|
100 |
return "<ItemInfo><key>%s</key><value>%s</value></ItemInfo>" % (self.key, self.value)
|
| 115 |
ashish |
101 |
|
| 94 |
ashish |
102 |
|
|
|
103 |
class CurrentInventorySnapshot(Entity):
|
| 115 |
ashish |
104 |
#id = Field(Integer, primary_key=True)
|
| 483 |
rajveer |
105 |
#checkedOn = Field(DateTime, default=datetime.datetime.now())
|
| 94 |
ashish |
106 |
availibility = Field(Integer)
|
|
|
107 |
item = ManyToOne("Item")
|
|
|
108 |
warehouse = ManyToOne("Warehouse")
|
|
|
109 |
|
|
|
110 |
def __repr__(self):
|
|
|
111 |
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)
|
|
|
112 |
|
|
|
113 |
class ItemInventoryHistory(Entity):
|
| 122 |
ashish |
114 |
id = Field(Integer, primary_key=True, autoincrement = True)
|
| 94 |
ashish |
115 |
timestamp = Field(DateTime, default=datetime.datetime.now())
|
|
|
116 |
availibility = Field(Integer)
|
|
|
117 |
item = ManyToOne("Item")
|
|
|
118 |
warehouse = ManyToOne("Warehouse")
|
|
|
119 |
|
|
|
120 |
def __repr__(self):
|
|
|
121 |
pass
|
| 103 |
ashish |
122 |
|
|
|
123 |
class ItemChangeLog(Entity):
|
| 122 |
ashish |
124 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 103 |
ashish |
125 |
old_status = Field(Integer)
|
|
|
126 |
new_status = Field(Integer)
|
| 122 |
ashish |
127 |
timestamp = Field(DateTime, default=datetime.datetime.now())
|
| 103 |
ashish |
128 |
item = ManyToOne("Item")
|
| 94 |
ashish |
129 |
|
| 103 |
ashish |
130 |
def __repr__(self):
|
|
|
131 |
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 |
132 |
|
| 103 |
ashish |
133 |
|
| 94 |
ashish |
134 |
def initialize():
|
| 384 |
ashish |
135 |
metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
|
| 94 |
ashish |
136 |
metadata.bind.echo = True
|
|
|
137 |
setup_all(True)
|
| 115 |
ashish |
138 |
|
|
|
139 |
if __name__=="__main__":
|
|
|
140 |
initialize()
|