| 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 |
|
|
|
14 |
class Warehouse(Entity):
|
| 122 |
ashish |
15 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 759 |
chandransh |
16 |
displayName = Field(String(50))
|
| 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')
|
| 643 |
chandransh |
26 |
logisticsLocation = Field(Integer)
|
| 746 |
rajveer |
27 |
using_options(shortnames=True)
|
|
|
28 |
using_table_options(mysql_engine="InnoDB")
|
| 94 |
ashish |
29 |
|
|
|
30 |
def __repr__(self):
|
|
|
31 |
return "<warehouse>%s</warehouse>" %(self.location)
|
|
|
32 |
|
| 122 |
ashish |
33 |
@property
|
|
|
34 |
def all_items(self):
|
|
|
35 |
items = []
|
|
|
36 |
for ci in self.inventory:
|
|
|
37 |
items.append(ci.item)
|
|
|
38 |
return items
|
| 626 |
chandransh |
39 |
|
|
|
40 |
class EntityIDGenerator(Entity):
|
|
|
41 |
id=Field(Integer, primary_key=True)
|
|
|
42 |
using_options(shortnames=True)
|
| 746 |
rajveer |
43 |
using_table_options(mysql_engine="InnoDB")
|
| 122 |
ashish |
44 |
|
| 94 |
ashish |
45 |
class Item(Entity):
|
| 122 |
ashish |
46 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 963 |
chandransh |
47 |
product_group = Field(String(100))
|
|
|
48 |
brand = Field(String(100))
|
| 483 |
rajveer |
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)
|
| 724 |
chandransh |
62 |
transfer_price = Field(Float)
|
| 483 |
rajveer |
63 |
weight = Field(Float)
|
| 122 |
ashish |
64 |
addedOn = Field(DateTime)
|
| 609 |
chandransh |
65 |
updatedOn = Field(DateTime)
|
| 122 |
ashish |
66 |
startDate = Field(DateTime)
|
|
|
67 |
retireDate = Field(DateTime)
|
| 483 |
rajveer |
68 |
status = Field(Integer)
|
| 609 |
chandransh |
69 |
bestDealText = Field(String(100))
|
| 630 |
chandransh |
70 |
bestDealValue = Field(Float)
|
| 621 |
chandransh |
71 |
bestSellingRank = Field(Integer)
|
| 94 |
ashish |
72 |
currentInventory = OneToMany('CurrentInventorySnapshot')
|
|
|
73 |
inventoryHistory = OneToMany('ItemInventoryHistory')
|
| 103 |
ashish |
74 |
iteminfo = OneToMany("ItemInfo")
|
|
|
75 |
statusChangeLog = OneToMany("ItemChangeLog")
|
| 724 |
chandransh |
76 |
hotspotCategory = Field(String(50))
|
| 746 |
rajveer |
77 |
using_options(shortnames=True)
|
|
|
78 |
using_table_options(mysql_engine="InnoDB")
|
| 103 |
ashish |
79 |
|
| 94 |
ashish |
80 |
def __repr__(self):
|
| 122 |
ashish |
81 |
return "<Item>%d</item>" % (self.id)
|
| 94 |
ashish |
82 |
|
| 122 |
ashish |
83 |
@property
|
| 94 |
ashish |
84 |
def get_total_inventory(self):
|
|
|
85 |
if self.currentInventory:
|
|
|
86 |
i = 0
|
|
|
87 |
for entry in self.currentInventory:
|
|
|
88 |
i += entry.availability
|
|
|
89 |
return i
|
|
|
90 |
|
|
|
91 |
else:
|
|
|
92 |
return 0;
|
| 103 |
ashish |
93 |
|
| 122 |
ashish |
94 |
@property
|
| 94 |
ashish |
95 |
def get_all_warehouses(self):
|
|
|
96 |
warehouses = []
|
| 122 |
ashish |
97 |
for ci in self.currentInventory:
|
|
|
98 |
warehouses.append(ci.warehouse)
|
| 94 |
ashish |
99 |
return warehouses
|
| 609 |
chandransh |
100 |
|
| 103 |
ashish |
101 |
class ItemInfo(Entity):
|
| 122 |
ashish |
102 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 103 |
ashish |
103 |
key = Field(String(30))
|
|
|
104 |
value = Field(String(100))
|
|
|
105 |
item = ManyToOne("Item")
|
| 746 |
rajveer |
106 |
using_options(shortnames=True)
|
|
|
107 |
using_table_options(mysql_engine="InnoDB")
|
| 103 |
ashish |
108 |
|
|
|
109 |
def __repr__(self):
|
|
|
110 |
return "<ItemInfo><key>%s</key><value>%s</value></ItemInfo>" % (self.key, self.value)
|
| 115 |
ashish |
111 |
|
| 94 |
ashish |
112 |
|
|
|
113 |
class CurrentInventorySnapshot(Entity):
|
| 115 |
ashish |
114 |
#id = Field(Integer, primary_key=True)
|
| 483 |
rajveer |
115 |
#checkedOn = Field(DateTime, default=datetime.datetime.now())
|
| 870 |
chandransh |
116 |
item = ManyToOne("Item", primary_key=True)
|
|
|
117 |
warehouse = ManyToOne("Warehouse", primary_key=True)
|
| 94 |
ashish |
118 |
availibility = Field(Integer)
|
| 870 |
chandransh |
119 |
reserved = Field(Integer)
|
| 746 |
rajveer |
120 |
using_options(shortnames=True)
|
|
|
121 |
using_table_options(mysql_engine="InnoDB")
|
| 94 |
ashish |
122 |
|
|
|
123 |
def __repr__(self):
|
|
|
124 |
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)
|
|
|
125 |
|
|
|
126 |
class ItemInventoryHistory(Entity):
|
| 122 |
ashish |
127 |
id = Field(Integer, primary_key=True, autoincrement = True)
|
| 94 |
ashish |
128 |
timestamp = Field(DateTime, default=datetime.datetime.now())
|
|
|
129 |
availibility = Field(Integer)
|
|
|
130 |
item = ManyToOne("Item")
|
|
|
131 |
warehouse = ManyToOne("Warehouse")
|
| 746 |
rajveer |
132 |
using_options(shortnames=True)
|
|
|
133 |
using_table_options(mysql_engine="InnoDB")
|
| 94 |
ashish |
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")
|
| 746 |
rajveer |
144 |
using_options(shortnames=True)
|
|
|
145 |
using_table_options(mysql_engine="InnoDB")
|
| 94 |
ashish |
146 |
|
| 103 |
ashish |
147 |
def __repr__(self):
|
|
|
148 |
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 |
149 |
|
| 635 |
rajveer |
150 |
class Category(Entity):
|
|
|
151 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
152 |
object = Field(Binary)
|
| 746 |
rajveer |
153 |
using_options(shortnames=True)
|
|
|
154 |
using_table_options(mysql_engine="InnoDB")
|
|
|
155 |
|
| 94 |
ashish |
156 |
def initialize():
|
| 746 |
rajveer |
157 |
#metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
|
|
|
158 |
metadata.bind = 'mysql://root:shop2020@localhost/catalog'
|
| 94 |
ashish |
159 |
metadata.bind.echo = True
|
|
|
160 |
setup_all(True)
|
| 115 |
ashish |
161 |
|
|
|
162 |
if __name__=="__main__":
|
|
|
163 |
initialize()
|