Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
children of, or create under.
account_name: A string, the name of the direct or indirect child leaf
to get or create.
Returns:
A RealAccount instance for the child, or the default value, if the child
is not found.
"""
if not isinstance(account_name, str):
raise ValueError
components = account.split(account_name)
path = []
for component in components:
path.append(component)
real_child = real_account.get(component, None)
if real_child is None:
real_child = RealAccount(account.join(*path))
real_account[component] = real_child
real_account = real_child
return real_account
Args:
entry: An entry.
predicate: A predicate for account names.
Returns:
True if predicate is True for any account of the entry.
"""
if isinstance(entry, Transaction):
return any(predicate(posting.account) for posting in entry.postings)
if isinstance(entry, Custom):
return any(
predicate(val.value)
for val in entry.values
if val.dtype == account.TYPE
)
return hasattr(entry, "account") and predicate(entry.account)
txn_postings_map[posting.account].append(
TxnPosting(entry, posting))
elif isinstance(entry, (Open, Close, Balance, Note, Document)):
# Append some other entries in the realized list.
txn_postings_map[entry.account].append(entry)
elif isinstance(entry, Pad):
# Insert the pad entry in both realized accounts.
txn_postings_map[entry.account].append(entry)
txn_postings_map[entry.source_account].append(entry)
elif isinstance(entry, Custom):
# Insert custom entry for each account in its values.
for custom_value in entry.values:
if custom_value.dtype == account.TYPE:
txn_postings_map[custom_value.value].append(entry)
return txn_postings_map
def get_previous_accounts(options):
"""Return account names for the previous earnings, balances and conversion accounts.
Args:
options: a dict of ledger options.
Returns:
A tuple of 3 account objects, for booking previous earnings,
previous balances, and previous conversions.
"""
equity = options['name_equity']
account_previous_earnings = account.join(equity,
options['account_previous_earnings'])
account_previous_balances = account.join(equity,
options['account_previous_balances'])
account_previous_conversions = account.join(equity,
options['account_previous_conversions'])
return (account_previous_earnings,
account_previous_balances,
account_previous_conversions)
def __call__(self, context):
args = self.eval_args(context)
return account.leaf(args[0])
options_map: A dict of options, that confirms to beancount.parser.options.
subaccount: A string, and optional the name of a subaccount to create
under an account to book the unrealized gain. If this is left to its
default value, the gain is booked directly in the same account.
Returns:
A list of entries, which includes the new unrealized capital gains entries
at the end, and a list of errors. The new list of entries is still sorted.
"""
errors = []
meta = data.new_metadata('', 0)
account_types = options.get_account_types(options_map)
# Assert the subaccount name is in valid format.
if subaccount:
validation_account = account.join(account_types.assets, subaccount)
if not account.is_valid(validation_account):
errors.append(
UnrealizedError(meta,
"Invalid subaccount name: '{}'".format(subaccount),
None))
return entries, errors
if not entries:
return (entries, errors)
# Group positions by (account, cost, cost_currency).
price_map = prices.build_price_map(entries)
holdings_list = holdings.get_final_holdings(entries, price_map=price_map)
# Group positions by (account, cost, cost_currency).
holdings_list = holdings.aggregate_holdings_by(
def get_current_accounts(options):
"""Return account names for the current earnings and conversion accounts.
Args:
options: a dict of ledger options.
Returns:
A tuple of 2 account objects, one for booking current earnings, and one
for current conversions.
"""
equity = options['name_equity']
account_current_earnings = account.join(equity,
options['account_current_earnings'])
account_current_conversions = account.join(equity,
options['account_current_conversions'])
return (account_current_earnings,
account_current_conversions)
def __call__(self, context):
args = self.eval_args(context)
return account.parent(args[0])
logging.error("The importer '%s' file_name() method should not date the "
"returned filename. Implement file_date() instead.")
# We need a simple filename; remove the directory part if there is one.
clean_basename = path.basename(clean_filename)
# Remove whitespace if requested.
if idify:
clean_basename = misc_utils.idify(clean_basename)
# Prepend the date prefix.
new_filename = '{0:%Y-%m-%d}.{1}'.format(date, clean_basename)
# Prepend destination directory.
new_fullname = path.normpath(path.join(destination,
file_account.replace(account.sep, os.sep),
new_filename))
# Print the filename and which modules matched.
if logfile is not None:
logfile.write('Importer: {}\n'.format(importer.name() if importer else '-'))
logfile.write('Account: {}\n'.format(file_account))
logfile.write('Date: {} (from {})\n'.format(date, date_source))
logfile.write('Destination: {}\n'.format(new_fullname))
logfile.write('\n')
return new_fullname
"""
# Generate all parent accounts in the account_set we're checking against, so
# that parent directories with no corresponding account don't warn.
accounts_with_parents = set(accounts)
for account_ in accounts:
while True:
parent = account.parent(account_)
if not parent:
break
if parent in accounts_with_parents:
break
accounts_with_parents.add(parent)
account_ = parent
errors = []
for directory, account_name, _, _ in account.walk(document_dir):
if account_name not in accounts_with_parents:
errors.append(ValidateDirectoryError(
"Invalid directory '{}': no corresponding account '{}'".format(
directory, account_name)))
return errors