accountsvc.py (5646B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\services\accountsvc.py 2 import blue 3 import localization 4 import utillib 5 from carbon.common.script.sys.service import Service 6 from carbon.common.script.sys.serviceConst import ROLE_SERVICE 7 from carbonui import uiconst 8 from eve.client.script.ui.shared.neocom.wallet.transactionsUtil import GetDerivedTransactions 9 from eve.common.lib import appConst 10 from eveexceptions import UserError 11 from player_messaging.client.ui_message import prompt_player_fsd_dialog 12 13 class Account(Service): 14 __exportedcalls__ = {'GetEntryTypes': [], 15 'GetWalletDivisionsInfo': [], 16 'GetDefaultContactCost': [], 17 'SetDefaultContactCost': [], 18 'AskYesNoQuestion': [ROLE_SERVICE]} 19 __guid__ = 'svc.account' 20 __notifyevents__ = ['ProcessSessionChange', 'OnAccountChange', 'ProcessUIRefresh'] 21 __servicename__ = 'account' 22 __displayname__ = 'Accounting Service' 23 24 def __init__(self): 25 Service.__init__(self) 26 self.dataLifeTime = appConst.MIN * 1 27 self.data = {} 28 self.walletDivisionsInfo = None 29 self.defaultContactCost = None 30 self.blocked = None 31 self.nocharge = None 32 self.transactionCache = {} 33 self.corpTransactionCache = {} 34 35 def Init(self): 36 self.dataLifeTime = appConst.MIN * 1 37 self.data = {} 38 self.walletDivisionsInfo = None 39 self.defaultContactCost = None 40 self.blocked = None 41 self.nocharge = None 42 self.transactionCache = {} 43 self.corpTransactionCache = {} 44 45 def Run(self, memStream = None): 46 self.LogInfo('Starting AccountSvc') 47 self.ReleaseAccountSvc() 48 49 def Stop(self, memStream = None): 50 self.ReleaseAccountSvc() 51 52 def ProcessSessionChange(self, isremote, session, change): 53 if 'charid' in change and change['charid'][1] is not None: 54 self.ReleaseAccountSvc() 55 self.Init() 56 57 def OnAccountChange(self, accountKey, ownerID, balance): 58 self.transactionCache = {} 59 self.corpTransactionCache = {} 60 61 def GetAccountMgr(self): 62 if hasattr(self, 'moniker') and self.moniker is not None: 63 return self.moniker 64 self.moniker = sm.RemoteSvc('account') 65 return self.moniker 66 67 def ReleaseAccountSvc(self): 68 if hasattr(self, 'moniker') and self.moniker is not None: 69 self.moniker = None 70 self.data = {} 71 72 def ProcessUIRefresh(self): 73 self.data = {} 74 75 def GetStaticData(self, itemName, trCol = None, trID = None, *args): 76 if itemName not in self.data: 77 account = self.GetAccountMgr() 78 data = getattr(account, itemName)(*args) 79 for rec in data: 80 messageID = getattr(rec, trID, None) 81 translated = localization.GetByMessageID(messageID) 82 setattr(rec, trCol, translated) 83 84 self.data[itemName] = data 85 return self.data[itemName] 86 87 def GetEntryTypes(self): 88 return self.GetStaticData('GetEntryTypes', 'entryTypeName', 'entryTypeNameID') 89 90 def GetRefTypeKeyByID(self, entryTypeID): 91 for rec in self.GetEntryTypes(): 92 if rec.entryTypeID == entryTypeID: 93 return rec 94 95 def GetPersonalTransactions(self, year = None, month = None): 96 key = (year, month) 97 if key in self.transactionCache: 98 return self.transactionCache[key] 99 self.transactionCache[key] = self._GetPersonalTransactions(year, month) 100 return self.transactionCache[key] 101 102 def _GetPersonalTransactions(self, year, month): 103 transactions = self.GetAccountMgr().GetTransactions(appConst.accountingKeyCash, year, month, False) 104 transactionsWithDerived = [] 105 for transaction in transactions: 106 transactionsWithDerived.append(transaction) 107 transactionsWithDerived.extend(GetDerivedTransactions(transaction)) 108 109 return transactionsWithDerived 110 111 def GetCorpTransactions(self, accountKey, year, month): 112 key = (accountKey, year, month) 113 if key in self.corpTransactionCache: 114 return self.corpTransactionCache[key] 115 self.corpTransactionCache[key] = self.GetAccountMgr().GetTransactions(accountKey, year, month, True) 116 return self.corpTransactionCache[key] 117 118 def GetWalletDivisionsInfo(self, force = False): 119 now = blue.os.GetWallclockTime() 120 if self.walletDivisionsInfo is None or self.walletDivisionsInfo.expires < now or force: 121 self.walletDivisionsInfo = utillib.KeyVal(info=self.GetAccountMgr().GetWalletDivisionsInfo(), expires=now + 5 * appConst.MIN) 122 return self.walletDivisionsInfo.info 123 124 def AskYesNoQuestion(self, question, props, defaultChoice = 1): 125 if defaultChoice: 126 defaultChoice = uiconst.ID_YES 127 else: 128 defaultChoice = uiconst.ID_NO 129 return prompt_player_fsd_dialog(question, props, uiconst.YESNO, defaultChoice) == uiconst.ID_YES 130 131 def SetDefaultContactCost(self, cost): 132 if cost < 0: 133 raise UserError('ContactCostNegativeAmount') 134 self.GetAccountMgr().SetContactCost(cost) 135 self.defaultContactCost = cost 136 137 def GetDefaultContactCost(self): 138 if self.defaultContactCost is None: 139 self.defaultContactCost = self.GetAccountMgr().GetDefaultContactCost() 140 if self.defaultContactCost is None: 141 self.defaultContactCost = -1 142 return self.defaultContactCost 143 144 def BlockAll(self): 145 self.GetAccountMgr().SetContactCost(None) 146 self.defaultContactCost = -1