def show_categories(self):
        """
        Fetches the categories and subcategories from DB, builds tree
        and shows it in the GUI.
        """
        cat_model = TreeModel(('Categories', ))
        self.categoriesView.setModel(cat_model)

        categories = self.orm.fetch_parents()
        for category in categories:
            item = TreeItem(category, cat_model.rootItem)
            cat_model.rootItem.appendChild(item)

            subs = self.orm.fetch_subcategories_for_parent(category)

            for sub in subs:
                sub_item = TreeItem(sub, item)
                item.appendChild(sub_item)

        self.categoriesView.expandAll()
Example #2
0
    def _update_accounts(self):
        """
        Fetches account list from DB and builds a tree model of accounts.
        Adds subtotal and grand total to that model.
        """
        accounts = self.orm.fetch_accounts_summary()
        account_dict = order_accounts(accounts)

        for key, accs in account_dict.items():
            item = TreeItem((key, ''), self.rootItem)
            self.rootItem.appendChild(item)
            for acc in accs:
                acc_item = TreeItem(acc, item)
                item.appendChild(acc_item)
            # Add type total
            if len(accs) > 1:
                sub_balance = sum(acc.balance for acc in accs if not acc.exbudget)
                subtotal = TreeItem(('Total', sub_balance), item)
                item.appendChild(subtotal)

        # Add grand total
        total_balance = sum([acc.balance for acc in accounts if not acc.exbudget])
        total = TreeItem(('Grand Total', total_balance), self.rootItem)
        self.rootItem.appendChild(total)