Skip to content

Commit

Permalink
Amazon: confguration to skip older invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
mbafford committed Oct 18, 2020
1 parent a80a77b commit 82a8654
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions beancount_import/source/amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@
These cached results are loaded as long as their mtime is more recent than
the HTML file to load. If you want to enable this funcionality, pass a path
to the `pickle_dir` parameter when initializing this class.
Skipping Older Invoices
=======================
In the event you want to only process invoices that happened after a certain
date you can pass the earliest date you want to process as a configuration
parameter `earliest_date` when initializing the this class.
This requires parsing the HTML file in order to determine the date of the
invoice, so it is recommended to use the caching/pickling mechanism described
above if you choose to have a large number of invoices in your data folder that
are not accounted for in your journal.
"""

import collections
Expand All @@ -266,6 +278,8 @@
from . import ImportResult, Source, SourceResults, InvalidSourceReference, AssociatedData
from ..journal_editor import JournalEditor

import datetime

ITEM_DESCRIPTION_KEY = 'amazon_item_description'
ITEM_URL_KEY = 'amazon_item_url'
ITEM_BY_KEY = 'amazon_item_by'
Expand Down Expand Up @@ -522,6 +536,7 @@ def __init__(self,
amazon_account: str,
posttax_adjustment_accounts: Dict[str, str] = {},
pickle_dir: str = None,
earliest_date: datetime.date = None,
**kwargs) -> None:
super().__init__(**kwargs)
self.directory = directory
Expand All @@ -533,6 +548,8 @@ def __init__(self,
self.example_transaction_key_extractors[AMAZON_ACCOUNT_KEY] = None
self.pickler = AmazonPickler(pickle_dir)

self.earliest_date = earliest_date

self.invoice_filenames = [] # type: List[Tuple[str, str]]
for filename in os.listdir(self.directory):
suffix = '.html'
Expand Down Expand Up @@ -577,6 +594,11 @@ def prepare(self, journal: JournalEditor, results: SourceResults):
continue
if invoice is None:
continue

if self.earliest_date is not None and invoice.order_date < self.earliest_date:
self.log_status("Skipping order with date [%s] before [%s]" % ( str(invoice.order_date), self.earliest_date ) )
continue

transaction = make_amazon_transaction(
invoice=invoice,
posttax_adjustment_accounts=self.posttax_adjustment_accounts,
Expand Down

0 comments on commit 82a8654

Please sign in to comment.