Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion beancount_reds_plugins/effective_date/effective_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import string
import sys
import time
from typing import NamedTuple
from beancount.core import data
from beancount_reds_plugins.common import common

Expand All @@ -18,6 +19,10 @@

LINK_FORMAT = 'edate-{date}-{random}'

class EffectiveDateError(NamedTuple):
source: data.Meta
message: str
entry: data.Directive

def has_valid_effective_date(posting):
return posting.meta is not None and \
Expand All @@ -31,6 +36,13 @@ def has_posting_with_valid_effective_date(entry):
return True
return False

def has_posting_with_meaningless_effective_date(entry):
for posting in entry.postings:
if has_valid_effective_date(posting) \
and posting.meta['effective_date'] == entry.date:
return True
return False


def create_new_effective_date_entry(entry, date, hold_posting, original_posting):
def cleaned(p):
Expand Down Expand Up @@ -80,7 +92,17 @@ def effective_date(entries, options_map, config):
new_accounts = set()
for entry in entries:
if isinstance(entry, data.Transaction) and has_posting_with_valid_effective_date(entry):
interesting_entries.append(entry)
if not has_posting_with_meaningless_effective_date(entry):
interesting_entries.append(entry)
else:
errors.append(
EffectiveDateError(
entry.meta,
"Effective and actual dates are identical",
entry
)
)
filtered_entries.append(entry)
else:
filtered_entries.append(entry)

Expand Down
15 changes: 15 additions & 0 deletions beancount_reds_plugins/effective_date/test_effective_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,18 @@ def test_expense_later_multiple(self, entries, _, options_map):

new_entries, _ = effective_date(entries, options_map, None)
self.assertEqual(7, len(new_entries))

@loader.load_doc()
def test_meaningless_effective_dates(self, entries, _, options_map):
"""
2014-01-01 open Liabilities:Mastercard
2014-01-01 open Expenses:Taxes:Federal

2014-02-01 * "Estimated taxes for 2013"
Liabilities:Mastercard -2000 USD
Expenses:Taxes:Federal 2000 USD
effective_date: 2014-02-01
"""
new_entries, errors = effective_date(entries, options_map, None)
self.assertEqual(1, len(errors))
self.assertEqual(new_entries, entries)
Loading