transactionsUtil.py (10492B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\wallet\transactionsUtil.py 2 import datetime 3 import sys 4 import types 5 import yaml 6 import evetypes 7 import log 8 from eve.client.script.ui.shared.neocom.wallet.walletUtil import FmtWalletCurrency, SafeGetName 9 from eve.common.lib import appConst 10 from eve.common.lib import appConst as const 11 from eve.common.script.util.walletEntryFormat import GetFreelanceProjectLinkFromPayoutReason 12 from evelink.client import corporation_link 13 from localization import GetByLabel, formatters 14 from utillib import KeyVal 15 descriptionByRefType = {appConst.refCorporationTaxNpcBounties: 'UI/Wallet/WalletWindow/HintNPCBountyTax', 16 appConst.refCorporationTaxAgentRewards: 'UI/Wallet/WalletWindow/HintAgentRewardTax', 17 appConst.refCorporationTaxAgentBonusRewards: 'UI/Wallet/WalletWindow/HintAgentBonusRewardTax', 18 appConst.refCorporationTaxRewards: 'UI/Wallet/WalletWindow/HintCorporateRewardTax', 19 appConst.refProjectDiscoveryTaxRewards: 'UI/Wallet/WalletWindow/HintProjectDiscoveryRewardTax', 20 appConst.refFreelanceContributionRewardsTax: 'UI/Wallet/WalletWindow/HintFreelanceProjectRewardTax'} 21 NO_TOOLTIP_TYPES = [appConst.refProjectPayouts, 22 appConst.refDailyGoalPayouts, 23 appConst.refCareerProgramPayouts, 24 appConst.refAchievementMilestoneReward, 25 appConst.refAchievementCategoryMilestoneReward] + appConst.COSMETIC_MARKET_TRANSACTION_REFS + appConst.FREELANCE_PROJECT_REFS 26 27 def GetDerivedTransactions(transaction): 28 derivedTransactions = [] 29 if not transaction.description: 30 return derivedTransactions 31 if transaction.description: 32 try: 33 descriptionDict = yaml.load(transaction.description, Loader=yaml.CSafeLoader) 34 if type(descriptionDict) == types.DictType: 35 for refTypeID in appConst.derivedTransactionParentMapping.keys(): 36 if refTypeID in descriptionDict: 37 try: 38 taxTransaction = _GetDerivedCorporationTaxTransaction(transaction, descriptionDict, refTypeID) 39 derivedTransactions.insert(0, taxTransaction) 40 except KeyError: 41 log.LogException('Failed to find derived corporation transaction for entry type %s' % refTypeID) 42 43 securityTaxTransaction = _GetDerivedSecurityTaxTransaction(transaction, descriptionDict) 44 if securityTaxTransaction: 45 derivedTransactions.append(securityTaxTransaction) 46 except yaml.scanner.ScannerError as e: 47 log.LogError('wallet::_GetDerivedTransactions: ScannerError: Could not parse wallet transaction description:', transaction.description) 48 sys.exc_clear() 49 50 return derivedTransactions 51 52 53 def _GetDerivedCorporationTaxTransaction(transaction, descriptionDict, entryTypeID): 54 corpID = descriptionDict[entryTypeID][0] 55 taxAmount = descriptionDict[entryTypeID][1] 56 taxTransaction = KeyVal(transaction) 57 taxTransaction.amount = -taxAmount 58 taxTransaction.sortValue = transaction.transactionID + 0.5 59 taxTransaction.ownerID2 = corpID 60 _, surcharge = descriptionDict.get(appConst.refBountySurcharge, (0, 0)) 61 taxPercentage = float(taxAmount) / (transaction.amount - surcharge + taxAmount) * 100 62 taxTransaction.entryTypeID = entryTypeID 63 transaction.amount += taxAmount 64 transaction.balance += taxAmount 65 descriptionArguments = {'taxPercentage': taxPercentage, 66 'corporationName': corporation_link(corpID), 67 'amountInIsk': FmtWalletCurrency(amt=appConst.minCorporationTaxAmount, currency=appConst.creditsISK)} 68 if entryTypeID == appConst.refCorporationTaxRewards: 69 donorCorpID = transaction.ownerID1 70 descriptionArguments['donorCorporationName'] = corporation_link(donorCorpID) 71 elif entryTypeID == appConst.refFreelanceContributionRewardsTax: 72 reason = descriptionDict['DESC'] 73 project_link = GetFreelanceProjectLinkFromPayoutReason(reason) 74 descriptionArguments['projectName'] = project_link 75 if entryTypeID in descriptionByRefType: 76 descriptionLabel = descriptionByRefType[entryTypeID] 77 taxTransaction.description = GetByLabel(descriptionLabel, **descriptionArguments) 78 else: 79 taxTransaction.description = '' 80 return taxTransaction 81 82 83 def _GetDerivedSecurityTaxTransaction(transaction, descriptionDict): 84 securityTaxAmount = descriptionDict.get('securityTaxAmount', 0.0) 85 if securityTaxAmount <= 0.0: 86 return 87 if transaction.entryTypeID in (appConst.refAgentMissionReward, appConst.refAgentMissionTimeBonusReward): 88 grossAmount = descriptionDict.get('grossRewardAmount', None) 89 securityTaxRefTypeID = appConst.refAgentMissionSecurityTax 90 elif transaction.entryTypeID in (appConst.refBountyPrize, appConst.refBountyPrizes): 91 grossAmount = descriptionDict.get('grossBountyAmount', None) 92 securityTaxRefTypeID = appConst.refNpcBountySecurityTax 93 else: 94 return 95 if grossAmount is None: 96 return 97 taxTransaction = KeyVal(transaction) 98 taxTransaction.amount = -securityTaxAmount 99 taxTransaction.transactionID = transaction.transactionID - 0.25 100 taxTransaction.sortValue = transaction.transactionID - 0.25 101 taxTransaction.entryTypeID = securityTaxRefTypeID 102 taxTransaction.ownerID2 = appConst.ownerCONCORD 103 taxTransaction.description = '' 104 transaction.amount = grossAmount 105 transaction.balance += securityTaxAmount 106 return taxTransaction 107 108 109 def ShouldTransactionTextBeClickable(entryTypeID): 110 if entryTypeID == appConst.refProjectPayouts: 111 return True 112 if entryTypeID in appConst.FREELANCE_PROJECT_REFS: 113 return True 114 return False 115 116 117 def GetTransactionHint(transaction): 118 if not transaction.description: 119 return None 120 try: 121 description = yaml.load(transaction.description, Loader=yaml.CSafeLoader) 122 except yaml.scanner.ScannerError as e: 123 log.LogError('wallet::_ParseDescription: ScannerError: Could not parse wallet transaction description:', transaction.description) 124 sys.exc_clear() 125 return None 126 127 if type(description) != types.DictType: 128 return None 129 hintLines = [] 130 if transaction.entryTypeID == const.refBountyReimbursement: 131 ownerIDs = description[const.recDescOwners].split(',') 132 if description.get(const.recDescOwnersTrunc, 0): 133 return GetByLabel('UI/Wallet/WalletWindow/HintBountyReimbursedTruncated', ownerList=formatters.FormatGenericList((cfg.eveowners.Get(ownerID).ownerName for ownerID in ownerIDs)), others=description.get(const.recDescOwnersTrunc, 0)) 134 else: 135 return GetByLabel('UI/Wallet/WalletWindow/HintBountyReimbursed', ownerList=formatters.FormatGenericList((cfg.eveowners.Get(ownerID).ownerName for ownerID in ownerIDs), useConjunction=True)) 136 elif transaction.entryTypeID == const.refBountyPrize: 137 try: 138 ownerIDs = description[const.recDescOwners].split(',') 139 except KeyError: 140 pass 141 else: 142 if description.get(const.recDescOwnersTrunc, 0): 143 return GetByLabel('UI/Wallet/WalletWindow/HintBountyPaidTruncated', ownerList=formatters.FormatGenericList((cfg.eveowners.Get(ownerID).ownerName for ownerID in ownerIDs)), others=description.get(const.recDescOwnersTrunc, 0)) 144 return GetByLabel('UI/Wallet/WalletWindow/HintBountyPaid', ownerList=formatters.FormatGenericList((cfg.eveowners.Get(ownerID).ownerName for ownerID in ownerIDs), useConjunction=True)) 145 146 elif transaction.entryTypeID in NO_TOOLTIP_TYPES: 147 return None 148 if const.recDescription in description: 149 hintLines.append(description[const.recDescription]) 150 if const.recDescNpcBountyList in description: 151 for typeID, numVictims in description.get(const.recDescNpcBountyList, {}).iteritems(): 152 hintLines.append(u'{} x {}'.format(SafeGetName(typeID), str(numVictims))) 153 154 if const.recDescNpcBountyListTruncated in description: 155 hintLines.append(GetByLabel('UI/Wallet/WalletWindow/HintBountyTruncated')) 156 if const.recStoreItems in description: 157 hintLines.append(GetByLabel('UI/Wallet/WalletWindow/HintVGpurchase')) 158 for typeID, qty in description.get(const.recStoreItems, []): 159 try: 160 typeName = evetypes.GetName(typeID) 161 except evetypes.TypeNotFoundException as e: 162 log.LogError('wallet::_ParseDescription: TypeNotFoundException', e) 163 sys.exc_clear() 164 continue 165 166 hintLines.append(GetByLabel('UI/Wallet/WalletWindow/HintItemNameQty', itemName=typeName, qty=int(qty))) 167 168 if transaction.entryTypeID == const.refPlanetaryConstruction and not hintLines: 169 ccUpgradeReason = '' 170 if 'oldLevel' in description: 171 ccUpgradeReason = GetByLabel('UI/PI/Planet/CommandCenterUpgradeReason', oldLevel=description['oldLevel'], newLevel=description['newLevel']) 172 constructionReason = '' 173 destructionReason = '' 174 if 'constructions' in description: 175 constructionParts = [] 176 for typeID, qty in description['constructions'].iteritems(): 177 constructionParts.append(GetByLabel('UI/Inventory/QuantityAndName', quantity=qty, name=evetypes.GetName(typeID))) 178 179 constructionReason = GetByLabel('UI/PI/Planet/ConstructionReason', planet=transaction.referenceID, constructions='\r\n'.join(constructionParts)) 180 if 'destructions' in description: 181 destructionParts = [] 182 for groupID, qty in description['destructions'].iteritems(): 183 destructionParts.append(GetByLabel('UI/Inventory/QuantityAndName', quantity=qty, name=evetypes.GetGroupNameByGroup(groupID))) 184 185 destructionReason = GetByLabel('UI/PI/Planet/DestructionReason', destructions='\r\n'.join(destructionParts)) 186 hintLines.append(GetByLabel('UI/PI/Planet/NetworkUpdateTransactionReason', ccUpgrade=ccUpgradeReason, constructions=constructionReason, destructions=destructionReason)) 187 hintText = '<br>'.join(hintLines) 188 return hintText or None 189 190 191 def GetLastNYearMonthTuples(numMonths): 192 today = datetime.date.today() 193 year = today.year 194 month = today.month 195 ret = [] 196 for i in xrange(numMonths): 197 month -= 1 198 if month == -1: 199 month = 11 200 year -= 1 201 ret.append((year, month)) 202 203 return ret