Skip to content
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

[Amazon] Amazon import source for amazon.de #144

Merged
merged 46 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
27f88c0
amazon source with locale specification for EN and DE
moritzj29 Dec 12, 2021
75097fd
update test reference output
moritzj29 Dec 12, 2021
7570a8b
addressed some PR comments, polishing
moritzj29 Dec 18, 2021
b3760b7
updated example docstring with new locale names
moritzj29 Dec 18, 2021
6501b5f
added some translations (de_DE)
moritzj29 Dec 18, 2021
c1c8af8
add ability to parse prepended 3 letter currency specification, e.g. …
moritzj29 Dec 18, 2021
93e6b11
Merge branch 'dev/amount_parse' into dev/amazonDE
moritzj29 Dec 18, 2021
e9a9c95
updated invoice sanitizer to not completely remove payment table for …
moritzj29 Dec 18, 2021
03b9a06
add some sanitized invoice tests for de_DE
moritzj29 Dec 18, 2021
02cb706
change invoice.tax from None to [] to match convention of other JSON …
moritzj29 Dec 19, 2021
1864838
de_DE correct adjustments: posttax instead of pretax
moritzj29 Dec 19, 2021
17661bf
add ability to parse gift card orders correctly
moritzj29 Dec 19, 2021
7afeaac
remove debugging logs
moritzj29 Dec 19, 2021
8c109ac
Merge branch 'dev/amazonDE' into dev/amazonDEgiftCard
moritzj29 Dec 19, 2021
0bbce16
add some test data
moritzj29 Dec 19, 2021
a562159
add test for direct debit
moritzj29 Dec 19, 2021
f4b676c
Merge branch 'dev/amazonDE' into dev/amazonDEgiftCard
moritzj29 Dec 19, 2021
3d4a077
add amazon account charge up including test case
moritzj29 Dec 19, 2021
d3e701b
remove debugging print statement
moritzj29 Dec 19, 2021
a641c94
make quantity parsing more consistent, add log message if parsing failed
moritzj29 Jan 13, 2022
a460017
fix DE shipment_quantity_pattern
moritzj29 Jan 13, 2022
d367cdb
fix shipment quantity algorithm
moritzj29 Jan 13, 2022
eda2adb
make payee match chosen locale
moritzj29 Feb 20, 2022
98f15f0
add nonshipped header translation
moritzj29 Feb 20, 2022
df350d2
add nonshipped header translation
moritzj29 Feb 21, 2022
c179a48
fix typing, remove debug print statements
moritzj29 Mar 24, 2022
1529e0b
add test cases for nonshipped headers
moritzj29 Mar 24, 2022
8b5a878
correct locale name en_EN to en_US
moritzj29 Mar 24, 2022
e8d1e83
add Locale base class
moritzj29 Mar 24, 2022
63c9a47
Merge branch 'dev/amazonDEgiftCard' into dev/amazonDE
moritzj29 Mar 24, 2022
d5263ea
clean up imports, do not create locale instance
moritzj29 Mar 24, 2022
ff21279
reduce excessive logging for amazon fresh invoices with irrelevant qu…
moritzj29 Mar 25, 2022
8715e51
correct test name
moritzj29 Mar 25, 2022
7aac6ad
add missing types
moritzj29 Mar 25, 2022
f042a9f
add docstring with hierarchy of functions
moritzj29 Mar 25, 2022
7338a7b
use static class instead of class instance as default arguments
moritzj29 Mar 26, 2022
a438613
factor out is_items_ordered_header
moritzj29 Mar 26, 2022
69d146e
clean up locales, add comments
moritzj29 Mar 27, 2022
577e196
add comments and docstrings
moritzj29 Mar 27, 2022
e4b1ee9
add logging and error messages
moritzj29 Mar 27, 2022
8b6de9c
reduce conditionals in parse_credit_card_transactions_from_payments_t…
moritzj29 Mar 27, 2022
38fe597
move order ID and date extraction to beginning of parsing method, mor…
moritzj29 Mar 27, 2022
2287972
add check and error message if no items were found for an order
moritzj29 Mar 27, 2022
4be65b3
fix handling of cases with no tax; tax on Order level is Amount (None…
moritzj29 Mar 27, 2022
41a14fa
update types, fix Shipment tax type
moritzj29 Mar 27, 2022
66298c1
make parse_gift_cards optional
moritzj29 Mar 27, 2022
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
10 changes: 8 additions & 2 deletions beancount_import/source/amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'Gift Card Amount': 'Assets:Gift-Cards:Amazon',
'Rewards Points': 'Income:Amazon:Cashback',
},
locale='EN' # optional, defaults to 'EN'
)

The `amazon_account` key must be specified, and should be set to the email
Expand All @@ -54,6 +55,9 @@
specify these keys in the configuration, the generic automatic account
prediction will likely handle them.

The `locale` sets country/language specific settings.
Currently, `EN` and `DE` are available.

Specifying credit cards
=======================

Expand Down Expand Up @@ -271,7 +275,7 @@
from beancount.core.number import ZERO, ONE
import beancount.core.amount

from .amazon_invoice import parse_invoice, DigitalItem, Order
from .amazon_invoice import AmazonInvoice, DigitalItem, Order

from ..matching import FIXME_ACCOUNT, SimpleInventory
from ..posting_date import POSTING_DATE_KEY, POSTING_TRANSACTION_DATE_KEY
Expand Down Expand Up @@ -539,6 +543,7 @@ def __init__(self,
posttax_adjustment_accounts: Dict[str, str] = {},
pickle_dir: str = None,
earliest_date: datetime.date = None,
locale='EN',
**kwargs) -> None:
super().__init__(**kwargs)
self.directory = directory
Expand All @@ -551,6 +556,7 @@ def __init__(self,
self.pickler = AmazonPickler(pickle_dir)

self.earliest_date = earliest_date
self.amz_inv = AmazonInvoice(locale=locale)

self.invoice_filenames = [] # type: List[Tuple[str, str]]
for filename in os.listdir(self.directory):
Expand All @@ -570,7 +576,7 @@ def _get_invoice(self, results: SourceResults, order_id: str, invoice_filename:
invoice = self.pickler.load(results, invoice_path) # type: Optional[Order]
if invoice is None:
self.log_status('amazon: processing %s: %s' % (order_id, invoice_path, ))
invoice = parse_invoice(invoice_path)
invoice = self.amz_inv.parse_invoice(invoice_path)
self.pickler.dump( results, invoice_path, invoice )

self._cached_invoices[invoice_filename] = invoice, invoice_path
Expand Down
Loading