Subversion Repositories SmartDukaan

Rev

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

'''
Created on 19-Sep-2012

@author: rajveer
'''
from elixir.entity import Entity
from elixir.fields import Field
from elixir.options import using_options, using_table_options
from elixir.relationships import ManyToOne
from shop2020.thriftpy.model.v1.order.ttypes import \
    UserWalletHistory as tUserWalletHistory, WalletReferenceType
from shop2020.utils.Utils import to_py_date, to_java_date
from sqlalchemy.types import Integer, DateTime, String

class UserWalletHistory(Entity):
    '''
    classdocs
    '''
    id = Field(Integer, primary_key=True, autoincrement=True)
    amount = Field(Integer)
    refundable_amount = Field(Integer)
    wallet = ManyToOne("UserWallet")
    reference = Field(Integer)
    reference_type = Field(String(20))
    wallet_type = Field(String(20))
    description = Field(String(192))
    timestamp = Field(DateTime)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

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


    def to_thrift_object(self, ):
        '''
        Copies attributes to thrift object
        '''
        thriftObject = tUserWalletHistory()
        thriftObject.id = self.id
        thriftObject.amount = self.amount
        thriftObject.refundableAmount = self.refundable_amount
        thriftObject.walletId = self.wallet.id
        thriftObject.timestamp = to_java_date(self.timestamp)
        thriftObject.referenceNumber = self.reference
        thriftObject.referenceType = WalletReferenceType._NAMES_TO_VALUES.get(self.reference_type)
        thriftObject.description = self.description
        return thriftObject
    
    def from_thrift_object(self, thriftUserWalletHistory):
        self.id = thriftUserWalletHistory.id
        self.amount = thriftUserWalletHistory.amount
        self.orderId = thriftUserWalletHistory.orderId
        self.wallet.id = thriftUserWalletHistory.walletId
        self.timestamp = to_py_date(thriftUserWalletHistory.timestamp)
        

    def is_valid(self):
        return True