Subversion Repositories SmartDukaan

Rev

Rev 1122 | Rev 1308 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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