def build_accounts_report(period, filename=None, format='pdf'): ''' PDF: List of balances ''' if not filename: filename = get_temp_filename('pdf') doc = Document(title=_(u"Accounts balance for %s") \ % period.display_name(), landscape=True) table = Table(4) table.add_header_row([ Text(_(u"Account Number")), Text(_(u"Account Name")), Text(_(u"Budget")), Text(_(u"Balance"))]) # column widths table.set_column_width(10, 0) table.set_column_width(15, 2) table.set_column_width(15, 3) # column alignments table.set_alignment(Table.ALIGN_LEFT, column=0) table.set_alignment(Table.ALIGN_LEFT, column=1) table.set_alignment(Table.ALIGN_RIGHT, column=2) table.set_alignment(Table.ALIGN_RIGHT, column=3) accounts = [account_summary(account, period) \ for account in session.query(Account).all()] list_budget = [] list_balance = [] for account in accounts: table.add_row([ Text(unicode(account[0])), Text(unicode(account[1])), Text(formatted_number(account[2])), Text(formatted_number(account[3]))]) list_budget.append(account[2]) list_balance.append(account[3]) table.add_row([Text(u''), Text(u'TOTALS', bold=True), Text(formatted_number(sum(list_budget)), bold=True), Text(formatted_number(sum(list_balance)), bold=True)]) doc.add_element(table) gen = PDFGenerator(doc, filename) gen.render_document() return gen.get_filename()
def set_data_for(self, period=current_period()): self.data = [account_summary(account, period) for account in session.query(Account).all()]