Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve ultipro_google import: regression test, efficiency improvemen…
…t, and employer contribution matching (#133) * ultipro_google: Add regression test. The test does not pass on Windows due to how the parser handles newlines. Install poppler-utils during the Linux build workflow to make pdftotext available. * ultipro_google: Memoize row_name to account translation. This will be a bit faster for large imports than doing an O(n) lookup for every posting, where n is the number of potential accounts, because row_names are repeated often. * ultipro_google: Support employer matched deductions. This is done by creating a corresponding earnings posting.
- Loading branch information
Showing
10 changed files
with
305 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import os | ||
import shutil | ||
import sys | ||
|
||
import pytest | ||
|
||
from . import ultipro_google | ||
from .source_test import check_source_example | ||
|
||
testdata_dir = os.path.realpath( | ||
os.path.join( | ||
os.path.dirname(__file__), '..', '..', 'testdata', 'source', 'ultipro_google')) | ||
|
||
@pytest.mark.skipif( | ||
shutil.which('pdftotext') is None, | ||
reason='the pdftotext program must be available') | ||
@pytest.mark.skipif( | ||
sys.platform.startswith('win'), | ||
reason='parsing does not work with Windows newlines') | ||
@pytest.mark.parametrize('name', ['test_basic']) | ||
def test_source(name: str): | ||
example_dir = os.path.join(testdata_dir, name) | ||
check_source_example( | ||
example_dir=example_dir, | ||
# source_spec is the example in ultipro_google.py. | ||
source_spec=dict( | ||
module='beancount_import.source.ultipro_google', | ||
company_name='Google', | ||
key_prefix='google_payroll', | ||
currency='USD', | ||
directory=example_dir, | ||
rules={ | ||
'Earnings': [ | ||
('Regular Pay', 'Income:Google:Salary'), | ||
('Annual Bonus', 'Income:Google:Annual-Bonus'), | ||
('HSA ER Seed', 'Income:Google:HSA'), | ||
], | ||
'Deductions': [ | ||
('Dental', 'Expenses:Health:Dental:Insurance'), | ||
('Medical', 'Expenses:Health:Medical:Insurance'), | ||
], | ||
'Taxes': [ | ||
('Federal Income Tax', | ||
'Income:Expenses:Taxes:TY{year:04d}:Federal:Income'), | ||
('Employee Medicare', | ||
'Income:Expenses:Taxes:TY{year:04d}:Federal:Medicare'), | ||
('Social Security Employee Tax', | ||
'Income:Expenses:Taxes:TY{year:04d}:Federal:Social-Security'), | ||
('CA State Income Tax', | ||
'Income:Expenses:Taxes:TY{year:04d}:California:Income'), | ||
('CA Private Disability Employee', | ||
'Income:Expenses:Taxes:TY{year:04d}:California:Disability'), | ||
], | ||
'Net Pay Distribution': [ | ||
('x+1234', 'Assets:Checking:My-Bank'), | ||
], | ||
}), | ||
replacements=[(testdata_dir, '<testdata>')]) |
1 change: 1 addition & 0 deletions
1
testdata/source/ultipro_google/test_basic/2021-01-08.statement-98765432.pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20210108-1.pdf |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Google LLC | ||
1600 Amphitheatre Parkway | ||
Mountain View, CA 94043 | ||
650-253-0000 | ||
Pay Statement | ||
Period Start Date 12/21/2020 | ||
Period End Date 01/03/2021 | ||
Pay Date 01/08/2021 | ||
Document 98765432 | ||
Net Pay $600.00 | ||
Pay Details | ||
Bean Counter | ||
123 Import St | ||
New York, NY 10001 | ||
USA | ||
Employee Number 000123456 | ||
SSN XXX-XX-XXXX | ||
Job Accountant | ||
Pay Rate $100.0000 | ||
Pay Frequency Biweekly | ||
Pay Group Salaried Employees | ||
Location US-NYC-NYC | ||
Cost Center 111 - Finance - Accounting | ||
Earnings | ||
Pay Type Hours Pay Rate Current YTD | ||
Dom Part $50.00 $100.00 | ||
Regular Pay 8.0000 $100.0000 $800.00 | ||
Regular Pay 72.0000 $100.0000 $7,200.00 $16,000.00 | ||
Total Hours Worked 80.0000 Total Hours 80.0000 | ||
Deductions | ||
Employee Employer | ||
Deduction Based On Pre-Tax Current YTD Current YTD | ||
401K Pretax $8,000.00 Yes $6,000.00 $12,000.00 $3,000.00 $6,000.00 | ||
Dental $1.11 Yes $1.11 $2.22 $0.00 $0.00 | ||
Dmstc Part - NR $50.00 No $50.00 $100.00 $0.00 $0.00 | ||
Medical $2.22 Yes $2.22 $4.44 $0.00 $0.00 | ||
Vision $3.33 Yes $3.33 $6.66 $0.00 $0.00 | ||
Taxes | ||
Tax Based On Current YTD | ||
Federal Income Tax $2,000.00 $200.00 $400.00 | ||
Employee Medicare $8,000.00 $50.00 $100.00 | ||
Social Security Employee Tax $8,000.00 $50.00 $150.00 | ||
NY State Income Tax $3,000.00 $100.00 $100.00 | ||
Paid Time Off | ||
Plan Current Balance | ||
Vacation 0.0000 0.0000 | ||
Net Pay Distribution | ||
Account Number Account Type Amount | ||
xxxxxxxx1234 Checking $600.00 | ||
Total $600.00 | ||
Pay Summary | ||
Gross FIT Taxable Wages Taxes Deductions Net Pay | ||
Current $8,050.00 $2,000.00 $400.00 $6,056.66 $600.00 | ||
YTD $16,000 $4,000.00 $800.00 $9,000.00 $1200.00 | ||
|
Empty file.
111 changes: 111 additions & 0 deletions
111
testdata/source/ultipro_google/test_basic/import_results.beancount
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
;; date: 2021-01-08 | ||
;; info: {"filename": "<testdata>/test_basic/20210108-1.pdf", "type": "application/pdf"} | ||
|
||
; features: [ | ||
; { | ||
; "amount": "-50.00 USD", | ||
; "date": "2021-01-08", | ||
; "key_value_pairs": { | ||
; "google_payroll_desc": [ | ||
; "Earnings: Dom Part" | ||
; ] | ||
; }, | ||
; "source_account": "" | ||
; }, | ||
; { | ||
; "amount": "6000.00 USD", | ||
; "date": "2021-01-08", | ||
; "key_value_pairs": { | ||
; "google_payroll_desc": [ | ||
; "Deductions: 401K Pretax" | ||
; ] | ||
; }, | ||
; "source_account": "" | ||
; }, | ||
; { | ||
; "amount": "3000.00 USD", | ||
; "date": "2021-01-08", | ||
; "key_value_pairs": { | ||
; "google_payroll_desc": [ | ||
; "Deductions: 401K Pretax Employer Match" | ||
; ] | ||
; }, | ||
; "source_account": "" | ||
; }, | ||
; { | ||
; "amount": "-3000.00 USD", | ||
; "date": "2021-01-08", | ||
; "key_value_pairs": { | ||
; "google_payroll_desc": [ | ||
; "Earnings: 401K Pretax Employer Match" | ||
; ] | ||
; }, | ||
; "source_account": "" | ||
; }, | ||
; { | ||
; "amount": "50.00 USD", | ||
; "date": "2021-01-08", | ||
; "key_value_pairs": { | ||
; "google_payroll_desc": [ | ||
; "Deductions: Dmstc Part - NR" | ||
; ] | ||
; }, | ||
; "source_account": "" | ||
; }, | ||
; { | ||
; "amount": "3.33 USD", | ||
; "date": "2021-01-08", | ||
; "key_value_pairs": { | ||
; "google_payroll_desc": [ | ||
; "Deductions: Vision" | ||
; ] | ||
; }, | ||
; "source_account": "" | ||
; }, | ||
; { | ||
; "amount": "100.00 USD", | ||
; "date": "2021-01-08", | ||
; "key_value_pairs": { | ||
; "google_payroll_desc": [ | ||
; "Taxes: NY State Income Tax" | ||
; ] | ||
; }, | ||
; "source_account": "" | ||
; } | ||
; ] | ||
2021-01-08 * "Google" "Payroll" | ||
associated_data0: "{\"description\": \"Google payroll statement\", \"meta\": [\"google_payroll_document\", \"98765432\"], \"path\": \"<testdata>/test_basic/20210108-1.pdf\", \"type\": \"application/pdf\"}" | ||
google_payroll_document: "98765432" | ||
google_payroll_pay_date: 2021-01-08 | ||
google_payroll_period_end_date: 2021-01-03 | ||
google_payroll_period_start_date: 2020-12-21 | ||
Expenses:FIXME -50.00 USD | ||
google_payroll_desc: "Earnings: Dom Part" | ||
Income:Google:Salary -800.00 USD | ||
google_payroll_desc: "Earnings: Regular Pay" | ||
Income:Google:Salary -7200.00 USD | ||
google_payroll_desc: "Earnings: Regular Pay" | ||
Expenses:FIXME 6000.00 USD | ||
google_payroll_desc: "Deductions: 401K Pretax" | ||
Expenses:FIXME 3000.00 USD | ||
google_payroll_desc: "Deductions: 401K Pretax Employer Match" | ||
Expenses:FIXME -3000.00 USD | ||
google_payroll_desc: "Earnings: 401K Pretax Employer Match" | ||
Expenses:Health:Dental:Insurance 1.11 USD | ||
google_payroll_desc: "Deductions: Dental" | ||
Expenses:FIXME 50.00 USD | ||
google_payroll_desc: "Deductions: Dmstc Part - NR" | ||
Expenses:Health:Medical:Insurance 2.22 USD | ||
google_payroll_desc: "Deductions: Medical" | ||
Expenses:FIXME 3.33 USD | ||
google_payroll_desc: "Deductions: Vision" | ||
Income:Expenses:Taxes:TY2021:Federal:Income 200.00 USD | ||
google_payroll_desc: "Taxes: Federal Income Tax" | ||
Income:Expenses:Taxes:TY2021:Federal:Medicare 50.00 USD | ||
google_payroll_desc: "Taxes: Employee Medicare" | ||
Income:Expenses:Taxes:TY2021:Federal:Social-Security 50.00 USD | ||
google_payroll_desc: "Taxes: Social Security Employee Tax" | ||
Expenses:FIXME 100.00 USD | ||
google_payroll_desc: "Taxes: NY State Income Tax" | ||
Assets:Checking:My-Bank 600.00 USD | ||
google_payroll_desc: "Net Pay Distribution: xxxxxxxx1234" |
Empty file.
Oops, something went wrong.