Skip to content

Commit

Permalink
Fix invoice count (#1099)
Browse files Browse the repository at this point in the history
* Up the number of invoices from 10k to 60k.

* Fix count.

* Include csv export unit test.

* consistency
  • Loading branch information
seeker25 authored Feb 9, 2023
1 parent 94c7ed0 commit 16366d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pay-api/src/pay_api/models/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def search_purchase_history(cls, # noqa:E501; pylint:disable=too-many-arguments
result, count = query.filter(Invoice.id.in_(sub_query.subquery())).all(), sub_query.count()
else:
count = cls.get_count(auth_account_id, search_filter)
if len(count) > 10000:
if count > 60000:
raise BusinessException(Error.PAYMENT_SEARCH_TOO_MANY_RECORDS)
result = query.all()
return result, count
Expand Down Expand Up @@ -273,7 +273,7 @@ def filter(cls, query, auth_account_id: str, search_filter: Dict, is_count=False
query = query.filter(InvoiceReference.invoice_number.ilike(f'%{invoice_number}%'))

query = cls.filter_corp_type(query, search_filter)
query = cls.filter_no_fee(query, search_filter)
query = cls.filter_payment(query, search_filter)
query = cls.filter_details(query, search_filter, is_count)
query = cls.filter_date(query, search_filter)
return query
Expand All @@ -290,8 +290,8 @@ def filter_corp_type(cls, query, search_filter: dict):
return query

@classmethod
def filter_no_fee(cls, query, search_filter: dict):
"""Filter for no fee."""
def filter_payment(cls, query, search_filter: dict):
"""Filter for payment."""
if payment_type := search_filter.get('paymentMethod', None):
if payment_type == 'NO_FEE':
# only include no fee transactions
Expand Down
8 changes: 7 additions & 1 deletion pay-api/tests/unit/services/test_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def test_payment_with_no_active_invoice(session):
('account_name_view_all_2', {'accountName': 'account'}, True, 4, None, None),
('product', {'product': 'BUSINESS'}, False, 3, 'product', 'BUSINESS'),
('product_view_all', {'product': 'BUSINESS'}, True, 4, 'product', 'BUSINESS'),
('csv_export', {'product': 'BUSINESS'}, True, 4, None, None),
])
def test_search_payment_history(session, test_name, search_filter, view_all,
expected_total, expected_key, expected_value):
Expand Down Expand Up @@ -150,11 +151,16 @@ def test_search_payment_history(session, test_name, search_filter, view_all,

auth_account_id = payment_account.auth_account_id if not view_all else None

if test_name == 'csv_export':
return_all = True
else:
return_all = False
limit = 2
results = Payment_service.search_purchase_history(auth_account_id=auth_account_id,
search_filter=search_filter,
limit=limit,
page=1)
page=1,
return_all=return_all)
assert results is not None
assert results.get('items') is not None
assert results.get('total') == expected_total
Expand Down

0 comments on commit 16366d0

Please sign in to comment.