fix: duplicate scorecard period when supplier is created on a month end

make_all_scorecards' dedup query used strict bounds, so a single-day
period (supplier created on a month's last day -> start == end under
"Per Month") never matched its own window and was re-created on every
call. The daily refresh_scorecards job would insert a duplicate
submitted period each day for such suppliers, and
test_make_all_scorecards_is_idempotent fails on any date where
nowdate() - 75 days lands on a month end — both nightly server suites
went red on 2026-07-14 (75 days after April 30).

Inclusive bounds cannot false-match adjacent periods: each next period
starts at end_date + 1, so closed intervals never touch.
This commit is contained in:
Mihir Kandoi
2026-07-14 10:20:41 +05:30
parent 39b5c6ba2a
commit 3aafda331b

View File

@@ -201,14 +201,16 @@ def make_all_scorecards(docname: str):
while (start_date < todays) and (end_date <= todays):
# check to make sure there is no scorecard period already created
# (inclusive bounds: a single-day period — supplier created on a month's
# last day — must match its own window, else it is re-created every run)
scorecards = frappe.get_all(
"Supplier Scorecard Period",
fields=["name"],
filters={
"scorecard": docname,
"docstatus": 1,
"start_date": ["<", end_date],
"end_date": [">", start_date],
"start_date": ["<=", end_date],
"end_date": [">=", start_date],
},
order_by="end_date desc",
)