Bug 41229

Summary: Cash registers are not fully reset on library change
Product: Koha Reporter: Martin Renvoize (ashimema) <martin.renvoize>
Component: Staff interfaceAssignee: Martin Renvoize (ashimema) <martin.renvoize>
Status: Pushed to oldstable --- QA Contact: Marcel de Rooy <m.de.rooy>
Severity: major    
Priority: P5 - low CC: david, fridolin.somers, gmcharlt, jrobb, m.de.rooy, sally.healey
Version: Main   
Hardware: All   
OS: All   
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
25.11.00,25.05.06,24.11.11
Circulation function:
Bug Depends on:    
Bug Blocks: 40445    
Attachments: Bug 41229: Fix desk and register session persistence on library change
Bug 41229: Fix desk and register session persistence on library change
Bug 41229: Fix desk and register session persistence on library change

Description Martin Renvoize (ashimema) 2025-11-10 13:43:19 UTC
When changing library in circ/set-library.pl, desk and register values are not being properly cleared from the session. This caused stale desk/register data from the previous library to persist, resulting in:
    - Incorrect cashup displays showing wrong library's register
    - Point of Sale defaulting to registers from different libraries
    - Session state inconsistent with visual UI
Comment 1 Martin Renvoize (ashimema) 2025-11-10 13:44:42 UTC
Created attachment 189409 [details] [review]
Bug 41229: Fix desk and register session persistence on library change

When changing library in circ/set-library.pl, desk and register values
were not being properly cleared from the session. This caused stale
desk/register data from the previous library to persist, resulting in:
- Incorrect cashup displays showing wrong library's register
- POS defaulting to registers from different libraries
- Session state inconsistent with visual UI

Three issues fixed:
1. Template: Changed register "None" option ID from "set-library-noregister"
   to "noregister" to match JavaScript expectations (consistent with desk handling)
2. Desk logic: Changed condition to use defined() and explicitly clear session
   when "No desk" is selected
3. Register logic: Added session clearing when "No register" is selected and
   fixed condition to handle empty initial state

Test plan:
1. Select Library A with Register 5
2. Change to Library B without selecting a register
3. Verify register is cleared from session (check POS page)
4. Repeat for desk selection
5. Verify explicit "-- None --" selection clears session values
Comment 2 Jason Robb 2025-11-22 02:15:25 UTC
Created attachment 189890 [details] [review]
Bug 41229: Fix desk and register session persistence on library change

When changing library in circ/set-library.pl, desk and register values
were not being properly cleared from the session. This caused stale
desk/register data from the previous library to persist, resulting in:
- Incorrect cashup displays showing wrong library's register
- POS defaulting to registers from different libraries
- Session state inconsistent with visual UI

Three issues fixed:
1. Template: Changed register "None" option ID from "set-library-noregister"
   to "noregister" to match JavaScript expectations (consistent with desk handling)
2. Desk logic: Changed condition to use defined() and explicitly clear session
   when "No desk" is selected
3. Register logic: Added session clearing when "No register" is selected and
   fixed condition to handle empty initial state

Test plan:
1. Select Library A with Register 5
2. Change to Library B without selecting a register
3. Verify register is cleared from session (check POS page)
4. Repeat for desk selection
5. Verify explicit "-- None --" selection clears session values

Signed-off-by: Jason Robb <jrobb@sekls.org>
Comment 3 Jason Robb 2025-11-22 02:19:32 UTC
Worked great for me!

For testing, note that you need these sysprefs enabled:

-EnablePointOfSale 
-UseCashRegisters 
-UseCirculationDesks

Cash registers need set up under Administration > Accounting > Cash Registers and desks need set up under Administration > Patrons and circulation > Desks
Comment 4 Marcel de Rooy 2025-11-28 10:18:36 UTC
Created attachment 190016 [details] [review]
Bug 41229: Fix desk and register session persistence on library change

When changing library in circ/set-library.pl, desk and register values
were not being properly cleared from the session. This caused stale
desk/register data from the previous library to persist, resulting in:
- Incorrect cashup displays showing wrong library's register
- POS defaulting to registers from different libraries
- Session state inconsistent with visual UI

Three issues fixed:
1. Template: Changed register "None" option ID from "set-library-noregister"
   to "noregister" to match JavaScript expectations (consistent with desk handling)
2. Desk logic: Changed condition to use defined() and explicitly clear session
   when "No desk" is selected
3. Register logic: Added session clearing when "No register" is selected and
   fixed condition to handle empty initial state

Test plan:
1. Select Library A with Register 5
2. Change to Library B without selecting a register
3. Verify register is cleared from session (check POS page)
4. Repeat for desk selection
5. Verify explicit "-- None --" selection clears session values

Signed-off-by: Jason Robb <jrobb@sekls.org>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 5 Marcel de Rooy 2025-11-28 10:18:55 UTC
Just noting that this may fail easily since desk_id comes directly from CGI:
my $desk = Koha::Desks->find( { desk_id => $desk_id } );

my $register = Koha::Cash::Registers->find($register_id);
Note that we fill register_id no matter what but we test for the name:
$session->param( 'register_name', $register ? $register->name : '' );

No blocker for me.
Comment 6 Lucas Gass (lukeg) 2025-12-01 15:36:21 UTC
Nice work everyone!

Pushed to main for 25.11
Comment 7 Paul Derscheid 2025-12-03 16:03:17 UTC
Nice work everyone!

Pushed to 25.05.x
Comment 8 Fridolin Somers 2025-12-04 14:14:04 UTC
Pushed to 24.11.x for 24.11.11