From 7a0fa4fb57a4d50767019f89f137a82a678372a3 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Wed, 1 Jul 2020 13:43:58 -0400 Subject: [PATCH] accrual: Wire is a single payment method. --- conservancy_beancount/reports/accrual.py | 36 +++++++++++++----------- setup.py | 2 +- tests/test_reports_accrual.py | 2 +- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/conservancy_beancount/reports/accrual.py b/conservancy_beancount/reports/accrual.py index 1ad6fed..cd0ccbf 100644 --- a/conservancy_beancount/reports/accrual.py +++ b/conservancy_beancount/reports/accrual.py @@ -88,6 +88,7 @@ from typing import ( Iterator, List, Mapping, + Match, NamedTuple, Optional, Sequence, @@ -434,17 +435,17 @@ class BalanceReport(BaseReport): class OutgoingReport(BaseReport): - PAYMENT_METHODS = { - 'ach': 'ACH', - 'check': 'Check', - 'creditcard': 'Credit Card', - 'debitcard': 'Debit Card', - 'fxwire': 'International Wire', - 'paypal': 'PayPal', - 'uswire': 'Domestic Wire', - 'vendorportal': 'Vendor Portal', - } - PAYMENT_METHOD_RE = re.compile(rf'^([a-z]{{3}})\s+({"|".join(PAYMENT_METHODS)})$') + class PaymentMethods(enum.Enum): + ach = 'ACH' + check = 'Check' + creditcard = 'Credit Card' + debitcard = 'Debit Card' + paypal = 'PayPal' + vendorportal = 'Vendor Portal' + wire = 'Wire' + fxwire = wire + uswire = wire + def __init__(self, rt_wrapper: rtutil.RT, out_file: TextIO) -> None: super().__init__(out_file) @@ -563,17 +564,20 @@ class OutgoingReport(BaseReport): ticket_id, payment_method_count, ) else: - match = self.PAYMENT_METHOD_RE.fullmatch(payment_method) + currency, method_key = payment_method.lower().split(None, 1) + try: + method_enum = self.PaymentMethods[method_key] + except KeyError: + match: Optional[Match] = None + else: + match = re.fullmatch(r'[a-z]{3}', currency) if match is None: self.logger.warning( "cannot set payment-method for rt:%s: invalid value %r", ticket_id, payment_method, ) else: - cf_targets['payment-method'] = '{} {}'.format( - match.group(1).upper(), - self.PAYMENT_METHODS[match.group(2)], - ) + cf_targets['payment-method'] = f'{currency.upper()} {method_enum.value}' cf_updates = { f'CF_{key}': value diff --git a/setup.py b/setup.py index cc8ab3f..2712bc7 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup setup( name='conservancy_beancount', description="Plugin, library, and reports for reading Conservancy's books", - version='1.5.5', + version='1.5.6', author='Software Freedom Conservancy', author_email='info@sfconservancy.org', license='GNU AGPLv3+', diff --git a/tests/test_reports_accrual.py b/tests/test_reports_accrual.py index 56cfcae..deb3553 100644 --- a/tests/test_reports_accrual.py +++ b/tests/test_reports_accrual.py @@ -546,7 +546,7 @@ def test_outgoing_report_fx_amounts(accrual_postings, caplog): ]) assert rt_client.edits == {'520': { 'CF_payment-amount': 'EUR 1,000.00 ($1,100.00)', - 'CF_payment-method': 'EUR International Wire', + 'CF_payment-method': 'EUR Wire', }} assert 'payment-method:' not in output.getvalue()