Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc50f645

Browse files
authored
Merge pull request#4708 from unicef/fix_241723
Dashboard Hotfix
2 parentsfda48a2 +ac57423 commitc50f645

File tree

6 files changed

+100
-8
lines changed

6 files changed

+100
-8
lines changed

‎pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ distribution = true
132132

133133
[project]
134134
name ="hope"
135-
version ="3.1.5"
135+
version ="3.1.6"
136136
description ="HCT MIS is UNICEF's humanitarian cash transfer platform."
137137
authors = [
138138
{name ="Tivix" },

‎src/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name":"frontend",
3-
"version":"3.1.5",
3+
"version":"3.1.6",
44
"private":true,
55
"type":"module",
66
"scripts": {

‎src/hct_mis_api/apps/dashboard/services.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def refresh_data(cls, business_area_slug: str) -> ReturnDict:
9191
.filter(
9292
business_area=area,
9393
parent__status__in=["ACCEPTED","FINISHED"],
94+
program__is_visible=True,
95+
parent__is_removed=False,
9496
is_removed=False,
9597
conflicted=False,
9698
)# noqa
@@ -122,15 +124,23 @@ def refresh_data(cls, business_area_slug: str) -> ReturnDict:
122124
total_usd=Sum(
123125
Case(
124126
When(delivered_quantity_usd__isnull=False,then="delivered_quantity_usd"),
125-
When(entitlement_quantity_usd__isnull=False,then="entitlement_quantity_usd"),
127+
When(
128+
delivered_quantity_usd__isnull=True,
129+
entitlement_quantity_usd__isnull=False,
130+
then="entitlement_quantity_usd",
131+
),
126132
default=Value(0.0),
127133
output_field=DecimalField(),
128134
)
129135
),
130136
total_quantity=Sum(
131137
Case(
132138
When(delivered_quantity__isnull=False,then="delivered_quantity"),
133-
When(entitlement_quantity__isnull=False,then="entitlement_quantity"),
139+
When(
140+
delivered_quantity__isnull=True,
141+
entitlement_quantity__isnull=False,
142+
then="entitlement_quantity",
143+
),
134144
default=Value(0.0),
135145
output_field=DecimalField(),
136146
)
@@ -234,6 +244,8 @@ def refresh_data(cls, business_area_slug: str = "global") -> ReturnDict:
234244
)
235245
.filter(
236246
parent__status__in=["ACCEPTED","FINISHED"],
247+
program__is_visible=True,
248+
parent__is_removed=False,
237249
is_removed=False,
238250
conflicted=False,
239251
)# noqa
@@ -257,7 +269,11 @@ def refresh_data(cls, business_area_slug: str = "global") -> ReturnDict:
257269
total_usd=Sum(
258270
Case(
259271
When(delivered_quantity_usd__isnull=False,then="delivered_quantity_usd"),
260-
When(entitlement_quantity_usd__isnull=False,then="entitlement_quantity_usd"),
272+
When(
273+
delivered_quantity_usd__isnull=True,
274+
entitlement_quantity_usd__isnull=False,
275+
then="entitlement_quantity_usd",
276+
),
261277
default=Value(0.0),
262278
output_field=DecimalField(),
263279
)

‎tests/selenium/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ def login(browser: Chrome) -> Chrome:
313313
browser.find_element(By.ID,login).send_keys("superuser")
314314
browser.find_element(By.ID,password).send_keys("testtest2")
315315
browser.find_element(By.XPATH,loginButton).click()
316+
fromtimeimportsleep
317+
318+
sleep(0.2)
316319
browser.get(f"{browser.live_server.url}/")
317320
fromdjango.core.cacheimportcache
318321

‎tests/unit/apps/dashboard/test_services.py

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
importjson
2+
fromdecimalimportDecimal
23
fromtypingimportAny,Callable,Dict,Optional
34

45
fromdjango.core.cacheimportcache
@@ -11,6 +12,7 @@
1112
DashboardDataCache,
1213
DashboardGlobalDataCache,
1314
)
15+
fromhct_mis_api.apps.payment.modelsimportPayment
1416

1517
CACHE_CONFIG= [
1618
("DashboardDataCache",DashboardDataCache,"test-area"),
@@ -29,7 +31,11 @@ def test_get_cache_key(cache_name: str, cache_class: Any, slug: str) -> None:
2931
@pytest.mark.django_db(databases=["default","read_only"])
3032
deftest_get_data_cache_hit(cache_name:str,cache_class:Any,slug:str)->None:
3133
"""Test get_data when data is found in the cache."""
32-
cache.set(f"dashboard_data_{slug}",json.dumps({"test":f"{cache_name}_data"}),60*60*24)
34+
cache.set(
35+
f"dashboard_data_{slug}",
36+
json.dumps({"test":f"{cache_name}_data"}),
37+
60*60*24,
38+
)
3339
data:Optional[Dict[str,Any]]=cache_class.get_data(slug)
3440
assertdata== {"test":f"{cache_name}_data"}
3541

@@ -84,7 +90,8 @@ def test_refresh_data(
8490
cache_key=cache_class.get_cache_key(slug)
8591
cache.delete(cache_key)
8692

87-
_=populate_dashboard_cache(afghanistan)
93+
populate_dashboard_cache(afghanistan)
94+
8895
refreshed_data=cache_class.refresh_data()ifslug=="global"elsecache_class.refresh_data(afghanistan.slug)
8996
assertrefreshed_dataisnotNone,"Refresh data returned None"
9097
assertlen(refreshed_data)>0,"No data returned by refresh"
@@ -99,3 +106,65 @@ def test_refresh_data(
99106
),f"Expected optional fields{expected_optional_fields} are missing in{cache_name}:{item.keys()}"
100107
cached_data=cache.get(cache_key)
101108
assertcached_dataisnotNone,"Data not cached"
109+
110+
111+
TEST_CASES= [
112+
(
113+
"delivered_quantity_usd prioritized",
114+
{"delivered_quantity_usd":Decimal("100.0"),"entitlement_quantity_usd":Decimal("50.0")},
115+
Decimal("500.0"),
116+
DashboardDataCache,
117+
),
118+
(
119+
"entitlement_quantity_usd used when delivered_quantity_usd is null",
120+
{"delivered_quantity_usd":None,"entitlement_quantity_usd":Decimal("50.0")},
121+
Decimal("250.0"),
122+
DashboardDataCache,
123+
),
124+
(
125+
"both fields null",
126+
{"delivered_quantity_usd":None,"entitlement_quantity_usd":None},
127+
Decimal("0.0"),
128+
DashboardDataCache,
129+
),
130+
(
131+
"Pending status with null delivered_quantity_usd",
132+
{"status":"Pending","delivered_quantity_usd":None,"entitlement_quantity_usd":Decimal("50.0")},
133+
Decimal("250.0"),
134+
DashboardDataCache,
135+
),
136+
(
137+
"global cache prioritizes delivered_quantity_usd",
138+
{"delivered_quantity_usd":Decimal("100.0"),"entitlement_quantity_usd":Decimal("50.0")},
139+
Decimal("500.0"),
140+
DashboardGlobalDataCache,
141+
),
142+
]
143+
144+
145+
@pytest.mark.parametrize(
146+
"test_name, payment_updates, expected_total, cache_service",
147+
TEST_CASES,
148+
ids=[case[0]forcaseinTEST_CASES],
149+
)
150+
@pytest.mark.django_db(transaction=True,databases=["default","read_only"])
151+
deftest_dashboard_data_cache(
152+
test_name:str,
153+
payment_updates:Dict[str,Any],
154+
expected_total:Decimal,
155+
cache_service:Any,
156+
populate_dashboard_cache:Callable,
157+
)->None:
158+
"""Test DashboardDataCache and DashboardGlobalDataCache behavior."""
159+
business_area=BusinessAreaFactory(slug="test-area")
160+
household=populate_dashboard_cache(business_area)
161+
162+
Payment.objects.filter(household=household).update(**payment_updates)
163+
ifcache_service==DashboardDataCache:
164+
result=cache_service.refresh_data(business_area.slug)
165+
else:
166+
result=cache_service.refresh_data()
167+
168+
total_usd=sum(Decimal(item["total_delivered_quantity_usd"])foriteminresult)
169+
assertlen(result)>0
170+
asserttotal_usd==expected_total

‎tests/unit/fixtures/dashboard.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
fromhct_mis_api.apps.household.fixturesimportcreate_household
1111
fromhct_mis_api.apps.household.modelsimportHousehold
1212
fromhct_mis_api.apps.payment.fixturesimportPaymentFactory,PaymentPlanFactory
13+
fromhct_mis_api.apps.program.fixturesimportProgramFactory
1314

1415

1516
classModifiedPaymentFactory(PaymentFactory):
@@ -35,6 +36,8 @@ def _populate_dashboard_cache(afghanistan: BusinessAreaFactory) -> Household:
3536
Create household and related records
3637
"""
3738
withtransaction.atomic(using="default"):
39+
program=ProgramFactory(business_area=afghanistan)
40+
3841
household,_=create_household(
3942
household_args={
4043
"business_area":afghanistan,
@@ -50,9 +53,10 @@ def _populate_dashboard_cache(afghanistan: BusinessAreaFactory) -> Household:
5053
"male_age_group_18_59_disabled_count":0,
5154
"male_age_group_60_disabled_count":1,
5255
"admin1":AreaFactory(name="Kabul",area_type__name="Province",area_type__area_level=1),
56+
"program":program,
5357
}
5458
)
55-
ModifiedPaymentFactory.create_batch(5,household=household)
59+
ModifiedPaymentFactory.create_batch(5,household=household,program=program)
5660

5761
returnhousehold
5862

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp