Changeset - 4796932cb7a4
[Not reviewed]
0 3 0
Brett Smith - 6 years ago 2017-12-18 19:09:54
brettcsmith@brettcsmith.org
importers.patreon: Handle commas in large amounts.
3 files changed with 6 insertions and 7 deletions:
0 comments (0 inline, 0 general)
import2ledger/importers/patreon.py
Show inline comments
...
 
@@ -5,17 +5,15 @@ from . import _csv
 
from .. import util
 

	
 
class IncomeImporter(_csv.CSVImporterBase):
 
    NEEDED_FIELDS = frozenset([
 
        'FirstName',
 
        'LastName',
 
        'Pledge',
 
        'Status',
 
    ])
 
    COPIED_FIELDS = {
 
        'Pledge': 'amount',
 
    }
 
    ENTRY_SEED = {
 
        'currency': 'USD',
 
    }
 
    TEMPLATE_KEY = 'template patreon income'
 

	
 
    def __init__(self, input_file):
...
 
@@ -27,12 +25,13 @@ class IncomeImporter(_csv.CSVImporterBase):
 

	
 
    def _read_row(self, row):
 
        if row['Status'] != 'Processed':
 
            return None
 
        else:
 
            return {
 
                'amount': row['Pledge'].replace(',', ''),
 
                'payee': '{0[FirstName]} {0[LastName]}'.format(row),
 
            }
 

	
 

	
 
class FeeImporterBase(_csv.CSVImporterBase):
 
    ENTRY_SEED = {
tests/data/PatreonPatronReport_2017-09-01.csv
Show inline comments
 
FirstName,LastName,Email,Pledge,Lifetime,Status,Twitter,Street,City,State,Zip,Country,Start,MaxAmount,Complete
 
100 + Reward,Description You donate a lot of money!,,,,,,,,,,,,,
 
Alex,Jones,alex@example.org,150,300,Processed,,,,,,,2017-08-11 11:28:06.166065,200,0
 
Alex,Jones,alex@example.org,"1,500.00","3,000.00",Processed,,,,,,,2017-08-11 11:28:06.166065,"2,000.00",0
 
5 + Reward,Description You’re nice!,,,,,,,,,,,,,
 
Brett,Smith,brett@example.org,10,30,Declined,Brett20XX,,,,,,2017-08-10 13:24:15.955782,10,0
 
Dakota,Doe,ddoe@example.org,12,48,Processed,,,,,,,2017-08-10 12:58:31.919341,12,0
 
Brett,Smith,brett@example.org,10.00,30.00,Declined,Brett20XX,,,,,,2017-08-10 13:24:15.955782,10.00,0
 
Dakota,Doe,ddoe@example.org,12.00,48.00,Processed,,,,,,,2017-08-10 12:58:31.919341,12.00,0
tests/data/imports.yml
Show inline comments
 
- source: PatreonPatronReport_2017-09-01.csv
 
  importer: patreon.IncomeImporter
 
  expect:
 
    - payee: Alex Jones
 
      date: !!python/object/apply:datetime.date [2017, 9, 1]
 
      amount: !!python/object/apply:decimal.Decimal ["150.00"]
 
      amount: !!python/object/apply:decimal.Decimal ["1500.00"]
 
      currency: USD
 
    - payee: Dakota Doe
 
      date: !!python/object/apply:datetime.date [2017, 9, 1]
 
      amount: !!python/object/apply:decimal.Decimal ["12.00"]
 
      currency: USD
 

	
0 comments (0 inline, 0 general)