diff --git a/import2ledger/importers/patreon.py b/import2ledger/importers/patreon.py index 85f6a5a..7a64996 100644 --- a/import2ledger/importers/patreon.py +++ b/import2ledger/importers/patreon.py @@ -5,7 +5,7 @@ from . import _csv from .. import strparse class IncomeImporter(_csv.CSVImporterBase): - AMOUNT_KEY = 'Pledge $' + AMOUNT_KEY = 'Pledge Amount' DATE_KEY = 'Last Charge Date' STATUS_KEY = 'Last Charge Status' NEEDED_FIELDS = frozenset([ @@ -23,6 +23,13 @@ class IncomeImporter(_csv.CSVImporterBase): 'currency': 'USD', } + def __init_subclass__(cls): + cls.NEEDED_FIELDS = frozenset([ + cls.AMOUNT_KEY, + cls.DATE_KEY, + cls.STATUS_KEY, + ]) + def _read_row(self, row): if row[self.STATUS_KEY] != 'Paid': return None @@ -93,14 +100,14 @@ class VATImporter(FeeImporterBase): } -class Income2020AugustImporter(IncomeImporter): + +class Income2020OctoberImporter(IncomeImporter): + AMOUNT_KEY = 'Pledge $' + + +class Income2020AugustImporter(Income2020OctoberImporter): DATE_KEY = 'Charged On Date' STATUS_KEY = 'Charge Status' - NEEDED_FIELDS = frozenset([ - IncomeImporter.AMOUNT_KEY, - DATE_KEY, - STATUS_KEY, - ]) class Income2017Importer(_csv.CSVImporterBase): diff --git a/setup.py b/setup.py index be18bfe..9cd03fa 100755 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ REQUIREMENTS['tests_require'] = [ setup( name='import2ledger', description="Import different sources of financial data to Ledger", - version='1.2.0', + version='1.3.0', author='Brett Smith', author_email='brettcsmith@brettcsmith.org', license='GNU AGPLv3+', diff --git a/tests/data/PatreonPatronReport_2020-11-01.csv b/tests/data/PatreonPatronReport_2020-11-01.csv new file mode 100644 index 0000000..a34426e --- /dev/null +++ b/tests/data/PatreonPatronReport_2020-11-01.csv @@ -0,0 +1,3 @@ +Name,Email,Twitter,Discord,Patron Status,Follows You,Lifetime Amount,Pledge Amount,Charge Frequency,Tier,Addressee,Street,City,State,Zip,Country,Phone,Patronage Since Date,Max Amount,Last Charge Date,Last Charge Status,Additional Details,User ID,Last Updated +Alex Jones,ajones@example.com,,,Active patron,No,$28,$2,monthly,Even tier,,,,,,,,2019-10-30 18:25:15.457830,$2,2020-08-01 18:21:04,Paid,,1234567,2020-08-12 12:34:31.348413 +Breonna,breonna@example.org,patreonb,patreond#0123,Active patron,No,$5,$5,monthly,Odd tier,,,,,,,,2020-08-02 11:59:15.365305,$5,2020-08-02 12:00:02,Paid,,234567,2020-08-12 12:43:08.745681 diff --git a/tests/data/imports.yml b/tests/data/imports.yml index 28213b2..3000d33 100644 --- a/tests/data/imports.yml +++ b/tests/data/imports.yml @@ -29,6 +29,24 @@ currency: USD - source: PatreonPatronReport_2020-10-01.csv + importer: patreon.Income2020OctoberImporter + expect: + - payee: Alex Jones + email: ajones@example.com + tier: Even tier + patreon_id: "1234567" + date: !!python/object/apply:datetime.date [2020, 8, 1] + amount: !!python/object/apply:decimal.Decimal ["2"] + currency: USD + - payee: Breonna + email: breonna@example.org + tier: Odd tier + patreon_id: "234567" + date: !!python/object/apply:datetime.date [2020, 8, 2] + amount: !!python/object/apply:decimal.Decimal ["5.00"] + currency: USD + +- source: PatreonPatronReport_2020-11-01.csv importer: patreon.IncomeImporter expect: - payee: Alex Jones