Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
104 ashish 1
'''
2
Created on 29-Mar-2010
3
 
4
@author: ashish
5
'''
6
 
7
from elixir import *
8
from elixir.entity import Entity
9
from elixir.fields import Field
10
from sqlalchemy.types import Integer
11
from elixir.relationships import OneToMany, ManyToOne
12
import datetime
13
 
14
 
15
 
16
#===============================================================================
17
# Different entities in the model
18
#===============================================================================
19
 
483 rajveer 20
def initialize():
21
    metadata.bind = "sqlite:///Transactionsnew.sqlite"
22
    metadata.bind.echo = True
23
    setup_all(True)
24
 
25
 
26
if __name__=="__main__":
27
    initialize()
28
 
29
 
30
class LineItem(Entity):
31
    id = Field(Integer, primary_key=True, autoincrement=True)
32
    sku_id = Field(String(30))
33
    brand = Field(String(30))
34
    model_number = Field(String(30))
35
    model_name = Field(String(30)) 
36
    extra_info = Field(String(100))
37
    quantity = Field(Float)
38
    unit_price = Field(Float)
39
    unit_weight = Field(Float)
40
    total_price = Field(Float)
41
    total_weight = Field(Float)
42
    order = ManyToOne("Order")
43
 
44
class Order(Entity):
45
    id = Field(Integer, primary_key=True, autoincrement=True)
46
    warehouse_id = Field(Integer)
47
    logistics_provider_id = Field(Integer)
48
    airwaybill_no = Field(String(50))
49
    tracking_id = Field(String(50))
50
    expected_delivery_time = Field(DateTime)
51
    customer_id = Field(Integer)
52
    customer_name = Field(String(50))
53
    customer_mobilenumber = Field(String(20))
54
    customer_pincode = Field(String(10))
55
    customer_address = Field(String(200))
56
    customer_email = Field(String(50))
57
    status = Field(Integer)
58
    statusDescription = Field(String(50))
59
    total_amount = Field(Float)
60
    total_weight = Field(Float)
61
    invoice_number = Field(String(30))
62
    billed_by = Field(String(30))
63
    created_timestamp = Field(DateTime)
64
    accepted_timestamp = Field(DateTime)
65
    billing_timestamp = Field(DateTime)
66
    shipping_timestamp = Field(DateTime)
67
    delivery_timestamp = Field(DateTime)
68
    lineitems = OneToMany("LineItem")
69
    transaction = ManyToOne("Transaction")
70
 
71
 
104 ashish 72
class Transaction(Entity):
483 rajveer 73
    id = Field(Integer, primary_key=True, autoincrement=True)
74
    createdOn = Field(DateTime)
75
    status = Field(Integer)
76
    status_message = Field(String(100))
77
    customer_id = Field(Integer)
78
    shopping_cart_id = Field(Integer)
79
    payments = OneToMany("Payment")
80
    orders = OneToMany("Order")
81
 
82
class Payment(Entity):
83
    id = Field(Integer, primary_key=True, autoincrement=True)
84
    payment_id = Field(Integer)
85
    merchant_tx_id = Field(String(30))
86
    bank_tx_id = Field(String(30))
87
    mode = Field(String(30))
88
    amount = Field(Float)
89
    status = Field(Integer)
90
    status_message = Field(String(100))
91
    start_time = Field(DateTime)
92
    finish_time = Field(DateTime)
93
    transaction = ManyToOne("Transaction")
132 ashish 94
 
483 rajveer 95
    def __repr__(self):
96
        return "Payment: id %d"%(self.id)
97
 
98
 
99
class Alerts(Entity):
132 ashish 100
    id = Field(Integer, primary_key=True, autoincrement=True)
483 rajveer 101
    order_id = Field(Integer)
102
    valid = Field(Boolean)
103
    type = Field(Integer)
104
    time_set = Field(DateTime)
105
    comment = Field(String(100))
106
    time_unset = Field(DateTime)
107
 
108
 
109
"""
110
class Transaction(Entity):
111
 
112
    id = Field(Integer, primary_key=True, autoincrement=True)
104 ashish 113
    createdOn = Field(DateTime)
114
    expected_delivery_time = Field(DateTime)
115
    status = Field(Integer)
116
    status_message = Field(String(100))
117
    customer_id = Field(Integer)
358 ashish 118
    warehouse_id = Field(Integer)
132 ashish 119
    shopping_cart_id = Field(Integer)
104 ashish 120
    payments = OneToMany("Payment")
121
    shipments = OneToMany("Shipment")
122
    lineitems = OneToMany("LineItem")
123
    trails = OneToMany("TransactionTrail")
194 ashish 124
 
104 ashish 125
 
126
 
127
class Payment(Entity):
115 ashish 128
    #using_options(auto_primarykey=False)
132 ashish 129
    id = Field(Integer, primary_key=True, autoincrement=True)
130
    payment_id = Field(Integer)
104 ashish 131
    merchant_tx_id = Field(String(30))
132
    bank_tx_id = Field(String(30))
132 ashish 133
    mode = Field(String(30))
104 ashish 134
    amount = Field(Float)
135
    status = Field(Integer)
136
    status_message = Field(String(100))
137
    start_time = Field(DateTime)
138
    finish_time = Field(DateTime)
139
    transaction = ManyToOne("Transaction")
140
 
141
    def __repr__(self):
142
        return "Payment: id %d"%(self.id)
143
 
144
 
145
class Shipment(Entity):
115 ashish 146
    #using_options(auto_primarykey=False)
132 ashish 147
    id = Field(Integer, primary_key=True, autoincrement=True)
104 ashish 148
    address = Field(String(100))
149
    tracking_id = Field(String(100))
150
    status = Field(Integer)
151
    status_message = Field(String(100))
152
    shipment_time = Field(DateTime)
153
    delivery_time = Field(DateTime)
154
    declared_value = Field(Float)
155
    insurance_value = Field(Float)
156
    weight = Field(Float)
157
    airway_bill_no = Field(String(30))
158
    provider = Field(String(30))
159
    transaction = ManyToOne("Transaction")
160
    lineitems = OneToMany("LineItem")
161
 
162
    def __repr__(self):
163
        return "Shipment: id %d"%(self.id)
164
 
165
 
166
class LineItem(Entity):
115 ashish 167
    #using_options(auto_primarykey=False)
132 ashish 168
    id = Field(Integer, primary_key=True, autoincrement=True)
104 ashish 169
    added_on = Field(DateTime)
170
    item_id = Field(Integer)
171
    additional_info = OneToMany("AdditionalInfo")
172
    transaction = ManyToOne("Transaction")
115 ashish 173
    billing = ManyToOne("Billing")
104 ashish 174
    shipment = ManyToOne("Shipment")
132 ashish 175
    item_info = OneToOne("ItemInfo")
104 ashish 176
    def __repr__(self):
177
        return "id %d item_id %d"%(self.id, self.item_id)
178
 
132 ashish 179
class ItemInfo(Entity):
180
    id = Field(Integer, primary_key=True, autoincrement=True)
181
    price = Field(Float)
182
    weight = Field(Float)
183
    line_item = ManyToOne("LineItem")
104 ashish 184
 
185
class AdditionalInfo(Entity):
115 ashish 186
    #using_options(auto_primarykey=False)
132 ashish 187
    id = Field(Integer, primary_key=True, autoincrement=True)
104 ashish 188
    key = Field(String(30))
189
    value = Field(String(100))
190
    line_item = ManyToOne("LineItem")
191
 
192
    def __repr__(self):
193
        return "Additonal info id %d key %s value %s" %(self.id, self.key, self.value)
194
 
195
 
196
class Billing(Entity):
115 ashish 197
    #using_options(auto_primarykey=False)
132 ashish 198
    id = Field(Integer, primary_key=True, autoincrement=True)
104 ashish 199
    bill_number = Field(String(30))
200
    created_on = Field(DateTime)
201
    generated_by = Field(String(30))
115 ashish 202
    line_item = OneToMany("LineItem")
104 ashish 203
 
132 ashish 204
 
104 ashish 205
    def __repr__(self):
206
        return "Billing: billing id %d billno %s " % (self.id, self.bill_number)
207
 
208
class TransactionTrail(Entity):
115 ashish 209
    #using_options(auto_primarykey=False)
132 ashish 210
    id = Field(Integer, primary_key=True, autoincrement=True)
104 ashish 211
    field_changed = Field(String(30))
212
    old_value = Field(String(30))
213
    new_value = Field(String(30))
214
    description = Field(String(100))
215
    timestamp = Field(DateTime)
216
    transaction = ManyToOne("Transaction")
217
 
304 ashish 218
class Alerts(Entity):
219
    id = Field(Integer, primary_key=True, autoincrement=True)
220
    transaction_id = Field(Integer)
221
    valid = Field(Boolean)
222
    type = Field(Integer)
223
    time_set = Field(DateTime)
224
    comment = Field(String(100))
225
    time_unset = Field(DateTime)
226
 
227
class ExtraItemInfo(Entity):
228
    id = Field(Integer, primary_key=True, autoincrement=True)
229
    transaction_id = Field(Integer)
230
    sku_id = Field(Integer)
231
    model = Field(String(50))
232
    vendor = Field(String(50))
233
    colour = Field(String(50))
483 rajveer 234
"""