Rev 3355 | Rev 4295 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 22-Mar-2010@author: ashish'''import datetimeimport elixirfrom elixir.entity import Entityfrom elixir.fields import Fieldfrom sqlalchemy.types import Integer, String, DateTime, Float, Booleanfrom sqlalchemy import create_enginefrom elixir.relationships import OneToMany, ManyToOnefrom elixir.options import using_options, using_table_optionsfrom elixir import metadata, setup_allclass Vendor(Entity):id = Field(Integer, primary_key=True, autoincrement=True)name = Field(String(50))warehouses = OneToMany('Warehouse')using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")class Warehouse(Entity):id = Field(Integer, primary_key=True, autoincrement=True)displayName = Field(String(50))location = Field(String(200))status = Field(Integer)addedOn = Field(DateTime)lastCheckedOn = Field(DateTime)tinNumber = Field(String(50))pincode = Field(String(10))vendorString = Field(String(50))inventory = OneToMany('CurrentInventorySnapshot')inventoryHistory = OneToMany('ItemInventoryHistory')logisticsLocation = Field(Integer)vendor = ManyToOne('Vendor')billingType = Field(Integer)using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")def __repr__(self):return "<warehouse>%s</warehouse>" %(self.location)@propertydef all_items(self):items = []for ci in self.inventory:items.append(ci.item)return itemsclass EntityIDGenerator(Entity):id=Field(Integer, primary_key=True)using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")class Item(Entity):id = Field(Integer, primary_key=True, autoincrement=True)product_group = Field(String(100))brand = Field(String(100))model_number = Field(String(50))model_name = Field(String(50))color = Field(String(20))category = Field(Integer)comments = Field(String(200))catalog_item_id = Field(Integer)feature_id = Field(Integer)feature_description = Field(String(200))mrp = Field(Float)mop = Field(Float)sellingPrice = Field(Float)dealerPrice = Field(Float)transfer_price = Field(Float)weight = Field(Float)addedOn = Field(DateTime)updatedOn = Field(DateTime)startDate = Field(DateTime)retireDate = Field(DateTime)status = Field(Integer)status_description = Field(String(100))bestDealText = Field(String(100))bestDealValue = Field(Float)bestSellingRank = Field(Integer)currentInventory = OneToMany('CurrentInventorySnapshot')inventoryHistory = OneToMany('ItemInventoryHistory')iteminfo = OneToMany("ItemInfo")statusChangeLog = OneToMany("ItemChangeLog")hotspotCategory = Field(String(50))preferredWarehouse = Field(String(50))defaultForEntity = Field(Boolean)risky = Field(Boolean)expectedDelay = Field(Integer)using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")def __repr__(self):return "<Item>%d</item>" % (self.id)@propertydef get_total_inventory(self):if self.currentInventory:i = 0for entry in self.currentInventory:i += entry.availabilityreturn ielse:return 0;@propertydef get_all_warehouses(self):return [ci.warehouse for ci in self.currentInventory]class VendorItemMapping(Entity):vendor = ManyToOne('Vendor', primary_key=True)item_key = Field(String(200), primary_key=True)item = ManyToOne('Item')vendor_category = Field(String(50))using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")class VendorItemPricing(Entity):vendor = ManyToOne('Vendor', primary_key=True)item = ManyToOne('Item', primary_key=True)mop = Field(Float)dealerPrice = Field(Float)transfer_price = Field(Float)using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")class ItemInfo(Entity):id = Field(Integer, primary_key=True, autoincrement=True)key = Field(String(30))value = Field(String(100))item = ManyToOne("Item")using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")def __repr__(self):return "<ItemInfo><key>%s</key><value>%s</value></ItemInfo>" % (self.key, self.value)class CurrentInventorySnapshot(Entity):#id = Field(Integer, primary_key=True)#checkedOn = Field(DateTime, default=datetime.datetime.now())item = ManyToOne("Item", primary_key=True)warehouse = ManyToOne("Warehouse", primary_key=True)availibility = Field(Integer)reserved = Field(Integer)using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")def __repr__(self):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)class ItemInventoryHistory(Entity):id = Field(Integer, primary_key=True, autoincrement = True)timestamp = Field(DateTime, default=datetime.datetime.now())availibility = Field(Integer)item = ManyToOne("Item")warehouse = ManyToOne("Warehouse")using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")def __repr__(self):passclass ItemChangeLog(Entity):id = Field(Integer, primary_key=True, autoincrement=True)old_status = Field(Integer)new_status = Field(Integer)timestamp = Field(DateTime)item = ManyToOne("Item")using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")def __repr__(self):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)class Category(Entity):id = Field(Integer, primary_key=True, autoincrement=False)label = Field(String(50))description = Field(String(200))parent_category_id = Field(Integer)using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")class SimilarItems(Entity):item = ManyToOne('Item', primary_key=True)catalog_item_id = Field(Integer, primary_key=True, autoincrement=False)using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")class ProductNotification(Entity):item = ManyToOne('Item', primary_key=True)email = Field(String(100), primary_key=True, autoincrement=False)addedOn = Field(DateTime, primary_key=True, autoincrement=False)using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")class Source(Entity):id = Field(Integer, primary_key=True, autoincrement=True)name = Field(String(50))identifier = Field(String(100))using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")class SourceItemPricing(Entity):source = ManyToOne('Source', primary_key=True)item = ManyToOne('Item', primary_key=True)mrp = Field(Float)sellingPrice = Field(Float)using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")def initialize(dbname='catalog', db_hostname="localhost"):#metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.#metadata.bind = 'mysql://root:shop2020@localhost/catalog'engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200)metadata.bind = enginemetadata.bind.echo = Truesetup_all(True)if __name__=="__main__":initialize()