Bug 37223 - Deleting the last item in a label batch needs to redirect to ?op=new
Summary: Deleting the last item in a label batch needs to redirect to ?op=new
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Label/patron card printing (show other bugs)
Version: Main
Hardware: All All
: P5 - low major
Assignee: Chris Nighswonger
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-28 18:27 UTC by Phil Ringnalda
Modified: 2024-07-02 18:53 UTC (History)
0 users

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Phil Ringnalda 2024-06-28 18:27:10 UTC
When you delete the last item in a label batch, it effectively deletes the batch, but leaves you with an add form which still retains the batch_id. That means that if someone else creates a new batch before you add another item to "your" empty list, their batch will take that same batch_id, and when you add your item you will add it to their list.

Steps to reproduce:
1. Cataloging - Label creator - New label batch
2. Add any item to the batch
3. In the list of items in the batch, click delete
4. Different browser, log in as a user at a different branch
5. Cataloging - Label creator - New label batch
6. Add any item to the batch
7. Back to the original browser, add any item to the "empty" batch
8. You now have a batch with two items in it when you only added one
9. Try to solve your confusion by going to Manage - label batches, maybe
   you added it to the wrong batch?

Wups, no, there are no batches to manage, because now that batch you added an item to is owned by a different branch and you can't manage it to remove your accidental add.
Comment 1 Phil Ringnalda 2024-07-02 18:53:50 UTC
The unobvious thing behind "effectively deletes the batch" is that batches only exist by one or more items having a batch_id in the creator_batches table, where the primary key is label_id.

C4::Labels::Batch->new sets batch_id to 0, and it stays that way until add_item is called, when batch_id is set to one more than SELECT MAX(batch_id) FROM creator_batches;. And deleting a batch consists of calling remove_item until they are all gone.