Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ultipro_google: support additional deduction section formats #7

Merged
merged 1 commit into from
Jan 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion beancount_import/source/ultipro_google_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def parse(text: str) -> ParseResult:
"""
date_re = r'[0-9]{2}/[0-9]{2}/[0-9]{4}'
decimal_re = r'[0-9]+(?:,[0-9]+)*\.[0-9]+'
yesno_re = r'(?:Yes|No)'
currency_amount_re = r'(?:\$' + decimal_re + r'|\(\$' + decimal_re + r'\))'
number_re = r'[0-9]+'
account_re = r'[0-9x]+'
Expand All @@ -49,6 +50,11 @@ def parse_currency(x: Optional[str]) -> Optional[Decimal]:
return -D(x[1:-1])
return D(x)

def parse_yesno(x: Optional[str]) -> Optional[bool]:
if x is None:
return None
return x == 'Yes'

def parse_hours(x: Optional[str]) -> Optional[Decimal]:
if x is None:
return None
Expand All @@ -70,7 +76,7 @@ def parse_hours(x: Optional[str]) -> Optional[Decimal]:
(r'^(Period Start Date|Period End Date|Pay Date) (' + date_re +
r')$',
('date', parse_date)),
(r'^(Document) ([0-9A-Z]+)$',
(r'^(Document) ?([0-9A-Z]*)$',
('number', str)),
(r'^(Net Pay) (' + currency_amount_re + r')$',
('Amount', parse_currency)),
Expand Down Expand Up @@ -136,6 +142,19 @@ def parse_hours(x: Optional[str]) -> Optional[Decimal]:
('Current:Employer', parse_currency),
('YTD:Employer', parse_currency)),
]),
(r'^(Deductions)\nEmployee Employer\nDeduction\sBased\sOn\sPre-\s?Tax Current YTD Current YTD$',
[
(r'^(' + field_name_re + r')' +
(r' (' + currency_amount_re + r')') +
(r' (' + yesno_re + r')') + 4 *
(r' (' + currency_amount_re + r')') + r'$',
('Based On', parse_currency),
('Pre-tax', parse_yesno),
('Current', parse_currency),
('YTD', parse_currency),
('Current:Employer', parse_currency),
('YTD:Employer', parse_currency)),
]),
],
(r'^(Taxes)\nTax(?:es)? Based On Current YTD$', [
(r'^(' + field_name_re + r')' + 3 *
Expand Down