-
Notifications
You must be signed in to change notification settings - Fork 107
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
Changes from 31 commits
27f88c0
75097fd
7570a8b
b3760b7
6501b5f
c1c8af8
93e6b11
e9a9c95
03b9a06
02cb706
1864838
17661bf
7afeaac
8c109ac
0bbce16
a562159
f4b676c
3d4a077
d3e701b
a641c94
a460017
d367cdb
eda2adb
98f15f0
df350d2
c179a48
1529e0b
8b5a878
e8d1e83
63c9a47
d5263ea
ff21279
8715e51
7aac6ad
f042a9f
7338a7b
a438613
69d146e
577e196
e4b1ee9
8b6de9c
38fe597
2287972
4be65b3
41a14fa
66298c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
'Gift Card Amount': 'Assets:Gift-Cards:Amazon', | ||
'Rewards Points': 'Income:Amazon:Cashback', | ||
}, | ||
locale='en_US' # optional, defaults to 'en_US' | ||
) | ||
|
||
The `amazon_account` key must be specified, and should be set to the email | ||
|
@@ -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_US` and `de_DE` are available. | ||
|
||
Specifying credit cards | ||
======================= | ||
|
||
|
@@ -264,14 +268,15 @@ | |
import os | ||
import sys | ||
import pickle | ||
import logging | ||
|
||
from beancount.core.data import Transaction, Posting, Balance, Commodity, Price, EMPTY_SET, Directive | ||
from beancount.core.amount import Amount | ||
from beancount.core.flags import FLAG_OKAY | ||
from beancount.core.number import ZERO, ONE | ||
import beancount.core.amount | ||
|
||
from .amazon_invoice import parse_invoice, DigitalItem, Order | ||
from .amazon_invoice import LOCALES, parse_invoice, DigitalItem, Order | ||
|
||
from ..matching import FIXME_ACCOUNT, SimpleInventory | ||
from ..posting_date import POSTING_DATE_KEY, POSTING_TRANSACTION_DATE_KEY | ||
|
@@ -280,6 +285,8 @@ | |
|
||
import datetime | ||
|
||
logger = logging.getLogger('amazon') | ||
|
||
ITEM_DESCRIPTION_KEY = 'amazon_item_description' | ||
ITEM_URL_KEY = 'amazon_item_url' | ||
ITEM_BY_KEY = 'amazon_item_by' | ||
|
@@ -300,14 +307,15 @@ def make_amazon_transaction( | |
posttax_adjustment_accounts, | ||
credit_card_accounts, | ||
amazon_account: str, | ||
payee='Amazon.com' | ||
): | ||
txn = Transaction( | ||
date=invoice.order_date, | ||
meta=collections.OrderedDict([ | ||
(ORDER_ID_KEY, invoice.order_id), | ||
(AMAZON_ACCOUNT_KEY, amazon_account), | ||
]), | ||
payee='Amazon.com', | ||
payee=payee, | ||
narration='Order', | ||
flag=FLAG_OKAY, | ||
tags=EMPTY_SET, | ||
|
@@ -387,7 +395,7 @@ def make_amazon_transaction( | |
(INVOICE_DESCRIPTION, adjustment.description), | ||
]), | ||
)) | ||
if invoice.tax is not None and invoice.tax.number != ZERO: | ||
if len(invoice.tax)>0 and invoice.tax.number != ZERO: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What guarantees invoice.tax is not None? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it relates to the above discussion: #144 (comment) But I cannot recall why I removed the check on For digital orders, For regular orders, tax is set via:
Which may return Following up on the discussion above, I would vote for checking on What are your thoughts on this? Did I miss something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I tried to tackle this and stumbled upon an inconsistency in the current codebase: According to the typedefs I don't know why the typedef check does not catch this... When it comes to digital orders, the current code sets From the code perspective, I would go with the above corrections. But my dilemma arises when it comes to the JSON output for the tests: Setting @Zburatorul are you fine with this? what are your thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a proposal in 4be65b3
|
||
txn.postings.append( | ||
Posting( | ||
account=unknown_account_name, | ||
|
@@ -539,6 +547,7 @@ def __init__(self, | |
posttax_adjustment_accounts: Dict[str, str] = {}, | ||
pickle_dir: str = None, | ||
earliest_date: datetime.date = None, | ||
locale='en_US', | ||
**kwargs) -> None: | ||
super().__init__(**kwargs) | ||
self.directory = directory | ||
|
@@ -551,6 +560,7 @@ def __init__(self, | |
self.pickler = AmazonPickler(pickle_dir) | ||
|
||
self.earliest_date = earliest_date | ||
self.locale = LOCALES[locale] | ||
|
||
self.invoice_filenames = [] # type: List[Tuple[str, str]] | ||
for filename in os.listdir(self.directory): | ||
|
@@ -570,7 +580,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 = parse_invoice(invoice_path, locale=self.locale) | ||
self.pickler.dump( results, invoice_path, invoice ) | ||
|
||
self._cached_invoices[invoice_filename] = invoice, invoice_path | ||
|
@@ -605,7 +615,8 @@ def prepare(self, journal: JournalEditor, results: SourceResults): | |
invoice=invoice, | ||
posttax_adjustment_accounts=self.posttax_adjustment_accounts, | ||
amazon_account=self.amazon_account, | ||
credit_card_accounts=credit_card_accounts) | ||
credit_card_accounts=credit_card_accounts, | ||
payee=self.locale.payee) | ||
results.add_pending_entry( | ||
ImportResult( | ||
date=transaction.date, | ||
|
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.
allow to specify currency with prepended three letters, e.g.
EUR 20.00