Bug 39888

Summary: Error on acquisitions home when no budgets are defined
Product: Koha Reporter: Martin Renvoize (ashimema) <martin.renvoize>
Component: AcquisitionsAssignee: Martin Renvoize (ashimema) <martin.renvoize>
Status: Pushed to main --- QA Contact: Jonathan Druart <jonathan.druart>
Severity: normal    
Priority: P5 - low    
Version: unspecified   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
25.05.00
Circulation function:
Attachments: Bug 39888: Prevent load of superflous JS when table is not present
Bug 39888: Prevent load of superflous JS when table is not present

Description Martin Renvoize (ashimema) 2025-05-13 10:39:32 UTC
We see the following error in the browser console when loading acqui-home.pl without any budgets defined:

Cannot read properties of undefined (reading 'DataTable')

This is due to loading a large chunk of javascript to deal with a table we opt not to load into the DOM at all when budgets are not found.

This causes cypress test failures as there appears to be a transaction that removes budgets somewhere in our test suite.

Either way, we shouldn't load the JS when there's no DOM to action upon.
Comment 1 Martin Renvoize (ashimema) 2025-05-13 10:41:38 UTC
Created attachment 182352 [details] [review]
Bug 39888: Prevent load of superflous JS when table is not present

We shouldn't attempt to load the JS block for dealing with the budgets
table if there is no budgets defined and thus no budgets table.

Test plan
1) Remove all budgets
2) Load acqui-home.pl and note an error in the browser console
3) Apply the patch
4) Reload acqui-home.pl and note the errors have gone

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Comment 2 Martin Renvoize (ashimema) 2025-05-13 10:42:36 UTC
Self QA to get Jenkins green again... Matt is trying to track down where in the test suite we're not rolling back a transaction that removes all budgets.
Comment 3 Jonathan Druart 2025-05-13 11:03:25 UTC
Created attachment 182353 [details] [review]
Bug 39888: Prevent load of superflous JS when table is not present

We shouldn't attempt to load the JS block for dealing with the budgets
table if there is no budgets defined and thus no budgets table.

Test plan
1) Remove all budgets
2) Load acqui-home.pl and note an error in the browser console
3) Apply the patch
4) Reload acqui-home.pl and note the errors have gone

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>

Amended-by: Jonathan Druart
Tidy

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 4 Jonathan Druart 2025-05-13 11:04:56 UTC
Pushed to main for 25.05