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