accrual: Wire is a single payment method.

This commit is contained in:
Brett Smith 2020-07-01 13:43:58 -04:00
parent 42b3e6ca17
commit 7a0fa4fb57
3 changed files with 22 additions and 18 deletions

View file

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

View file

@ -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+',

View file

@ -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()