patreon: Exclude tax from full amount.

This makes the balancing logic in entry generation work the way we want.
This commit is contained in:
Brett Smith 2020-12-10 09:43:47 -05:00
parent c1d1e17afb
commit 742fccca0c
4 changed files with 17 additions and 6 deletions

View file

@ -5,6 +5,7 @@ import functools
import io import io
import logging import logging
import operator import operator
import pprint
import re import re
import tokenize import tokenize
@ -192,8 +193,18 @@ class AccountSplitter:
"template {!r}".format(self.template_name) "template {!r}".format(self.template_name)
) from error ) from error
if sum(amt for _, amt in amounts) != 0: if sum(amt for _, amt in amounts) != 0:
self._balance_amounts(amounts, template_vars['amount']) try:
self._balance_amounts(amounts, -template_vars['amount']) self._balance_amounts(amounts, template_vars['amount'])
self._balance_amounts(amounts, -template_vars['amount'])
except errors.UserInputConfigurationError as error:
printer = pprint.PrettyPrinter()
logger.debug(
"%s\n%s\n%s",
error.args[0],
printer.pformat(amounts),
printer.pformat(dict(template_vars)),
)
raise
return amounts return amounts
def _iter_splits(self, template_vars): def _iter_splits(self, template_vars):

View file

@ -31,7 +31,7 @@ class EarningsImporter(_csv.CSVImporterBase):
ret_key: strparse.currency_decimal(row[src_key] or 0) ret_key: strparse.currency_decimal(row[src_key] or 0)
for src_key, ret_key in self.AMOUNT_FIELDS.items() for src_key, ret_key in self.AMOUNT_FIELDS.items()
} }
retval['amount'] = sum(retval.values()) retval['amount'] = sum(retval.values()) - retval['tax_amount']
retval['date'] = strparse.date(row[self.DATE_KEY], self.DATE_FMT) retval['date'] = strparse.date(row[self.DATE_KEY], self.DATE_FMT)
return retval return retval

View file

@ -30,7 +30,7 @@ REQUIREMENTS['tests_require'] = [
setup( setup(
name='import2ledger', name='import2ledger',
description="Import different sources of financial data to Ledger", description="Import different sources of financial data to Ledger",
version='1.4.0', version='1.4.1',
author='Brett Smith', author='Brett Smith',
author_email='brettcsmith@brettcsmith.org', author_email='brettcsmith@brettcsmith.org',
license='GNU AGPLv3+', license='GNU AGPLv3+',

View file

@ -85,7 +85,7 @@
event_id: "30123456" event_id: "30123456"
date: !!python/object/apply:datetime.date [2020, 12, 3] date: !!python/object/apply:datetime.date [2020, 12, 3]
currency: USD currency: USD
amount: !!python/object/apply:decimal.Decimal ["6"] amount: !!python/object/apply:decimal.Decimal ["5"]
tax_amount: !!python/object/apply:decimal.Decimal ["1"] tax_amount: !!python/object/apply:decimal.Decimal ["1"]
net_amount: !!python/object/apply:decimal.Decimal ["4.31"] net_amount: !!python/object/apply:decimal.Decimal ["4.31"]
platform_fee: !!python/object/apply:decimal.Decimal ["0.25"] platform_fee: !!python/object/apply:decimal.Decimal ["0.25"]
@ -97,7 +97,7 @@
event_id: "34567890" event_id: "34567890"
date: !!python/object/apply:datetime.date [2020, 12, 2] date: !!python/object/apply:datetime.date [2020, 12, 2]
currency: USD currency: USD
amount: !!python/object/apply:decimal.Decimal ["7.33"] amount: !!python/object/apply:decimal.Decimal ["6.06"]
tax_amount: !!python/object/apply:decimal.Decimal ["1.27"] tax_amount: !!python/object/apply:decimal.Decimal ["1.27"]
net_amount: !!python/object/apply:decimal.Decimal ["5.14"] net_amount: !!python/object/apply:decimal.Decimal ["5.14"]
platform_fee: !!python/object/apply:decimal.Decimal ["0.31"] platform_fee: !!python/object/apply:decimal.Decimal ["0.31"]