patreon: New importer for revamped earnings report.
This commit is contained in:
		
							parent
							
								
									f0da9e5bbe
								
							
						
					
					
						commit
						15ef02c153
					
				
					 3 changed files with 73 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -4,6 +4,38 @@ import re
 | 
			
		|||
from . import _csv
 | 
			
		||||
from .. import strparse
 | 
			
		||||
 | 
			
		||||
class EarningsImporter(_csv.CSVImporterBase):
 | 
			
		||||
    AMOUNT_FIELDS = {
 | 
			
		||||
        'Creator Share': 'net_amount',
 | 
			
		||||
        'Creator Platform Fee': 'platform_fee',
 | 
			
		||||
        'Creator Payment Processing Fee': 'processing_fee',
 | 
			
		||||
        'Creator Currency Conversion Fee': 'currency_fee',
 | 
			
		||||
        'Creator Equivalent of Patron Tax': 'tax_amount',
 | 
			
		||||
    }
 | 
			
		||||
    DATE_KEY = 'Date'
 | 
			
		||||
    TYPE_KEY = 'Event Type'
 | 
			
		||||
    NEEDED_FIELDS = frozenset([*AMOUNT_FIELDS, DATE_KEY, TYPE_KEY])
 | 
			
		||||
    COPIED_FIELDS = {
 | 
			
		||||
        'Creator Currency': 'currency',
 | 
			
		||||
        'Event ID': 'event_id',
 | 
			
		||||
        'Patron Email': 'email',
 | 
			
		||||
        'Patron Name': 'payee',
 | 
			
		||||
        'Patron User ID': 'user_id',
 | 
			
		||||
    }
 | 
			
		||||
    DATE_FMT = '%Y-%m-%d %H:%M:%S'
 | 
			
		||||
 | 
			
		||||
    def _read_row(self, row):
 | 
			
		||||
        if row[self.TYPE_KEY] != 'Payment':
 | 
			
		||||
            return None
 | 
			
		||||
        retval = {
 | 
			
		||||
            ret_key: strparse.currency_decimal(row[src_key] or 0)
 | 
			
		||||
            for src_key, ret_key in self.AMOUNT_FIELDS.items()
 | 
			
		||||
        }
 | 
			
		||||
        retval['amount'] = sum(retval.values())
 | 
			
		||||
        retval['date'] = strparse.date(row[self.DATE_KEY], self.DATE_FMT)
 | 
			
		||||
        return retval
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class IncomeImporter(_csv.CSVImporterBase):
 | 
			
		||||
    AMOUNT_KEY = 'Pledge Amount'
 | 
			
		||||
    DATE_KEY = 'Last Charge Date'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								setup.py
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								setup.py
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -30,7 +30,7 @@ REQUIREMENTS['tests_require'] = [
 | 
			
		|||
setup(
 | 
			
		||||
    name='import2ledger',
 | 
			
		||||
    description="Import different sources of financial data to Ledger",
 | 
			
		||||
    version='1.3.1',
 | 
			
		||||
    version='1.4.0',
 | 
			
		||||
    author='Brett Smith',
 | 
			
		||||
    author_email='brettcsmith@brettcsmith.org',
 | 
			
		||||
    license='GNU AGPLv3+',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -76,6 +76,46 @@
 | 
			
		|||
      amount: !!python/object/apply:decimal.Decimal ["117.03"]
 | 
			
		||||
      currency: USD
 | 
			
		||||
 | 
			
		||||
- source: PatreonEarnings2020.csv
 | 
			
		||||
  importer: patreon.EarningsImporter
 | 
			
		||||
  expect:
 | 
			
		||||
    - payee: Frances Jones
 | 
			
		||||
      email: fjones@example.com
 | 
			
		||||
      user_id: "32101234"
 | 
			
		||||
      event_id: "30123456"
 | 
			
		||||
      date: !!python/object/apply:datetime.date [2020, 12, 3]
 | 
			
		||||
      currency: USD
 | 
			
		||||
      amount: !!python/object/apply:decimal.Decimal ["6"]
 | 
			
		||||
      tax_amount: !!python/object/apply:decimal.Decimal ["1"]
 | 
			
		||||
      net_amount: !!python/object/apply:decimal.Decimal ["4.31"]
 | 
			
		||||
      platform_fee: !!python/object/apply:decimal.Decimal ["0.25"]
 | 
			
		||||
      processing_fee: !!python/object/apply:decimal.Decimal ["0.44"]
 | 
			
		||||
      currency_fee: !!python/object/apply:decimal.Decimal ["0"]
 | 
			
		||||
    - payee: Barbara Johnson
 | 
			
		||||
      email: bjohnson@example.com
 | 
			
		||||
      user_id: "2345678"
 | 
			
		||||
      event_id: "34567890"
 | 
			
		||||
      date: !!python/object/apply:datetime.date [2020, 12, 2]
 | 
			
		||||
      currency: USD
 | 
			
		||||
      amount: !!python/object/apply:decimal.Decimal ["7.33"]
 | 
			
		||||
      tax_amount: !!python/object/apply:decimal.Decimal ["1.27"]
 | 
			
		||||
      net_amount: !!python/object/apply:decimal.Decimal ["5.14"]
 | 
			
		||||
      platform_fee: !!python/object/apply:decimal.Decimal ["0.31"]
 | 
			
		||||
      processing_fee: !!python/object/apply:decimal.Decimal ["0.42"]
 | 
			
		||||
      currency_fee: !!python/object/apply:decimal.Decimal ["0.19"]
 | 
			
		||||
    - payee: Alex Jones
 | 
			
		||||
      email: ajones@example.com
 | 
			
		||||
      user_id: "7654321"
 | 
			
		||||
      event_id: "456789090"
 | 
			
		||||
      date: !!python/object/apply:datetime.date [2020, 12, 1]
 | 
			
		||||
      currency: USD
 | 
			
		||||
      amount: !!python/object/apply:decimal.Decimal ["14"]
 | 
			
		||||
      tax_amount: !!python/object/apply:decimal.Decimal ["0"]
 | 
			
		||||
      net_amount: !!python/object/apply:decimal.Decimal ["12.64"]
 | 
			
		||||
      platform_fee: !!python/object/apply:decimal.Decimal [".7"]
 | 
			
		||||
      processing_fee: !!python/object/apply:decimal.Decimal [".66"]
 | 
			
		||||
      currency_fee: !!python/object/apply:decimal.Decimal ["0"]
 | 
			
		||||
 | 
			
		||||
- source: PatreonEarnings.csv
 | 
			
		||||
  importer: patreon.CardFeesImporter
 | 
			
		||||
  expect:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue