Changeset - 0eb014aeeb2e
[Not reviewed]
0 4 1
Brett Smith - 6 years ago 2018-07-10 15:36:07
brettcsmith@brettcsmith.org
patreon: New importer for payouts.
5 files changed with 64 insertions and 1 deletions:
0 comments (0 inline, 0 general)
README.rst
Show inline comments
...
 
@@ -180,48 +180,63 @@ O'Reilly Media
 
                   the end of the month, while the actual transaction date
 
                   might be slightly off.
 
  ---------------- -----------------------------------------------------------
 

	
 
``oreilly royalties ledger entry``
 
  Imports one transaction per royalty period (usually a month, historically a quarter).  Generated from CSV export of O'Reilly's royalties statement.
 

	
 
  This template can use these variables:
 

	
 
  ================ ===========================================================
 
  Name             Contents
 
  ================ ===========================================================
 
  start_date       From the corresponding spreadsheet column
 
  ---------------- -----------------------------------------------------------
 
  paid_date        From the corresponding spreadsheet column.  This
 
                   corresponds to a row in the payment history as well.
 
  ---------------- -----------------------------------------------------------
 

	
 
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.
 

	
 
``patreon servicefees ledger entry``
 
  Imports one expense transaction per month for that month's Patreon service fees.  Generated from Patreon's earnings report CSV.
 

	
 
``patreon vat ledger entry``
 
  Imports one transaction per country per month each time Patreon withheld VAT.  Generated from Patreon's VAT report CSV.
 

	
 
  This template can use these variables:
 

	
 
  ============== ============================================================
 
  Name           Contents
 
  ============== ============================================================
 
  country_name   The full name of the country VAT was withheld for
 
  -------------- ------------------------------------------------------------
 
  country_code   The two-letter ISO country code of the country VAT was
 
                 withheld for
 
  ============== ============================================================
 

	
 
Stripe
 
^^^^^^
 

	
 
``stripe payment ledger entry``
import2ledger/importers/patreon.py
Show inline comments
...
 
@@ -13,48 +13,76 @@ class IncomeImporter(_csv.CSVImporterBase):
 
    ])
 
    COPIED_FIELDS = {
 
        'Pledge': 'amount',
 
    }
 
    ENTRY_SEED = {
 
        'currency': 'USD',
 
    }
 

	
 
    def __init__(self, input_file):
 
        super().__init__(input_file)
 
        match = re.search(r'(?:\b|_)(\d{4}-\d{2}-\d{2})(?:\b|_)',
 
                          pathlib.Path(input_file.name).name)
 
        if match:
 
            self.entry_seed['date'] = strparse.date(match.group(1), '%Y-%m-%d')
 

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

	
 

	
 
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',
 
        'payee': "Patreon",
 
    }
 

	
 
    def _read_row(self, row):
 
        return {
 
            'amount': row[self.AMOUNT_FIELD],
 
            'date': strparse.date(row['Month'], '%Y-%m'),
 
        }
 

	
 

	
 
class ServiceFeesImporter(FeeImporterBase):
 
    AMOUNT_FIELD = 'Patreon Fee'
 
    NEEDED_FIELDS = frozenset(['Month', AMOUNT_FIELD])
 

	
 

	
 
class CardFeesImporter(FeeImporterBase):
 
    AMOUNT_FIELD = 'Processing Fees'
 
    NEEDED_FIELDS = frozenset(['Month', AMOUNT_FIELD])
 

	
 

	
 
class VATImporter(FeeImporterBase):
setup.py
Show inline comments
...
 
@@ -9,36 +9,36 @@ REQUIREMENTS = {
 
        'babel',
 
        'enum34;python_version<"3.4"',
 
    ],
 
    'setup_requires': ['pytest-runner'],
 
    'extras_require': {
 
        'brightfunds': ['xlrd'],
 
        'nbpy2017': ['beautifulsoup4', 'html5lib'],
 
    },
 
}
 

	
 
all_extras_require = [
 
    req for reqlist in REQUIREMENTS['extras_require'].values() for req in reqlist
 
]
 

	
 
REQUIREMENTS['extras_require']['all_importers'] = all_extras_require
 
REQUIREMENTS['tests_require'] = [
 
    'pytest',
 
    'PyYAML',
 
    *all_extras_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+',
 

	
 
    packages=find_packages(include=['import2ledger', 'import2ledger.*']),
 
    entry_points={
 
        'console_scripts': ['import2ledger = import2ledger.__main__:main'],
 
    },
 

	
 
    **REQUIREMENTS,
 
)
tests/data/PatreonPayouts.csv
Show inline comments
 
new file 100644
 
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"
tests/data/imports.yml
Show inline comments
...
 
@@ -41,48 +41,64 @@
 
      date: !!python/object/apply:datetime.date [2017, 9, 1]
 
      amount: !!python/object/apply:decimal.Decimal ["2.00"]
 
      currency: USD
 
      country_code: AT
 
      country_name: Austria
 
    - payee: Patreon
 
      date: !!python/object/apply:datetime.date [2017, 9, 1]
 
      amount: !!python/object/apply:decimal.Decimal ["3.30"]
 
      currency: USD
 
      country_code: BE
 
      country_name: Belgium
 
    - payee: Patreon
 
      date: !!python/object/apply:datetime.date [2017, 10, 1]
 
      amount: !!python/object/apply:decimal.Decimal ["0.40"]
 
      currency: USD
 
      country_code: BG
 
      country_name: Bulgaria
 
    - payee: Patreon
 
      date: !!python/object/apply:datetime.date [2017, 10, 1]
 
      amount: !!python/object/apply:decimal.Decimal ["6.05"]
 
      currency: USD
 
      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:
 
    - payee: Dakota Smith
 
      date: !!python/object/apply:datetime.date [2017, 11, 8]
 
      amount: !!python/object/apply:decimal.Decimal ["100.00"]
 
      fee: !!python/object/apply:decimal.Decimal ["3"]
 
      tax: !!python/object/apply:decimal.Decimal ["0"]
 
      currency: USD
 
      payment_id: ch_oxuish6phae2Raighooghi3U
 
      customer_id: cus_DohSheeQu8eng3
 
      customer_email: one@example.org
 
      payout_id: po_aeYees2ahtier8ohju7Eeyie
 
      description: "Payment for invoice #102"
 
    - payee: Dakota Jones
 
      date: !!python/object/apply:datetime.date [2017, 10, 28]
 
      amount: !!python/object/apply:decimal.Decimal ["50.00"]
 
      fee: !!python/object/apply:decimal.Decimal ["1.4"]
 
      tax: !!python/object/apply:decimal.Decimal ["0"]
 
      currency: USD
 
      payment_id: ch_hHee9ef1aeyee1ruo7ochee9
 
      customer_id: cus_iepae2Iecae8Ei
 
      customer_email: two@example.org
 
      payout_id: po_aeYees2ahtier8ohju7Eeyie
0 comments (0 inline, 0 general)