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 <david@davidnind.com>

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 <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit cf06f05ec0)
Signed-off-by: Jacob O'Mara <jacob.omara@ptfs-europe.com>
This commit is contained in:
Pedro Amorim 2023-01-13 13:23:17 +00:00 committed by Jacob O'Mara
parent dfc61d419b
commit 7fb699f46d
2 changed files with 56 additions and 0 deletions

View file

@ -146,6 +146,10 @@
Deactivate
[% END %]
</a>
<a class="btn btn-default btn-xs" href="?op=confirm_delete_rota&amp;rota_id=[% rota.rota_id | uri %]">
<i class="fa fa-trash"></i>
Delete
</a>
</td>
</tr>
[% END %]
@ -368,6 +372,22 @@
<a class="btn btn-default btn-xs deny" href="?op=manage_items&amp;rota_id=[% rota_id | uri %]"><i class="fa fa-fw fa-remove"></i>No</a>
</p>
</div>
[% ELSIF (op == 'confirm_delete_rota') %]
<div class="dialog alert">
<h1>Are you sure you want to delete this rota?</h1>
[% IF sritemstotal > 0 %]
[% IF sritemstotal == 1 %]
<p> [% sritemstotal | html %] item is still attached to this rota, that item will remain at its current stage libraries.</p>
[% ELSE %]
<p> [% sritemstotal | html %] items are still attached to this rota, those items will remain at their current stage libraries.</p>
[% END %]
[% END %]
<p>
<a class="btn btn-default btn-xs approve" href="?op=delete_rota&amp;rota_id=[% rota_id | uri %]"><i class="fa fa-fw fa-check"></i>Yes</a>
<a class="btn btn-default btn-xs deny" href="/cgi-bin/koha/tools/stockrotation.pl"><i class="fa fa-fw fa-remove"></i>No</a>
</p>
</div>
[% ELSIF (op == 'confirm_delete_stage') %]
<div class="dialog alert">

View file

@ -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