From 65e6c746d5a142d37a60364312c1c5cd574b03ae Mon Sep 17 00:00:00 2001
From: Pedro Amorim
Date: Thu, 3 Nov 2022 15:33:55 -0100
Subject: [PATCH] Bug 30869 - Stock rotation rotas cannot be deleted
"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.
To test:
1) Enable StockRotation system preference
2) Tools > 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) Click "return to rotas" and press "Delete"
11) Verify the warning now shows, because items are attached, with the attached items count
12) Click "Delete" -> Deletion is successful
Sponsored-by: PTFS-Europe
---
.../prog/en/modules/tools/stockrotation.tt | 19 ++++++++++
tools/stockrotation.pl | 36 +++++++++++++++++++
2 files changed, 55 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 695d9a8bed..965ac3bf21 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stockrotation.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stockrotation.tt
@@ -145,6 +145,10 @@
Deactivate
[% END %]
+
+
+ Delete
+
[% END %]
@@ -366,6 +370,21 @@
No
+ [% ELSIF (op == 'confirm_delete_rota') %]
+
+
Are you sure you want to delete this rota?
+ [% IF sritemstotal > 0 %]
+ [% IF sritemstotal == 1 %]
+
[% sritemstotal %] item is still attached to this rota, that item will remain at its current stage libraries.
+ [% ELSE %]
+
[% sritemstotal %] 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.25.1