def test_get_entry(self): entry = self.create_empty_transaction() posting = data.create_simple_posting(entry, 'Assets:Bank:Checking', '123.45', 'USD') self.assertEqual(entry, data.get_entry(entry)) self.assertEqual(entry, data.get_entry(data.TxnPosting(entry, posting)))
def render_real_htmldiv(self, real_root, options_map, file): account_types = options.get_account_types(options_map) for root in (account_types.assets, account_types.liabilities): oss = io.StringIO() table = tree_table.tree_table(oss, realization.get(real_root, root), None, ['Account', 'Last Entry']) num_cells = 0 for real_account, cells, row_classes in table: if not isinstance(real_account, realization.RealAccount): continue last_posting = realization.find_last_active_posting( real_account.txn_postings) # Don't render updates to accounts that have been closed. # Note: this is O(N), maybe we can store this at realization. if last_posting is None or isinstance(last_posting, data.Close): continue last_date = data.get_entry(last_posting).date # Skip this posting if a cutoff date has been specified and the # account has been updated to at least the cutoff date. if self.args.cutoff and self.args.cutoff <= last_date: continue # Okay, we need to render this. Append. cells.append( data.get_entry(last_posting).date if real_account. txn_postings else '-') num_cells += 1 if num_cells: file.write(oss.getvalue())
def render_real_text(self, real_root, price_map, price_date, options_map, file): rows = [] account_types = options.get_account_types(options_map) for root in (account_types.assets, account_types.liabilities): for unused_first_line, unused_cont_line, real_account in realization.dump( realization.get(real_root, root)): last_posting = realization.find_last_active_posting( real_account.txn_postings) # Don't render updates to accounts that have been closed. # Note: this is O(N), maybe we can store this at realization. if last_posting is None or isinstance(last_posting, data.Close): continue last_date = data.get_entry(last_posting).date # Skip this posting if a cutoff date has been specified and the # account has been updated to at least the cutoff date. if self.args.cutoff and self.args.cutoff <= last_date: continue rows.append((real_account.account, last_date)) table_ = table.create_table(rows, [(0, 'Account'), (1, 'Last Date', '{}'.format)]) table.render_table(table_, file, 'text')
def _activity_by_account(self, account_name=None): nb_activity_by_account = [] for real_account in realization.iter_children(self.root_account): if not isinstance(real_account, RealAccount): continue if account_name and real_account.account != account_name: continue last_posting = realization.find_last_active_posting( real_account.txn_postings) if last_posting is None or isinstance(last_posting, Close): continue entry = get_entry(last_posting) nb_activity_by_account.append({ 'account': real_account.account, 'last_posting_date': entry.date, 'last_posting_filename': entry.meta['filename'], 'last_posting_lineno': entry.meta['lineno'] }) return nb_activity_by_account
def last_entry(self, account_name): """The last entry of the account if it is not a Close entry. """ account = realization.get_or_create(self.all_root_account, account_name) last = realization.find_last_active_posting(account.txn_postings) if last is None or isinstance(last, Close): return return get_entry(last)
def last_account_activity_in_days(self, account_name): real_account = realization.get_or_create(self.all_root_account, account_name) last_posting = realization.find_last_active_posting( real_account.txn_postings) if last_posting is None or isinstance(last_posting, Close): return 0 entry = get_entry(last_posting) return (datetime.date.today() - entry.date).days
def last_entry(self, account_name: str) -> Directive | None: """Get last entry of an account. Args: account_name: An account name. Returns: The last entry of the account if it is not a Close entry. """ account = realization.get_or_create(self.all_root_account, account_name) last = realization.find_last_active_posting(account.txn_postings) if last is None or isinstance(last, Close): return None return get_entry(last)