How to use the beancount.core.number.ZERO function in beancount

To help you get started, we’ve selected a few beancount examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beancount / beancount / beancount / scripts / example.py View on Github external
{date_begin} open Income:CC:Employer1:Vacation         VACHR
        {date_begin} open Assets:CC:Employer1:Vacation         VACHR
        {date_begin} open Expenses:Vacation                    VACHR

        {date_begin} open Expenses:Health:Life:GroupTermLife
        {date_begin} open Expenses:Health:Medical:Insurance
        {date_begin} open Expenses:Health:Dental:Insurance
        {date_begin} open Expenses:Health:Vision:Insurance

        ;{date_begin} open Expenses:Vacation:Employer

    """, **locals())

    date_prev = None

    contrib_retirement = ZERO
    contrib_socsec = ZERO

    biweekly_pay = annual_salary / 26
    gross = biweekly_pay

    medicare = gross * D('0.0231')
    federal = gross * D('0.2303')
    state = gross * D('0.0791')
    city = gross * D('0.0379')
    sdi = D('1.12')

    lifeinsurance = D('24.32')
    dental = D('2.90')
    medical = D('27.38')
    vision = D('42.30')
github beancount / beancount / beancount / core / amount.py View on Github external
def abs(amount):
    """Return the absolute value of the given amount.

    Args:
      amount: An instance of Amount.
    Returns:
      An instance of Amount.
    """
    return (amount
            if amount.number >= ZERO
            else Amount(-amount.number, amount.currency))
github beancount / beancount / src / python / beancount / core / amount.py View on Github external
def abs(amount):
    """Return the absolute value of the given amount.

    Args:
      amount: An instance of Amount.
    Returns:
      An instance of Amount.
    """
    return (amount
            if amount.number >= ZERO
            else Amount(-amount.number, amount.currency))


A = from_string = Amount.from_string  # pylint: disable=invalid-name
NULL_AMOUNT = Amount(ZERO, '')
github jbms / beancount-import / beancount_import / source / ultipro_google_statement.py View on Github external
expected_net_pay = sum(
        (x['Amount'] for key, x in all_values['Net Pay Distribution']), ZERO)
    listed_net_pay = general['Net Pay']['Amount']
    summary_net_pay = pay_summary['Current']['Net Pay']
    assert expected_net_pay == listed_net_pay, (expected_net_pay, listed_net_pay)
    assert summary_net_pay == listed_net_pay, (summary_net_pay, listed_net_pay)

    errors = []
    for period in [
            'Current',
            # Skip YTD because it may be incorrect if two pay statements occur on the same day.
            # 'YTD',
    ]:
        for value in ('Earnings', 'Taxes', 'Deductions'):
            expected_value = sum((x[period] for key, x in all_values[value]),
                                 ZERO)
            summary_value = pay_summary[period][value]
            if expected_value != summary_value:
                errors.append(
                    'The %r section specifies %s %s of %s, but computed total is %s.'
                    % (pay_summary_section, period, value, summary_value,
                       expected_value))
    return ParseResult(general=general, all_values=all_values, errors=errors)
github beancount / beancount / beancount / reports / export_reports.py View on Github external
def _render_debug_holdings(self, holdings, title=None):
        if title:
            sys.stderr.write('{}:\n'.format(title))
            sys.stderr.write('----------------------------------------\n')
        for holding in holdings:
            sys.stderr.write(self.HOLDING_FORMAT.format(
                h=holding,
                cost_number=holding.cost_number or ZERO,
                cost_currency=holding.cost_currency))
        sys.stderr.write('\n')
github lidongchao / BeancountSample / Importers / beanmaker.py View on Github external
"""
    debit, credit = None, None
    if Col.AMOUNT in iconfig:
        amount = row[iconfig[Col.AMOUNT]]
        # Distinguish debit or credit
        if DRCR_status == Debit_or_credit.CREDIT:
            credit = amount
        else:
            debit = amount
    else:
        debit, credit = [row[iconfig[col]] if col in iconfig else None
                         for col in [Col.AMOUNT_DEBIT, Col.AMOUNT_CREDIT]]

    # If zero amounts aren't allowed, return null value.
    is_zero_amount = ((credit is not None and cast_to_decimal(credit) == ZERO) and
                      (debit is not None and cast_to_decimal(debit) == ZERO))
    if not allow_zero_amounts and is_zero_amount:
        return (None, None)


    return (-cast_to_decimal(debit) if debit else None,
            cast_to_decimal(credit) if credit else None)
github beancount / beancount / beancount / core / interpolate.py View on Github external
if cost_number is None or cost_number is MISSING:
                            continue
                        cost_tolerance = min(tolerance * cost_number, cost_tolerance)
                cost_tolerances[cost_currency] += cost_tolerance

            # Compute bounds on the smallest digit of the number implied as cost.
            price = posting.price
            if isinstance(price, Amount) and isinstance(price.number, Decimal):
                price_currency = price.currency
                price_tolerance = min(tolerance * price.number, MAXIMUM_TOLERANCE)
                cost_tolerances[price_currency] += price_tolerance

    for currency, tolerance in cost_tolerances.items():
        tolerances[currency] = max(tolerance, tolerances.get(currency, -1024))

    default = tolerances.pop('*', ZERO)
    return defdict.ImmutableDictWithDefault(tolerances, default=default)
github beancount / beancount / experiments / washsales / wash_calculator.py View on Github external
# Skip other directives.
        if not isinstance(entry, data.Transaction):
            continue

        # Skip entries after the relevant period.
        if entry.date > date_end:
            continue

        # Skip entries not relevant to the currency.
        if not any(posting.position.lot.currency in symbols
                   for posting in entry.postings):
            continue

        # Calculate the fee amount and the total price, in order to split the
        # fee later on.
        fee_total = ZERO
        units_total = ZERO
        for posting in entry.postings:
            if account_types.get_account_type(posting.account) == acc_types.expenses:
                fee_total += posting.position.number
            if (account_types.get_account_type(posting.account) == acc_types.assets and
                posting.position.lot.cost is not None):
                units_total += posting.position.number

        # Loop through the postings and create trade entries for them, computing
        # proceeds and fees and all details required to wash sales later on.
        booked = False
        for posting in entry.postings:
            pos = posting.position
            if pos.lot.currency not in symbols:
                continue
github jbms / beancount-import / beancount_import / matching.py View on Github external
def get_match_group_key(weight: Amount) -> MatchGroupKey:
    return MatchGroupKey(weight.currency, weight.number > ZERO)
github jbms / beancount-import / beancount_import / source / amazon_invoice.py View on Github external
node = soup.find(is_order_placed_node)
    m = re.fullmatch(order_placed_pattern, node.text.strip())
    assert m is not None
    order_date = dateutil.parser.parse(m.group(1)).date()

    credit_card_transactions = parse_credit_card_transactions(soup)
    if not credit_card_transactions:
        credit_card_transactions = parse_credit_card_transactions_from_payments_table(
            payment_table, order_date)

    if credit_card_transactions:
        total_payments = reduce_amounts(
            x.amount for x in credit_card_transactions)
    else:
        total_payments = Amount(number=ZERO, currency=grand_total.currency)
    if total_payments != adjusted_grand_total:
        errors.append('total payment amount is %s, but grand total is %s' %
                      (total_payments, adjusted_grand_total))

    title = soup.find('title').text.strip()
    m = re.fullmatch(r'.*Order ([0-9\-]+)', title.strip())
    assert m is not None

    return Order(
        order_date=order_date,
        order_id=m.group(1),
        shipments=shipments,
        credit_card_transactions=credit_card_transactions,
        tax=tax,
        errors=sum((shipment.errors
                    for shipment in shipments), cast(Errors, [])) + errors,