-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add UNCONFIRMED to externally predicted postings of imported entries #82
base: master
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 222
💛 - Coveralls |
dc78237
to
a5e26d7
Compare
Please change variable name to UNCONFIRMED |
226742a
to
891d5c7
Compare
Edit:You may use the Original Comment (outdated):@Zburatorul use below code as You can also use the from decimal import Decimal
import os
import pytest
from .source_test import check_source_example
from beancount.ingest.importers.csv import Importer as CSVImporter, Col
from beancount.core.data import Transaction, Posting, Amount
testdata_dir = os.path.realpath(
os.path.join(
os.path.dirname(__file__), '..', '..', 'testdata', 'source', 'generic_importer'))
testdata_csv = os.path.join(testdata_dir, "csv")
examples = [
'test_basic',
'test_invalid',
'test_training_examples'
]
importer = CSVImporter({Col.DATE: 'Date',
Col.NARRATION1: 'Description',
Col.AMOUNT: 'Amount',
},
'Assets:Bank',
'USD',
'"Date","Description","Amount"',
)
class DummyPostingPredictor:
DUMMY_ACCOUNT = "Assets:Dummy"
def __init__(self, importer):
self.importer = importer
# move extract to _extract
self.importer._extract = self.importer.extract
self.importer.extract = self.extract_wrapper
def extract_wrapper(self, f, existing_entries):
entries = self.importer._extract(f, existing_entries)
for entry in entries:
if isinstance(entry, Transaction):
p = entry.postings[0]
entry.postings.append(
Posting(
account=self.DUMMY_ACCOUNT,
units=Amount(currency=p.units.currency, number=-1*p.units.number),
cost=None,
price=None,
flag=None,
meta={},
)
)
return entries
# wrap the importer with the dummy posting predictor.
# Will predict 2nd dummy postings for the importer entries
DummyPostingPredictor(importer)
@pytest.mark.parametrize('name', examples)
def test_source(name: str):
check_source_example(
example_dir=os.path.join(testdata_dir, name),
source_spec={
'module': 'beancount_import.source.generic_importer_source',
'directory': testdata_csv,
'account': 'Assets:Bank',
'importer': importer,
},
replacements=[(testdata_dir, '<testdata>')]) |
{"source_desc":entry.narration, "date": entry.date}) | ||
postings.insert(i, p) | ||
# add unconfirmed account key | ||
posting.meta[UNCONFIRMED] = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use True
rather than ""
since this seems to be a boolean field?
Can you please add a unit test? |
891d5c7
to
220ded3
Compare
testdata/source/generic_importer/test_dummy_predictor/import_results.beancount
Outdated
Show resolved
Hide resolved
623dc7e
to
50c6ba9
Compare
If a posting was predicted by smart_importer or was entered by hand, it should be editable. This was suggested and discussed in jbms#60
beancount-import will now look for new_account and unconfirmed_account meta fields in each posting, and understand their presence to mean that the account names of these postings are tentative, potentially new. Introduced two new methods similar to those present in training.py and new logic.
50c6ba9
to
278a7d0
Compare
278a7d0
to
b2df616
Compare
@jbms @Zburatorul Hey guys, this feels ready now.
|
@Zburatorul I have been using this too for a few months and works perfectly fine as expected. |
If a posting was predicted by smart_importer or was entered by hand, it won't be predicted again but should be editable like the FIXME or predicted entry by beancount-import.
This was suggested and discussed in #60 and will start working once #60 is completed and merged.