From 7fb699f46d3dc07cb7958a2a18b2598f0902fb7a Mon Sep 17 00:00:00 2001
From: Pedro Amorim
Date: Fri, 13 Jan 2023 13:23:17 +0000
Subject: [PATCH] Bug 30869: Add the ability to delete stock rotation rotas
'At the moment, it isn't possible to delete any rotas that have 0 items linked to it. The only way to do it is in MySQL - it would be good if this was possible from the staff client.'
This patch implements this, and also implements the possibility of deleting a rota with items linked to it, providing a warning that the item(s) currently in rotation will remain at its/their current stage library.
Test plan:
1) Enable StockRotation system preference
2) Cataloging > Stock rotation > New rota
3) Enter Name, save
4) Verify 'Delete' button shows on the right
5) Click 'Delete' -> Confirm 'Yes'
6) Repeat steps 1-3 and click 'Manage'->'Stages'
7) Add a new stage, enter Library and Duration, click 'Save'
8) Return to rotas, click 'Manage'->'Items'
9) Add item, enter barcode, click 'Save' (optional: add more than 1 item)
10) Optional: Click 'Move to next stage' and verify that item is now in different branch
11) Click 'return to rotas' and press 'Delete'
12) Verify the warning now shows, because items are attached, with the attached items count
13) Click 'Delete' -> Deletion is successful
14) If you did step 10, verify the item is still in the branch that it was at the time the rota was deleted
Sponsored-by: PTFS-Europe
Signed-off-by: David Nind
JD Amended patch:
* Fix QA failures
FAIL forbidden patterns
forbidden pattern: tab char (line 150)
forbidden pattern: tab char (line 151)
* Adjust commit message to describe what the patch does
Signed-off-by: Jonathan Druart
Signed-off-by: Tomas Cohen Arazi
(cherry picked from commit cf06f05ec0a3bc5f965ba09168e3dc8c82e0dbb3)
Signed-off-by: Jacob O'Mara
---
.../prog/en/modules/tools/stockrotation.tt | 20 +++++++++++
tools/stockrotation.pl | 36 +++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stockrotation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stockrotation.tt
index 1db4229438..a7f58583ab 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stockrotation.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stockrotation.tt
@@ -146,6 +146,10 @@
Deactivate
[% END %]
+
+
+ Delete
+
[% END %]
@@ -368,6 +372,22 @@
No
+ [% ELSIF (op == 'confirm_delete_rota') %]
+
+
+
Are you sure you want to delete this rota?
+ [% IF sritemstotal > 0 %]
+ [% IF sritemstotal == 1 %]
+
[% sritemstotal | html %] item is still attached to this rota, that item will remain at its current stage libraries.
+ [% ELSE %]
+
[% sritemstotal | html %] items are still attached to this rota, those items will remain at their current stage libraries.
+ [% END %]
+ [% END %]
+
+ Yes
+ No
+
+
[% ELSIF (op == 'confirm_delete_stage') %]
diff --git a/tools/stockrotation.pl b/tools/stockrotation.pl
index deaad70dcd..ec60a17864 100755
--- a/tools/stockrotation.pl
+++ b/tools/stockrotation.pl
@@ -193,6 +193,42 @@ if (!defined $op) {
item_id => $params{item_id}
);
+} elsif ($op eq 'confirm_delete_rota') {
+
+ # Get the rota we're deleting
+ my $rota = Koha::StockRotationRotas->find($params{rota_id});
+
+ # Get all items on this rota, for each prefetch their
+ # stage and biblio objects
+ my $sritems = Koha::StockRotationItems->search(
+ { 'stage.rota_id' => $params{rota_id} },
+ {
+ prefetch => {
+ stage => {
+ 'stockrotationitems' => {
+ 'itemnumber' => 'biblionumber'
+ }
+ }
+ }
+ }
+ );
+
+ $template->param(
+ rota_id => $params{rota_id},
+ sritemstotal => $sritems->count,
+ op => $op
+ );
+
+} elsif ($op eq 'delete_rota') {
+
+ # Get the rota we're deleting
+ my $rota = Koha::StockRotationRotas->find($params{rota_id});
+
+ $rota->delete;
+
+ # Return to the rotas list
+ print $input->redirect("/cgi-bin/koha/tools/stockrotation.pl");
+
} elsif ($op eq 'confirm_delete_stage') {
# Get the stage we're deleting
--
2.39.5