Skip to content

Commit b3bba10

Browse files
authored
Merge pull request #35 from cloudblue/LITE-30341-customer-list-report-is-broken
LITE-30341 Fix filtering customer list report by tier type
2 parents 6cb6376 + 2b92be1 commit b3bba10

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

reports/customers_list/entrypoint.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
'Extended Information',
1818
)
1919

20+
TIER_TYPE = {
21+
'customer': ['customer'],
22+
'reseller': ['tier1', 'tier2'],
23+
}
24+
ALL_TYPE = {*TIER_TYPE['customer'], *TIER_TYPE['reseller']}
25+
2026

2127
def generate(
2228
client=None,
@@ -50,13 +56,22 @@ def generate(
5056

5157
def _get_customers(client, parameters):
5258
query = R()
59+
parameter_choices = set((parameters.get('tier_type', {}) or {}).get('choices', []))
5360

5461
if parameters.get('date') and parameters['date'].get('after'):
5562
query &= R().events.created.at.ge(parameters['date']['after'])
5663
query &= R().events.created.at.le(parameters['date']['before'])
64+
if parameter_choices == ALL_TYPE:
65+
# In case all 3 scopes are present in parameter choices, is the same
66+
# as all=True
67+
parameters['tier_type']['all'] = True
5768
if parameters.get('tier_type') and parameters['tier_type']['all'] is False:
58-
query &= R().scopes.oneof(parameters['tier_type']['choices'])
59-
69+
# (tier1 or tier2) and customer in choices -> all (no RLQ filter for tier_type)
70+
# one or both of tier1/2 in choices -> R().type.eq('reseller')
71+
# only customer in choices -> R().type.eq('customer')
72+
for t_type, choices in TIER_TYPE.items():
73+
if not parameter_choices.difference(choices):
74+
query &= R().type.eq(t_type)
6075
return client.ns('tier').accounts.filter(query).order_by('-events.created.at').limit(1000)
6176

6277

tests/test_customer_list.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Copyright (c) 2023, CloudBlue
44
# All rights reserved.
55
#
6+
import copy
7+
8+
import pytest
69

710
from reports.customers_list.entrypoint import (
811
generate,
@@ -18,14 +21,31 @@
1821
}
1922

2023

24+
@pytest.mark.parametrize(
25+
'parameter_choices,expected_rql',
26+
(
27+
({'choices': ['customer']}, ',eq(type,customer)'),
28+
({'choices': ['tier1']}, ',eq(type,reseller)'),
29+
({'choices': ['tier2']}, ',eq(type,reseller)'),
30+
({'choices': ['tier2', 'tier1']}, ',eq(type,reseller)'),
31+
({'choices': ['customer', 'tier1']}, ''),
32+
({'choices': ['customer', 'tier2']}, ''),
33+
({'choices': ['customer', 'tier1', 'tier1', 'tier2']}, ''),
34+
35+
),
36+
)
2137
def test_generate(
2238
progress,
2339
client_factory,
2440
response_factory,
2541
mkp_list,
2642
ta_list,
2743
tier_account,
44+
parameter_choices,
45+
expected_rql,
2846
):
47+
parameters = copy.deepcopy(PARAMETERS)
48+
parameters['tier_type'] = {**parameter_choices, 'all': False}
2949
responses = []
3050
responses.append(
3151
response_factory(
@@ -37,10 +57,13 @@ def test_generate(
3757
count=1,
3858
),
3959
)
60+
ta_list_query = (
61+
'and(ge(events.created.at,2020-12-01T00:00:00),le(events.created.at,'
62+
'2021-01-01T00:00:00){0})'
63+
)
4064
responses.append(
4165
response_factory(
42-
query='and(ge(events.created.at,2020-12-01T00:00:00),le(events.created.at,'
43-
'2021-01-01T00:00:00))',
66+
query=ta_list_query.format(expected_rql),
4467
value=ta_list,
4568
),
4669
)
@@ -50,7 +73,7 @@ def test_generate(
5073
),
5174
)
5275
client = client_factory(responses)
53-
result = list(generate(client, PARAMETERS, progress))
76+
result = list(generate(client, parameters, progress))
5477

5578
assert len(result) == 1
5679
i = 0

0 commit comments

Comments
 (0)