Changeset - cebd1481ecb8
[Not reviewed]
0 3 1
Brett Smith - 7 years ago 2017-10-26 16:56:29
brettcsmith@brettcsmith.org
patreon: Import VAT withholdings.
4 files changed with 57 insertions and 4 deletions:
0 comments (0 inline, 0 general)
README.rst
Show inline comments
...
 
@@ -65,6 +65,17 @@ Patreon
 
``template patreon svcfees``
 
  Imports one expense transaction per month for that month's Patreon service fees.  Generated from Patreon's earnings report CSV.
 

	
 
``template patreon vat``
 
  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:
 

	
 
  ``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
 

	
 
Template variables
 
~~~~~~~~~~~~~~~~~~
 

	
import2ledger/importers/patreon.py
Show inline comments
...
 
@@ -53,11 +53,14 @@ class IncomeImporter(ImporterBase):
 

	
 
class FeeImporterBase(ImporterBase):
 
    def _read_row(self, row):
 
        return {
 
            'amount': row[self.AMOUNT_FIELD].lstrip('$'),
 
            'date': util.strpdate(row['Month'], '%Y-%m'),
 
            'payee': "Patreon",
 
        retval = {
 
            key.lower().replace(' ', '_'): row[key]
 
            for key in self.NEEDED_FIELDS.difference([self.AMOUNT_FIELD, 'Month'])
 
        }
 
        retval['amount'] = row[self.AMOUNT_FIELD].lstrip('$')
 
        retval['date'] = util.strpdate(row['Month'], '%Y-%m')
 
        retval['payee'] = "Patreon"
 
        return retval
 

	
 

	
 
class PatreonFeeImporter(FeeImporterBase):
...
 
@@ -70,3 +73,9 @@ class CardFeeImporter(FeeImporterBase):
 
    AMOUNT_FIELD = 'Processing Fees'
 
    NEEDED_FIELDS = frozenset(['Month', AMOUNT_FIELD])
 
    TEMPLATE_KEY = 'template patreon cardfees'
 

	
 

	
 
class VATImporter(FeeImporterBase):
 
    AMOUNT_FIELD = 'Vat Charged'
 
    NEEDED_FIELDS = frozenset(['Country Code', 'Country Name', 'Month', AMOUNT_FIELD])
 
    TEMPLATE_KEY = 'template patreon vat'
tests/data/PatreonVat.csv
Show inline comments
 
new file 100644
 
Country Code,Country Name,Month,Vat Charged
 
AT,Austria,2017-09,$2
 
BE,Belgium,2017-09,$3.30
 
BG,Bulgaria,2017-10,$0.40
 
CZ,Czech Republic,2017-10,$6.05
tests/data/imports.yml
Show inline comments
...
 
@@ -33,3 +33,31 @@
 
      date: [2017, 10, 1]
 
      amount: "99.47"
 
      currency: USD
 

	
 
- source: PatreonVat.csv
 
  importer: patreon.VATImporter
 
  expect:
 
    - payee: Patreon
 
      date: [2017, 9, 1]
 
      amount: "2"
 
      currency: USD
 
      country_code: AT
 
      country_name: Austria
 
    - payee: Patreon
 
      date: [2017, 9, 1]
 
      amount: "3.30"
 
      currency: USD
 
      country_code: BE
 
      country_name: Belgium
 
    - payee: Patreon
 
      date: [2017, 10, 1]
 
      amount: "0.40"
 
      currency: USD
 
      country_code: BG
 
      country_name: Bulgaria
 
    - payee: Patreon
 
      date: [2017, 10, 1]
 
      amount: "6.05"
 
      currency: USD
 
      country_code: CZ
 
      country_name: Czech Republic
0 comments (0 inline, 0 general)