| 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
|
| 635 |
rajveer |
9 |
from sqlalchemy.types import Integer, Binary
|
| 94 |
ashish |
10 |
from elixir.relationships import OneToMany, ManyToOne
|
|
|
11 |
import datetime
|
|
|
12 |
|
| 501 |
rajveer |
13 |
class BestSellers(Entity):
|
| 621 |
chandransh |
14 |
manufacturer_name = Field(String(100), primary_key=True)
|
|
|
15 |
model_number = Field(String(50), primary_key=True)
|
|
|
16 |
color = Field(String(20), primary_key=True)
|
|
|
17 |
rank = Field(Integer)
|
|
|
18 |
using_options(shortnames=True)
|
| 501 |
rajveer |
19 |
|
| 94 |
ashish |
20 |
class Warehouse(Entity):
|
| 122 |
ashish |
21 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 483 |
rajveer |
22 |
location = Field(String(200))
|
| 103 |
ashish |
23 |
status = Field(Integer)
|
| 122 |
ashish |
24 |
addedOn = Field(DateTime)
|
| 483 |
rajveer |
25 |
lastCheckedOn = Field(DateTime)
|
|
|
26 |
tinNumber = Field(String(50))
|
|
|
27 |
pincode = Field(String(10))
|
|
|
28 |
vendorString = Field(String(50))
|
| 94 |
ashish |
29 |
inventory = OneToMany('CurrentInventorySnapshot')
|
|
|
30 |
inventoryHistory = OneToMany('ItemInventoryHistory')
|
|
|
31 |
|
|
|
32 |
def __repr__(self):
|
|
|
33 |
return "<warehouse>%s</warehouse>" %(self.location)
|
|
|
34 |
|
| 122 |
ashish |
35 |
@property
|
|
|
36 |
def all_items(self):
|
|
|
37 |
items = []
|
|
|
38 |
for ci in self.inventory:
|
|
|
39 |
items.append(ci.item)
|
|
|
40 |
return items
|
| 626 |
chandransh |
41 |
|
|
|
42 |
class EntityIDGenerator(Entity):
|
|
|
43 |
id=Field(Integer, primary_key=True)
|
|
|
44 |
using_options(shortnames=True)
|
| 122 |
ashish |
45 |
|
| 94 |
ashish |
46 |
class Item(Entity):
|
| 122 |
ashish |
47 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 483 |
rajveer |
48 |
manufacturer_name = Field(String(100))
|
|
|
49 |
model_number = Field(String(50))
|
|
|
50 |
model_name = Field(String(50))
|
| 609 |
chandransh |
51 |
color = Field(String(20))
|
| 626 |
chandransh |
52 |
category = Field(Integer)
|
| 483 |
rajveer |
53 |
comments = Field(String(200))
|
| 122 |
ashish |
54 |
catalog_item_id = Field(Integer)
|
| 483 |
rajveer |
55 |
vendor_item_id = Field(String(50))
|
| 122 |
ashish |
56 |
feature_id = Field(Integer)
|
|
|
57 |
feature_description = Field(String(200))
|
| 483 |
rajveer |
58 |
mrp = Field(Float)
|
|
|
59 |
mop = Field(Float)
|
|
|
60 |
sellingPrice = Field(Float)
|
| 609 |
chandransh |
61 |
dealerPrice = Field(Float)
|
| 483 |
rajveer |
62 |
weight = Field(Float)
|
| 122 |
ashish |
63 |
addedOn = Field(DateTime)
|
| 609 |
chandransh |
64 |
updatedOn = Field(DateTime)
|
| 122 |
ashish |
65 |
startDate = Field(DateTime)
|
|
|
66 |
retireDate = Field(DateTime)
|
| 483 |
rajveer |
67 |
status = Field(Integer)
|
| 609 |
chandransh |
68 |
bestDealText = Field(String(100))
|
| 630 |
chandransh |
69 |
bestDealValue = Field(Float)
|
| 621 |
chandransh |
70 |
bestSellingRank = 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
|
| 609 |
chandransh |
96 |
|
| 103 |
ashish |
97 |
class ItemInfo(Entity):
|
| 122 |
ashish |
98 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 103 |
ashish |
99 |
key = Field(String(30))
|
|
|
100 |
value = Field(String(100))
|
|
|
101 |
item = ManyToOne("Item")
|
|
|
102 |
|
|
|
103 |
def __repr__(self):
|
|
|
104 |
return "<ItemInfo><key>%s</key><value>%s</value></ItemInfo>" % (self.key, self.value)
|
| 115 |
ashish |
105 |
|
| 94 |
ashish |
106 |
|
|
|
107 |
class CurrentInventorySnapshot(Entity):
|
| 115 |
ashish |
108 |
#id = Field(Integer, primary_key=True)
|
| 483 |
rajveer |
109 |
#checkedOn = Field(DateTime, default=datetime.datetime.now())
|
| 94 |
ashish |
110 |
availibility = Field(Integer)
|
|
|
111 |
item = ManyToOne("Item")
|
|
|
112 |
warehouse = ManyToOne("Warehouse")
|
|
|
113 |
|
|
|
114 |
def __repr__(self):
|
|
|
115 |
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)
|
|
|
116 |
|
|
|
117 |
class ItemInventoryHistory(Entity):
|
| 122 |
ashish |
118 |
id = Field(Integer, primary_key=True, autoincrement = True)
|
| 94 |
ashish |
119 |
timestamp = Field(DateTime, default=datetime.datetime.now())
|
|
|
120 |
availibility = Field(Integer)
|
|
|
121 |
item = ManyToOne("Item")
|
|
|
122 |
warehouse = ManyToOne("Warehouse")
|
|
|
123 |
|
|
|
124 |
def __repr__(self):
|
|
|
125 |
pass
|
| 103 |
ashish |
126 |
|
|
|
127 |
class ItemChangeLog(Entity):
|
| 122 |
ashish |
128 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 103 |
ashish |
129 |
old_status = Field(Integer)
|
|
|
130 |
new_status = Field(Integer)
|
| 122 |
ashish |
131 |
timestamp = Field(DateTime, default=datetime.datetime.now())
|
| 103 |
ashish |
132 |
item = ManyToOne("Item")
|
| 94 |
ashish |
133 |
|
| 103 |
ashish |
134 |
def __repr__(self):
|
|
|
135 |
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 |
136 |
|
| 635 |
rajveer |
137 |
class Category(Entity):
|
|
|
138 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
139 |
object = Field(Binary)
|
| 103 |
ashish |
140 |
|
| 94 |
ashish |
141 |
def initialize():
|
| 384 |
ashish |
142 |
metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
|
| 94 |
ashish |
143 |
metadata.bind.echo = True
|
|
|
144 |
setup_all(True)
|
| 115 |
ashish |
145 |
|
|
|
146 |
if __name__=="__main__":
|
|
|
147 |
initialize()
|