def loadYearSummary(self): """ load amounts for each transaction type, can we use the yearView directly? -- Yes! When we try to load year amount from doctest, we alway got ConnectionStateError from method searchTransactions. The error is raised when we try to get the physical path for the bkfolder. We need test this in a functional doctest text file. #>>> self.yearView.loadYearSummary() #>>> len(self.yearView.yearSummary) #2 """ for trxType in self.bkfolder.transactionTypes(): typeSummary = {} # the summary for business business percentage. typeSummaryBp = {} # go throught each category under this type. for category in self.bkfolder.getCategories(trxType): # set the initial value here to hold the spot for no # transaction catetories. categorySummary = {'subtotal' : 0.0, 'gst' : 0.0, 'pst' : 0.0} categoryBp = self.getCategoryBuzPercent(trxType, category) # search for all transaction under this category. query = { 'transactionDate' : getYearQuery(int(self.year)), 'transactionType' : trxType, 'transactionCategory' : category } trxs = self.bkfolder.searchTransactions(query) # calculate the summary. for trx in trxs: transaction = trx.getObject() categorySummary['subtotal'] += transaction.subtotal() categorySummary['gst'] += transaction.gst() categorySummary['pst'] += transaction.pst() # add to type summary. typeSummary[category] = categorySummary # preparing the BP summary. categorySummaryBp = {} categorySummaryBp['subtotal'] = categorySummary['subtotal'] * categoryBp / 100 categorySummaryBp['gst'] = categorySummary['gst'] * categoryBp / 100 categorySummaryBp['pst'] = categorySummary['pst'] * categoryBp / 100 typeSummaryBp[category] = categorySummaryBp # add to year summary. self.yearSummary[trxType] = typeSummary self.yearSummary[trxType + 'bp'] = typeSummaryBp
def getAmounts(self, trxType, year): """ the smount for sutotal, gst, pst as tuple """ query = { 'transactionDate' : getYearQuery(year), 'transactionType' : trxType } trxs = self.bkfolder.searchTransactions(query) subtotal = 0 gst = 0 pst = 0 for trx in trxs: obj = trx.getObject() subtotal += obj.subtotal() gst += obj.gst() pst += obj.pst() return (subtotal, gst, pst)
def getTransactions(self): query = { 'transactionDate' : getYearQuery(int(self.year)), 'transactionType' : self.trxType, 'transactionCategory' : self.category } transactions = [] trxs = self.bkfolder.searchTransactions(query) for trx in trxs: transaction = {} obj = trx.getObject() transaction['id'] = obj.id transaction['title'] = obj.title transaction['date'] = obj.transactionDate().strftime('%Y-%m-%d') transaction['description'] = obj.description transaction['editUrl'] = '/'.join(obj.getPhysicalPath()) + '/edit' summary = { 'subtotal' : obj.subtotal(), 'gst' : obj.gst(), 'pst' : obj.pst()} transaction['summary'] = summary self.categoryTotal['subtotal'] += obj.subtotal() self.categoryTotal['gst'] += obj.gst() self.categoryTotal['pst'] += obj.pst() # calculate BP total. self.categoryBpTotal['subtotal'] = self.categoryTotal['subtotal'] * self.categoryBp / 100 self.categoryBpTotal['gst'] = self.categoryTotal['gst'] * self.categoryBp / 100 self.categoryBpTotal['pst'] = self.categoryTotal['pst'] * self.categoryBp / 100 # add to transactions. transactions.append(transaction) return transactions