patreon: New importer for payouts.
This commit is contained in:
		
							parent
							
								
									e22b2f7c17
								
							
						
					
					
						commit
						0eb014aeeb
					
				
					 5 changed files with 64 additions and 1 deletions
				
			
		
							
								
								
									
										15
									
								
								README.rst
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								README.rst
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -201,6 +201,21 @@ Patreon
 | 
			
		|||
``patreon income ledger entry``
 | 
			
		||||
  Imports one transaction per patron per month.  Generated from Patreon's monthly patron report CSVs.
 | 
			
		||||
 | 
			
		||||
``patreon payout ledger entry``
 | 
			
		||||
  Imports one transaction per month for that month's payout.  Generated from Patreon's payout report CSV.
 | 
			
		||||
 | 
			
		||||
  This template can use these variables:
 | 
			
		||||
 | 
			
		||||
  =============== ===========================================================
 | 
			
		||||
  Name            Contents
 | 
			
		||||
  =============== ===========================================================
 | 
			
		||||
  pledges_amount  A decimal with the amount paid out by Patreon to pledges
 | 
			
		||||
                  you've made
 | 
			
		||||
  --------------- -----------------------------------------------------------
 | 
			
		||||
  transfer_amount A decimal with the amount paid out by Patreon to your bank
 | 
			
		||||
                  account
 | 
			
		||||
  =============== ===========================================================
 | 
			
		||||
 | 
			
		||||
``patreon cardfees ledger entry``
 | 
			
		||||
  Imports one expense transaction per month for that month's credit card fees.  Generated from Patreon's earnings report CSV.
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -34,6 +34,34 @@ class IncomeImporter(_csv.CSVImporterBase):
 | 
			
		|||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PayoutImporter(_csv.CSVImporterBase):
 | 
			
		||||
    AMOUNT_KEY = 'Total funds deducted from creator balance'
 | 
			
		||||
    PLEDGE_KEY = 'Funds used for pledges to other creators'
 | 
			
		||||
    TRANSFER_KEY = 'Funds transferred to you'
 | 
			
		||||
    NEEDED_FIELDS = frozenset([
 | 
			
		||||
        'Month',
 | 
			
		||||
        TRANSFER_KEY,
 | 
			
		||||
        PLEDGE_KEY,
 | 
			
		||||
        AMOUNT_KEY,
 | 
			
		||||
    ])
 | 
			
		||||
    ENTRY_SEED = {
 | 
			
		||||
        'currency': 'USD',
 | 
			
		||||
        'payee': 'Patreon',
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    def _read_row(self, row):
 | 
			
		||||
        amount = strparse.currency_decimal(row[self.AMOUNT_KEY])
 | 
			
		||||
        if not amount:
 | 
			
		||||
            return None
 | 
			
		||||
        else:
 | 
			
		||||
            return {
 | 
			
		||||
                'amount': amount,
 | 
			
		||||
                'date': strparse.date(row['Month'], '%Y-%m'),
 | 
			
		||||
                'pledges_amount': strparse.currency_decimal(row[self.PLEDGE_KEY]),
 | 
			
		||||
                'transfer_amount': strparse.currency_decimal(row[self.TRANSFER_KEY]),
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class FeeImporterBase(_csv.CSVImporterBase):
 | 
			
		||||
    ENTRY_SEED = {
 | 
			
		||||
        'currency': 'USD',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										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='0.5',
 | 
			
		||||
    version='0.6',
 | 
			
		||||
    author='Brett Smith',
 | 
			
		||||
    author_email='brettcsmith@brettcsmith.org',
 | 
			
		||||
    license='GNU AGPLv3+',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										4
									
								
								tests/data/PatreonPayouts.csv
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								tests/data/PatreonPayouts.csv
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
Month,Funds transferred to you,Funds used for pledges to other creators,Total funds deducted from creator balance
 | 
			
		||||
2018-03,$0,$0,$0
 | 
			
		||||
2018-04,$123.45,$0,$123.45
 | 
			
		||||
2018-05,"$2,345.67",$0,"$2,345.67"
 | 
			
		||||
		
		
			
  | 
| 
						 | 
				
			
			@ -62,6 +62,22 @@
 | 
			
		|||
      country_code: CZ
 | 
			
		||||
      country_name: Czech Republic
 | 
			
		||||
 | 
			
		||||
- source: PatreonPayouts.csv
 | 
			
		||||
  importer: patreon.PayoutImporter
 | 
			
		||||
  expect:
 | 
			
		||||
    - payee: Patreon
 | 
			
		||||
      date: !!python/object/apply:datetime.date [2018, 4, 1]
 | 
			
		||||
      amount: !!python/object/apply:decimal.Decimal ["123.45"]
 | 
			
		||||
      pledges_amount: !!python/object/apply:decimal.Decimal ["0"]
 | 
			
		||||
      transfer_amount: !!python/object/apply:decimal.Decimal ["123.45"]
 | 
			
		||||
      currency: USD
 | 
			
		||||
    - payee: Patreon
 | 
			
		||||
      date: !!python/object/apply:datetime.date [2018, 5, 1]
 | 
			
		||||
      amount: !!python/object/apply:decimal.Decimal ["2345.67"]
 | 
			
		||||
      pledges_amount: !!python/object/apply:decimal.Decimal ["0"]
 | 
			
		||||
      transfer_amount: !!python/object/apply:decimal.Decimal ["2345.67"]
 | 
			
		||||
      currency: USD
 | 
			
		||||
 | 
			
		||||
- source: StripePayments.csv
 | 
			
		||||
  importer: stripe.PaymentImporter
 | 
			
		||||
  expect:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue