NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

transactionsPanel.py (10831B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\wallet\panels\transactionsPanel.py
      2 import blue
      3 import log
      4 from carbon.common.script.util.format import FmtDate
      5 from carbonui import uiconst
      6 from carbonui.control.combo import Combo
      7 from carbonui.primitives.container import Container
      8 from carbonui.util.various_unsorted import SortListOfTuples
      9 from eve.client.script.ui import eveColor
     10 from eve.client.script.ui.control.entries.generic import Generic
     11 from eve.client.script.ui.control.entries.util import GetFromClass
     12 from eve.client.script.ui.shared.neocom.wallet import walletConst, transactionsUtil
     13 from eve.client.script.ui.shared.neocom.wallet.panels.baseTransactionsPanel import TransactionsScroll, BaseTransaction, BaseTransactionsList, BaseTransactionsPanel, GetTransactionKeyVal
     14 from eve.client.script.ui.shared.neocom.wallet.transactionsUtil import GetTransactionHint
     15 from eve.client.script.ui.shared.neocom.wallet.walletConst import WALLET_CORPTRANSACTIONS_SCROLLID
     16 from eve.client.script.ui.shared.neocom.wallet.walletUtil import FmtWalletCurrency
     17 from eve.common.lib import appConst as const
     18 from eve.common.script.util.walletEntryFormat import FmtWalletEntry
     19 from eveaccounting import get_accounting_key_for_name
     20 from eveservices.menu import GetMenuService
     21 from localization import GetByLabel
     22 from timeDateHelpers.const import MONTHANDYEAR_NAME_TEXT
     23 DATE_FILTER_LAST30DAYS = (None, None)
     24 
     25 class Transaction(BaseTransaction):
     26 
     27     def __init__(self, transactionData):
     28         super(Transaction, self).__init__(transactionData)
     29         self.amount = self.data.amount
     30         self.balance = self.data.balance
     31         refType = sm.GetService('account').GetRefTypeKeyByID(self.data.entryTypeID)
     32         self.dateString = GetByLabel('UI/Wallet/WalletWindow/FmtWalletDate', dt=self.data.transactionDate)
     33         self.typeString = refType.entryTypeName
     34         self.amountString = FmtWalletCurrency(self.data.amount, self.data.currency)
     35         self.balanceString = FmtWalletCurrency(self.data.balance, self.data.currency)
     36         self.descriptionString = FmtWalletEntry(self.data.entryTypeID, self.data.ownerID1, self.data.ownerID2, self.data.referenceID, amount=self.data.amount, reason=self.data.description)
     37         self.hint = GetTransactionHint(self.data)
     38         if self.hint:
     39             self.descriptionString = GetByLabel('UI/Wallet/WalletWindow/HintExtraReference', refText=self.descriptionString)
     40 
     41 
     42 class TransactionsList(BaseTransactionsList):
     43 
     44     def __init__(self, scrollHeaders):
     45         super(TransactionsList, self).__init__(scrollHeaders)
     46         self._entryTypes = set()
     47 
     48     def LoadTransactions(self, transactions):
     49         super(TransactionsList, self).LoadTransactions(transactions)
     50         self._entryTypes = set([ transaction.data.entryTypeID for transaction in self._allTransactions ])
     51 
     52     def GetAvailableEntryTypes(self):
     53         return self._entryTypes
     54 
     55 
     56 class TransactionsPanel(BaseTransactionsPanel):
     57     default_name = 'TransactionsPanel'
     58 
     59     def ApplyAttributes(self, attributes):
     60         super(TransactionsPanel, self).ApplyAttributes(attributes)
     61         self.scroll.sr.id = WALLET_CORPTRANSACTIONS_SCROLLID
     62 
     63     def _BuildOptionsCont(self):
     64         return Container(name='transactionsOptionsCont', parent=self, align=uiconst.TOTOP, height=32, idx=1)
     65 
     66     def _BuildScroll(self):
     67         scroll = TransactionsScroll(parent=self, padTop=8)
     68         scroll.onSort.connect(self._OnSort)
     69         return scroll
     70 
     71     def _BuildTransactionsList(self, scrollHeaders):
     72         return TransactionsList(scrollHeaders)
     73 
     74     def GetScrollHeaders(self):
     75         return [(GetByLabel('UI/Common/Date'), 'dateString'),
     76          (GetByLabel('UI/Wallet/WalletWindow/ColHeaderType'), 'typeString'),
     77          (GetByLabel('UI/Wallet/WalletWindow/ColHeaderAmount'), 'amount'),
     78          (GetByLabel('UI/Wallet/WalletWindow/ColHeaderBalance'), 'balance'),
     79          (GetByLabel('UI/Wallet/WalletWindow/ColHeaderDescription'), 'descriptionString')]
     80 
     81     def Close(self):
     82         super(TransactionsPanel, self).Close()
     83         settings.user.ui.Set('accountreftype', None)
     84 
     85     def ConstructLayout(self):
     86         self.referenceTypeCombo = Combo(parent=self.transactionsOptionsCont, name='accountreftype', callback=self.OnCombo, width=110, align=uiconst.TOLEFT, padRight=6)
     87         self.dateCombo = Combo(parent=self.transactionsOptionsCont, name='dateCombo', callback=self.OnDateCombo, width=130, align=uiconst.TOLEFT, padRight=6, options=self.GetDateComboOptions())
     88         super(TransactionsPanel, self).ConstructLayout()
     89 
     90     def GetDateComboOptions(self):
     91         options = []
     92         for year, month in transactionsUtil.GetLastNYearMonthTuples(6)[1:]:
     93             options.append((GetByLabel(MONTHANDYEAR_NAME_TEXT[month], year=year), (year, month + 1)))
     94 
     95         options.insert(0, (GetByLabel('UI/Wallet/WalletWindow/Last30Days'), DATE_FILTER_LAST30DAYS))
     96         return options
     97 
     98     def OnDateCombo(self, *args):
     99         self.UpdateTransactionsAndPopulateScroll()
    100 
    101     def OnDateEditReturn(self, *args):
    102         self.UpdateTransactionsAndPopulateScroll()
    103 
    104     def OnCombo(self, entry, header, value, *args):
    105         settings.user.ui.Set('accountreftype', value)
    106         self.UpdateTransactionsAndPopulateScroll()
    107 
    108     def UpdateTransactions(self):
    109         transactions = self._GetTransactions()
    110         transactionKeyVals = [ GetTransactionKeyVal(t) for t in transactions ]
    111         ownerIDs = set()
    112         for t in transactionKeyVals:
    113             ownerIDs.add(t.ownerID1)
    114             ownerIDs.add(t.ownerID2)
    115 
    116         cfg.eveowners.Prime(ownerIDs)
    117         transactions = []
    118         for t in transactionKeyVals:
    119             try:
    120                 transactions.append(Transaction(t))
    121             except AttributeError as exc:
    122                 log.LogWarn('Wallet Journal: failed to load data for entryType {}, error: {}'.format(t.entryTypeID, exc))
    123                 continue
    124 
    125         self._transactionsList.LoadTransactions(transactions)
    126         self.UpdateReferenceTypeCombo(self._transactionsList.GetAvailableEntryTypes())
    127         self.UpdateTransactionsByPage()
    128 
    129     def IsTransactionVisible(self, transaction):
    130         filterValue = self.referenceTypeCombo.GetValue()
    131         if not filterValue:
    132             return True
    133         else:
    134             return transaction.data.entryTypeID == self.referenceTypeCombo.GetValue()
    135 
    136     def _GetDateTimeSelection(self):
    137         return self.dateCombo.GetValue()
    138 
    139     def _GetTransactions(self):
    140         raise NotImplementedError
    141 
    142     def GetScrollEntry(self, transaction):
    143         refType = sm.GetService('account').GetRefTypeKeyByID(transaction.data.entryTypeID)
    144         originalType = self.referenceTypeCombo.GetValue()
    145         if originalType and refType.entryTypeID != originalType:
    146             return None
    147         if not refType:
    148             log.LogWarn('Wallet Journal: No entryType found for entryTypeID', transaction.data.entryTypeID)
    149             return None
    150         textList = [transaction.dateString, transaction.typeString]
    151         color = eveColor.HOT_RED_HEX if transaction.data.amount < 0 else eveColor.SUCCESS_GREEN_HEX
    152         amountString = '<right><color=%s>%s</color>' % (color, transaction.amountString)
    153         textList.append(amountString)
    154         balanceString = '<color=0xffffffff>%s</color>' % transaction.balanceString
    155         textList.append(balanceString)
    156         descString = '<left>%s' % transaction.descriptionString
    157         textList.append(descString)
    158         isClickable = transactionsUtil.ShouldTransactionTextBeClickable(transaction.data.entryTypeID)
    159         return GetFromClass(Generic, {'rec': transaction.data,
    160          'label': '<t>'.join(textList),
    161          'labelState': uiconst.UI_NORMAL if isClickable else uiconst.UI_DISABLED,
    162          'name': 'transaction_{}'.format(transaction.data.entryTypeID),
    163          'sort_%s' % GetByLabel('UI/Wallet/WalletWindow/ColHeaderAmount'): transaction.data.amount,
    164          'sort_%s' % GetByLabel('UI/Wallet/WalletWindow/ColHeaderBalance'): transaction.data.balance,
    165          'sort_%s' % GetByLabel('UI/Common/Date'): (transaction.data.transactionDate, transaction.data.sortValue),
    166          'sort_%s' % GetByLabel('UI/Wallet/WalletWindow/ColHeaderCurrency'): transaction.data.currency,
    167          'hint': transaction.hint,
    168          'GetMenu': self._GetMenuForTransactionScrollEntity})
    169 
    170     def _GetMenuForTransactionScrollEntity(self, scrollEntity):
    171         if scrollEntity.sr.node.rec.entryTypeID != const.refPlayerDonation:
    172             return []
    173         transactionSenderID = scrollEntity.sr.node.rec.ownerID1
    174         transactionReceiverID = scrollEntity.sr.node.rec.ownerID2
    175         sender = cfg.eveowners.Get(transactionSenderID)
    176         receiver = cfg.eveowners.Get(transactionReceiverID)
    177         menuSvc = GetMenuService()
    178         menuList = []
    179         menuList.append((sender.name, ('isDynamic', menuSvc.GetMenuFromItemIDTypeID, (transactionSenderID, sender.typeID))))
    180         menuList.append((receiver.name, ('isDynamic', menuSvc.GetMenuFromItemIDTypeID, (transactionReceiverID, receiver.typeID))))
    181         return menuList
    182 
    183     def GetNow(self):
    184         return FmtDate(blue.os.GetWallclockTime(), 'sn')
    185 
    186     def _GetCashAccountingKeys(self):
    187         accountKeys = [get_accounting_key_for_name('cash')]
    188         for i in range(2, 8):
    189             keyID = get_accounting_key_for_name('cash%d' % i)
    190             accountKeys.append(keyID)
    191 
    192         return accountKeys
    193 
    194     def _GetAccountKeyList(self):
    195         divisions = sm.GetService('corp').GetDivisionNames()
    196         keylist = []
    197         accountingKeys = self._GetCashAccountingKeys()
    198         for keyID, desc in zip(accountingKeys, [ divisions[i] for i in xrange(8, 15) ]):
    199             if keyID == session.corpAccountKey or session.corprole & (const.corpRoleAccountant | const.corpRoleJuniorAccountant):
    200                 keylist.append([desc, keyID])
    201 
    202         return keylist
    203 
    204     def UpdateReferenceTypeCombo(self, entryTypes):
    205         options = self.GetReferenceTypeComboOptions(entryTypes)
    206         self.referenceTypeCombo.LoadOptions(options, settings.user.ui.Get('accountreftype', None))
    207 
    208     def GetReferenceTypeComboOptions(self, entryTypes = None):
    209         reflist = []
    210         for refTypeID in entryTypes:
    211             refType = sm.GetService('account').GetRefTypeKeyByID(refTypeID)
    212             if refType and refType.entryTypeID not in walletConst.SKIP_REF_TYPES and refType.entryTypeID < const.refMaxEve:
    213                 reflist.append((refType.entryTypeName.lower(), [refType.entryTypeName, refType.entryTypeID]))
    214 
    215         reflist = SortListOfTuples(reflist)
    216         reflist.insert(0, (GetByLabel('UI/Wallet/WalletWindow/AccountKeyAllTypes'), None))
    217         return reflist
    218 
    219     def ShowTransactions(self, accountKey = None):
    220         self.UpdateTransactionsAndPopulateScroll()