From 55de5627f274560f48328979d5a081c403fbfdd5 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Sat, 16 May 2020 11:31:00 -0400 Subject: [PATCH] reports.accrual: Outgoing report uses payment-to custom field. RT#10656. --- conservancy_beancount/reports/accrual.py | 9 ++++----- tests/test_reports_accrual.py | 25 +++++++++++++++++++++++- tests/testutil.py | 9 +++++++-- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/conservancy_beancount/reports/accrual.py b/conservancy_beancount/reports/accrual.py index 7d74bb4..a19826b 100644 --- a/conservancy_beancount/reports/accrual.py +++ b/conservancy_beancount/reports/accrual.py @@ -218,10 +218,10 @@ def outgoing_report(groups: PostGroups, rt_requestor = None if rt_requestor is None: requestor = '' - payee = '' + requestor_name = '' else: requestor = '{RealName} <{EmailAddress}>'.format_map(rt_requestor) - payee = rt_requestor['RealName'] + requestor_name = rt_requestor['RealName'] contract_links = related.all_meta_links('contract') if contract_links: @@ -232,15 +232,14 @@ def outgoing_report(groups: PostGroups, contract_s = "NO CONTRACT GOVERNS THIS TRANSACTION" projects = [v for v in related.meta_values('project') if isinstance(v, str)] - payment_method = ticket.get('CF.{payment-method}', '') print( "PAYMENT FOR APPROVAL:", f"REQUESTOR: {requestor}", f"TOTAL TO PAY: {-related.balance()}", f"AGREEMENT: {contract_s}", - f"PAYMENT TO: {payee}", - f"PAYMENT METHOD: {payment_method}", + f"PAYMENT TO: {ticket.get('CF.{payment-to}', requestor_name)}", + f"PAYMENT METHOD: {ticket.get('CF.{payment-method}', '')}", f"PROJECT: {', '.join(projects)}", "\nBEANCOUNT ENTRIES:", sep='\n', file=out_file, diff --git a/tests/test_reports_accrual.py b/tests/test_reports_accrual.py index d641a5b..f9c9275 100644 --- a/tests/test_reports_accrual.py +++ b/tests/test_reports_accrual.py @@ -312,7 +312,7 @@ def test_outgoing_report(accrual_postings): r'^REQUESTOR: Mx\. 510 $', r'^TOTAL TO PAY: 280\.00 USD$', fr'^AGREEMENT: {contract_url}', - r'^PAYMENT TO: Mx\. 510$', + r'^PAYMENT TO: Hon\. Mx\. 510$', r'^PAYMENT METHOD: payment method 510$', r'^BEANCOUNT ENTRIES:$', # For each transaction, check for the date line, a metadata, and the @@ -325,6 +325,29 @@ def test_outgoing_report(accrual_postings): r'^\s+Expenses:FilingFees\s+60\.00 USD$', ]) +def test_outgoing_report_custom_field_fallbacks(accrual_postings): + invoice = 'rt:510/6100' + related = core.RelatedPostings( + post for post in accrual_postings + if post.meta.get('invoice') == invoice + and post.account.is_under('Assets:Receivable', 'Liabilities:Payable') + ) + output = io.StringIO() + errors = io.StringIO() + rt_client = RTClient(want_cfs=False) + rt_cache = rtutil.RT(rt_client) + accrual.outgoing_report({invoice: related}, output, errors, rt_client, rt_cache) + assert not errors.getvalue() + rt_url = rt_client.DEFAULT_URL[:-9] + rt_id_url = re.escape(f'<{rt_url}Ticket/Display.html?id=510>') + contract_url = re.escape(f'<{rt_url}Ticket/Attachment/4000/4000/contract.pdf>') + check_output(output, [ + r'^PAYMENT FOR APPROVAL:$', + r'^REQUESTOR: Mx\. 510 $', + r'^PAYMENT TO: Mx\. 510$', + r'^PAYMENT METHOD:\s*$', + ]) + def run_main(arglist, config): output = io.StringIO() errors = io.StringIO() diff --git a/tests/testutil.py b/tests/testutil.py index ab72bee..6d671d8 100644 --- a/tests/testutil.py +++ b/tests/testutil.py @@ -281,6 +281,7 @@ class RTClient: skip_login=False, verify_cert=True, http_auth=None, + want_cfs=True, ): self.url = url if http_auth is None: @@ -294,6 +295,7 @@ class RTClient: self.auth_method = type(http_auth).__name__ self.login_result = True self.last_login = None + self.want_cfs = want_cfs def login(self, login=None, password=None): if login is None and password is None: @@ -339,15 +341,18 @@ class RTClient: ticket_id_s = str(ticket_id) if ticket_id_s not in self.TICKET_DATA: return None - return { + retval = { 'id': 'ticket/{}'.format(ticket_id_s), 'numerical_id': ticket_id_s, - 'CF.{payment-method}': f'payment method {ticket_id_s}', 'Requestors': [ f'mx{ticket_id_s}@example.org', 'requestor2@example.org', ], } + if self.want_cfs: + retval['CF.{payment-method}'] = f'payment method {ticket_id_s}' + retval['CF.{payment-to}'] = f'Hon. Mx. {ticket_id_s}' + return retval def get_user(self, user_id): user_id_s = str(user_id)