Subversion Repositories SmartDukaan

Rev

Rev 22715 | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 28-Apr-2010

@author: ashish
'''

from elixir import *
from elixir.entity import Entity
from elixir.fields import Field
from elixir.relationships import OneToMany, ManyToOne
from sqlalchemy import create_engine
from sqlalchemy.types import Integer, Integer, String, Float, DateTime, Boolean, \
    Enum, Numeric, BigInteger, LargeBinary, Date
import datetime
import elixir

class Address(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    line_1 = Field(String(100))
    line_2 = Field(String(100))
    landmark = Field(String(100))
    city = Field(String(100))
    state = Field(String(100))
    pin = Field(String(10))
    country = Field(String(100))
    enabled = Field(Boolean)
    type = Field(Integer)
    added_on = Field(DateTime)
    name = Field(String(100))
    phone = Field(String(20))
    user = ManyToOne("User")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
        
class User(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    email = Field(String(100))
    password = Field(String(50))
    name = Field(String(150))
    default_address_id = Field(Integer)
    communication_email = Field(String(100))
    active_cart = ManyToOne("Cart")
    jsession_id = Field(String(64))
    is_anonymous = Field(Boolean)
    date_of_birth = Field(String(20))
    sex = Field(Integer)
    mobile_number = Field(String(20))
    source = Field(String(200))
    source_start_time = Field(DateTime)
    trust_level = Field(Float)
    last_login = Field(DateTime)
    last_logout = Field(DateTime)
    active_since = Field(DateTime)
    fbusers = OneToMany("FacebookUser")
    addresses = OneToMany("Address")
    sources = OneToMany("UserSource")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class FacebookUser(Entity):
    user = ManyToOne("User", primary_key=True)
    facebook_access_token = Field(String(200))
    facebook_id = Field(String(50))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class UserSource(Entity):
    user = ManyToOne("User", primary_key=True)
    source_id = Field(Integer)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class Line(Entity):
    cart = ManyToOne("Cart", primary_key=True)
    item_id = Field(Integer, primary_key=True, autoincrement=False)
    quantity = Field(Float)
    line_status = Field(Integer)
    estimate = Field(Integer)
    created_on = Field(DateTime)
    updated_on = Field(DateTime)
    actual_price = Field(Float)
    discounted_price = Field(Float)
    discounts = OneToMany('Discount')
    insurer = Field(Integer)
    insuranceAmount = Field(Float)
    dataProtectionInsurer =Field(Integer, default=0, server_default="0")
    dataProtectionAmount = Field(Float, default=0, server_default="0")
    dealText=Field(String(200))
    freebieId=Field(Integer)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class Cart(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    cart_status = Field(Integer)
    address_id = Field(Integer)
    pickupStoreId = Field(Integer)
    checked_out_on = Field(DateTime)
    created_on = Field(DateTime)
    updated_on = Field(DateTime)
    lines = OneToMany("Line")
    total_price = Field(Float)
    discounted_price = Field(Float)
    coupon_code = Field(String(20))
    user = OneToMany("User")
    wallet_amount = Field(Float, default=0, server_default="0")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class Discount(Entity):
    line = ManyToOne("Line", primary_key=True)
    discount = Field(Float, primary_key = True)
    quantity = Field(Float)
    using_options(shortnames = True)
    using_table_options(mysql_engine = 'InnoDB')

#===============================================================================
# Entity generated from Promotion Service
#===============================================================================
class Promotion(Entity):
    id = Field(Integer, primary_key = True, autoincrement = True)
    name = Field(String(200))
    rule_execution_src = Field(String(100))
    start_on = Field(DateTime)
    end_on = Field(DateTime)
    coupons = OneToMany("Coupon")
    created_on = Field(DateTime)
    type = Field(Integer)
    using_options(shortnames = True)
    using_table_options(mysql_engine = "InnoDB")
    
class PrivateDealUser(Entity):
    id = Field(Integer, primary_key=True)
    counter = ManyToOne("Counter")
    tin = Field(String(20))
    created_on = Field(DateTime)
    isActive = Field(Boolean)
    bulkShipmentAmountLimit = Field(Float, default=50000)
    creditorAssigned = Field(Boolean)
    tinVerified = Field(Boolean)
    isFofo = Field(Boolean)
    using_options(shortnames = True)
    using_table_options(mysql_engine = "InnoDB")

class Coupon(Entity):
    coupon_code = Field(String(20))
    promotion = ManyToOne("Promotion")
    arguments = Field(String(200))
    coupon_category = Field(Enum('CUSTOMER_SATISFACTION','MARKETING','REFUND'))
    using_options(shortnames = True)
    using_table_options(mysql_engine = "InnoDB")

class PromotionTracker(Entity):
    coupon_code = Field(String(20))
    transaction_id = Field(Integer)
    user_id = Field(Integer)
    applied_on = Field(DateTime)
    promotion_id = Field(Integer)
    amount = Field(Integer)
    is_digital  = Field(Boolean)
    using_options(shortnames = True)
    using_table_options(mysql_engine = "InnoDB")

class RechargeVoucher(Entity):
    id = Field(Integer, primary_key = True, autoincrement = True)
    voucherCode = Field(String(30))
    voucherType = Field(Integer)
    amount = Field(Numeric(precision=8, scale=2, asdecimal=False))
    available = Field(Boolean)
    issuedOn = Field(DateTime)
    expiredOn = Field(DateTime)
    redeemed = Field(Boolean)
    redeemedOn = Field(DateTime)
    email = Field(String(100))
    userId = Field(Integer)
    using_options(shortnames = True)
    using_table_options(mysql_engine = "InnoDB")
    
#===============================================================================
# Entity generated from Contact Us form
#===============================================================================
class UserCommunication(Entity):
    id = Field(Integer, primary_key = True, autoincrement = True)
    user_id = Field(Integer)
    communication_type = Field(Integer)
    order_id = Field(Integer)
    airwaybill_no = Field(String(50))
    reply_to = Field(String(50))
    product_name = Field(String(200))
    subject = Field(String(200))
    message = Field(String(600))
    communication_timestamp = Field(DateTime)
    using_options(shortnames = True)
    using_table_options(mysql_engine = "InnoDB")

#===============================================================================
# Different entities for the Widget service
#===============================================================================

class UserWidgetItem(Entity):
    userId = Field(Integer, primary_key=True)
    widgetId = Field(Integer, primary_key=True)
    itemId = Field(Integer, primary_key=True)
    addedOn = Field(DateTime)
    using_options(shortnames=True)    
    using_table_options(mysql_engine="InnoDB")

class MasterAffiliate(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    name = Field(String(100), unique=True)
    added_on = Field(DateTime)
    affiliates = OneToMany("Affiliate")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class Affiliate(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    master_affiliate = ManyToOne("MasterAffiliate")
    name = Field(String(100), unique=True)
    url = Field(String(200))
    added_on = Field(DateTime)
    tracklogs = OneToMany("TrackLog")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class Tracker(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    affiliate_id = Field(Integer)
    added_on = Field(DateTime)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class TrackLog(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    added_on = Field(DateTime)
    affiliate = ManyToOne("Affiliate")
    user_id = Field(Integer)
    event = Field(String(100))
    event_id = Field(Integer)
    url = Field(String(200))
    data = Field(String(200))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class InsuranceDetails(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    addressId = Field(Integer)
    dob = Field(String(64))
    guardianName = Field(String(255))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class Counter(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    code = Field(String(10),unique=True)
    dealUsers = OneToMany("PrivateDealUser")
    name = Field(String(128))
    ownerName = Field(String(100))
    email = Field(String(80))
    mobile = Field(String(10))
    alternateMobile = Field(String(10))
    addressId = Field(Integer)
    striker = Field(Boolean)
    tin = Field(String(20), unique=True)
    gstin = Field(String(20), unique=True)
    spCounterSize = Field(Integer)
    fpCounterSize = Field(Integer)
    dob = Field(String(20))
    createdOn = Field(DateTime)
    lastPurchasedOn = Field(DateTime)
    documentVerified = Field(Boolean)
    verificationType = Field(Integer)
    verifiedOn = Field(DateTime)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class CounterOnlineInfo(Entity):
    counterId = Field(Integer, primary_key=True)
    tinNumber = Field(String(30))
    cstNumber = Field(String(30))
    dealerName = Field(String(100))
    dealerAddress = Field(Text)
    state = Field(String(20))
    pan = Field(String(20))
    registrationDate = Field(DateTime)
    registrationStatus = Field(Boolean)
    validatedTill = Field(DateTime)
    created = Field(DateTime,default = datetime.datetime.now)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class PrivateDealUserAddressMapping(Entity):
    user_id = Field(Integer, primary_key=True, autoincrement=False)
    address_id = Field(Integer, primary_key=True, autoincrement=False)
    taxInvoiceAvailable = Field(Boolean)
    creditOptionAvailable = Field(Boolean)
    createdAt = Field(DateTime,default = datetime.datetime.now)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class AccessTokenizer(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    userId = Field(Integer)
    source = Field(String(50))
    tokenString = Field(String(50))
    expiredTime = Field(DateTime)
    expired = Field(Boolean)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

def initialize(dbname='user', db_hostname="localhost", setup=True):
    #metadata.bind = "sqlite:///user.sqlite" #need to read it from configserver.
    engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200, max_overflow=50)
    metadata.bind = engine
    metadata.bind.echo = True
    setup_all(setup)

if __name__=="__main__":
    initialize()