| 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
|
| 746 |
rajveer |
12 |
import elixir
|
| 94 |
ashish |
13 |
|
| 501 |
rajveer |
14 |
class BestSellers(Entity):
|
| 621 |
chandransh |
15 |
manufacturer_name = Field(String(100), primary_key=True)
|
|
|
16 |
model_number = Field(String(50), primary_key=True)
|
|
|
17 |
color = Field(String(20), primary_key=True)
|
|
|
18 |
rank = Field(Integer)
|
|
|
19 |
using_options(shortnames=True)
|
| 746 |
rajveer |
20 |
using_table_options(mysql_engine="InnoDB")
|
| 501 |
rajveer |
21 |
|
| 94 |
ashish |
22 |
class Warehouse(Entity):
|
| 122 |
ashish |
23 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 759 |
chandransh |
24 |
displayName = Field(String(50))
|
| 483 |
rajveer |
25 |
location = Field(String(200))
|
| 103 |
ashish |
26 |
status = Field(Integer)
|
| 122 |
ashish |
27 |
addedOn = Field(DateTime)
|
| 483 |
rajveer |
28 |
lastCheckedOn = Field(DateTime)
|
|
|
29 |
tinNumber = Field(String(50))
|
|
|
30 |
pincode = Field(String(10))
|
|
|
31 |
vendorString = Field(String(50))
|
| 94 |
ashish |
32 |
inventory = OneToMany('CurrentInventorySnapshot')
|
|
|
33 |
inventoryHistory = OneToMany('ItemInventoryHistory')
|
| 643 |
chandransh |
34 |
logisticsLocation = Field(Integer)
|
| 746 |
rajveer |
35 |
using_options(shortnames=True)
|
|
|
36 |
using_table_options(mysql_engine="InnoDB")
|
| 94 |
ashish |
37 |
|
|
|
38 |
def __repr__(self):
|
|
|
39 |
return "<warehouse>%s</warehouse>" %(self.location)
|
|
|
40 |
|
| 122 |
ashish |
41 |
@property
|
|
|
42 |
def all_items(self):
|
|
|
43 |
items = []
|
|
|
44 |
for ci in self.inventory:
|
|
|
45 |
items.append(ci.item)
|
|
|
46 |
return items
|
| 626 |
chandransh |
47 |
|
|
|
48 |
class EntityIDGenerator(Entity):
|
|
|
49 |
id=Field(Integer, primary_key=True)
|
|
|
50 |
using_options(shortnames=True)
|
| 746 |
rajveer |
51 |
using_table_options(mysql_engine="InnoDB")
|
| 122 |
ashish |
52 |
|
| 94 |
ashish |
53 |
class Item(Entity):
|
| 122 |
ashish |
54 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 483 |
rajveer |
55 |
manufacturer_name = Field(String(100))
|
|
|
56 |
model_number = Field(String(50))
|
|
|
57 |
model_name = Field(String(50))
|
| 609 |
chandransh |
58 |
color = Field(String(20))
|
| 626 |
chandransh |
59 |
category = Field(Integer)
|
| 483 |
rajveer |
60 |
comments = Field(String(200))
|
| 122 |
ashish |
61 |
catalog_item_id = Field(Integer)
|
| 483 |
rajveer |
62 |
vendor_item_id = Field(String(50))
|
| 122 |
ashish |
63 |
feature_id = Field(Integer)
|
|
|
64 |
feature_description = Field(String(200))
|
| 483 |
rajveer |
65 |
mrp = Field(Float)
|
|
|
66 |
mop = Field(Float)
|
|
|
67 |
sellingPrice = Field(Float)
|
| 609 |
chandransh |
68 |
dealerPrice = Field(Float)
|
| 724 |
chandransh |
69 |
transfer_price = Field(Float)
|
| 483 |
rajveer |
70 |
weight = Field(Float)
|
| 122 |
ashish |
71 |
addedOn = Field(DateTime)
|
| 609 |
chandransh |
72 |
updatedOn = Field(DateTime)
|
| 122 |
ashish |
73 |
startDate = Field(DateTime)
|
|
|
74 |
retireDate = Field(DateTime)
|
| 483 |
rajveer |
75 |
status = Field(Integer)
|
| 609 |
chandransh |
76 |
bestDealText = Field(String(100))
|
| 630 |
chandransh |
77 |
bestDealValue = Field(Float)
|
| 621 |
chandransh |
78 |
bestSellingRank = Field(Integer)
|
| 94 |
ashish |
79 |
currentInventory = OneToMany('CurrentInventorySnapshot')
|
|
|
80 |
inventoryHistory = OneToMany('ItemInventoryHistory')
|
| 103 |
ashish |
81 |
iteminfo = OneToMany("ItemInfo")
|
|
|
82 |
statusChangeLog = OneToMany("ItemChangeLog")
|
| 724 |
chandransh |
83 |
hotspotCategory = Field(String(50))
|
| 746 |
rajveer |
84 |
using_options(shortnames=True)
|
|
|
85 |
using_table_options(mysql_engine="InnoDB")
|
| 103 |
ashish |
86 |
|
| 94 |
ashish |
87 |
def __repr__(self):
|
| 122 |
ashish |
88 |
return "<Item>%d</item>" % (self.id)
|
| 94 |
ashish |
89 |
|
| 122 |
ashish |
90 |
@property
|
| 94 |
ashish |
91 |
def get_total_inventory(self):
|
|
|
92 |
if self.currentInventory:
|
|
|
93 |
i = 0
|
|
|
94 |
for entry in self.currentInventory:
|
|
|
95 |
i += entry.availability
|
|
|
96 |
return i
|
|
|
97 |
|
|
|
98 |
else:
|
|
|
99 |
return 0;
|
| 103 |
ashish |
100 |
|
| 122 |
ashish |
101 |
@property
|
| 94 |
ashish |
102 |
def get_all_warehouses(self):
|
|
|
103 |
warehouses = []
|
| 122 |
ashish |
104 |
for ci in self.currentInventory:
|
|
|
105 |
warehouses.append(ci.warehouse)
|
| 94 |
ashish |
106 |
return warehouses
|
| 609 |
chandransh |
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")
|
| 746 |
rajveer |
113 |
using_options(shortnames=True)
|
|
|
114 |
using_table_options(mysql_engine="InnoDB")
|
| 103 |
ashish |
115 |
|
|
|
116 |
def __repr__(self):
|
|
|
117 |
return "<ItemInfo><key>%s</key><value>%s</value></ItemInfo>" % (self.key, self.value)
|
| 115 |
ashish |
118 |
|
| 94 |
ashish |
119 |
|
|
|
120 |
class CurrentInventorySnapshot(Entity):
|
| 115 |
ashish |
121 |
#id = Field(Integer, primary_key=True)
|
| 483 |
rajveer |
122 |
#checkedOn = Field(DateTime, default=datetime.datetime.now())
|
| 870 |
chandransh |
123 |
item = ManyToOne("Item", primary_key=True)
|
|
|
124 |
warehouse = ManyToOne("Warehouse", primary_key=True)
|
| 94 |
ashish |
125 |
availibility = Field(Integer)
|
| 870 |
chandransh |
126 |
reserved = Field(Integer)
|
| 746 |
rajveer |
127 |
using_options(shortnames=True)
|
|
|
128 |
using_table_options(mysql_engine="InnoDB")
|
| 94 |
ashish |
129 |
|
|
|
130 |
def __repr__(self):
|
|
|
131 |
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)
|
|
|
132 |
|
|
|
133 |
class ItemInventoryHistory(Entity):
|
| 122 |
ashish |
134 |
id = Field(Integer, primary_key=True, autoincrement = True)
|
| 94 |
ashish |
135 |
timestamp = Field(DateTime, default=datetime.datetime.now())
|
|
|
136 |
availibility = Field(Integer)
|
|
|
137 |
item = ManyToOne("Item")
|
|
|
138 |
warehouse = ManyToOne("Warehouse")
|
| 746 |
rajveer |
139 |
using_options(shortnames=True)
|
|
|
140 |
using_table_options(mysql_engine="InnoDB")
|
| 94 |
ashish |
141 |
|
|
|
142 |
def __repr__(self):
|
|
|
143 |
pass
|
| 103 |
ashish |
144 |
|
|
|
145 |
class ItemChangeLog(Entity):
|
| 122 |
ashish |
146 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 103 |
ashish |
147 |
old_status = Field(Integer)
|
|
|
148 |
new_status = Field(Integer)
|
| 122 |
ashish |
149 |
timestamp = Field(DateTime, default=datetime.datetime.now())
|
| 103 |
ashish |
150 |
item = ManyToOne("Item")
|
| 746 |
rajveer |
151 |
using_options(shortnames=True)
|
|
|
152 |
using_table_options(mysql_engine="InnoDB")
|
| 94 |
ashish |
153 |
|
| 103 |
ashish |
154 |
def __repr__(self):
|
|
|
155 |
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 |
156 |
|
| 635 |
rajveer |
157 |
class Category(Entity):
|
|
|
158 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
159 |
object = Field(Binary)
|
| 746 |
rajveer |
160 |
using_options(shortnames=True)
|
|
|
161 |
using_table_options(mysql_engine="InnoDB")
|
|
|
162 |
|
| 94 |
ashish |
163 |
def initialize():
|
| 746 |
rajveer |
164 |
#metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
|
|
|
165 |
metadata.bind = 'mysql://root:shop2020@localhost/catalog'
|
| 94 |
ashish |
166 |
metadata.bind.echo = True
|
|
|
167 |
setup_all(True)
|
| 115 |
ashish |
168 |
|
|
|
169 |
if __name__=="__main__":
|
|
|
170 |
initialize()
|