Subversion Repositories SmartDukaan

Rev

Rev 6031 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 11-Sep-2012

@author: mandeep
'''
from elixir.entity import Entity
from elixir.fields import Field
from elixir.options import using_options, using_table_options
from sqlalchemy.types import Enum, Integer, DateTime, String

class BaseOrder(Entity):
    '''
    classdocs
    '''
    id = Field(Integer, primary_key=True, autoincrement=True)
    idPrefix = Field(String(8))
    transactionId = Field(Integer)
    creationTimestamp = Field(DateTime)
    amount = Field(Integer)
    customerId = Field(Integer)
    customerEmailId = Field(String(256))
    invoiceNumber = Field(Integer)
    orderType = Field(Enum('B2C', 'B2Cbulk', 'B2B'))
    using_options(shortnames=True, inheritance='multi')
    using_table_options(mysql_engine="InnoDB")

    def __init__(self):
        '''
        Constructor
        '''

    def to_thrift_object(self, thriftObject):
        '''
        Copies attributes to thrift object
        '''
        thriftObject.amount = self.amount
        thriftObject.creationTimestamp = self.creationTimestamp
        thriftObject.customerEmailId = self.customerEmailId
        thriftObject.customerId = self.customerId
        thriftObject.id = self.idPrefix + self.id
        thriftObject.invoiceNumber = self.invoiceNumber
        thriftObject.orderType = self.orderType
        thriftObject.transactionId = self.transactionId

    def from_thrift_object(self, thriftBaseOrder):
        self.amount = thriftBaseOrder.amount
        self.creationTimestamp = thriftBaseOrder.creationTimestamp
        self.customerEmailId = thriftBaseOrder.customerEmailId
        self.customerId = thriftBaseOrder.customerId
        self.id = thriftBaseOrder.id.split(self.idPrefix)[1]
        self.invoiceNumber = thriftBaseOrder.invoiceNumber
        self.orderType = thriftBaseOrder.orderType
        self.transactionId = thriftBaseOrder.transactionId

    def is_valid(self):
        return True