Bug 37115: Delete linked serial when deleting a single item
Test plan:
- Add a new subscription to a serial notice (with the option 'create an item record' selected)
- Receive one issue and create the linked item
- Return to the bibliographic record
- Edit item - Action - Delete
- Tick the box 'delete serial issues linked to item' and confirm
- The item should still be deleted correctly
- Back to subscription : the issue linked to the item doesn't exist any more
Signed-off-by: Boubacar OUATTARA <boubacar.ouattara@biblibre.com>
Signed-off-by: Nathalie <nathalie.savarit@univ-amu.fr>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 4260c84cde)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
parent
b13602054f
commit
88304db54b
16
Koha/Item.pm
16
Koha/Item.pm
|
|
@ -264,14 +264,24 @@ sub delete {
|
|||
my $self = shift;
|
||||
my $params = @_ ? shift : {};
|
||||
|
||||
# FIXME check the item has no current issues
|
||||
# i.e. raise the appropriate exception
|
||||
|
||||
# Get the item group so we can delete it later if it has no items left
|
||||
my $item_group = C4::Context->preference('EnableItemGroups') ? $self->item_group : undef;
|
||||
|
||||
my $serial_item = $self->serial_item;
|
||||
|
||||
my $result = $self->SUPER::delete;
|
||||
|
||||
# Delete the serial linked to the item if required
|
||||
if ( $result && $params->{delete_serial_issues} ) {
|
||||
if ($serial_item) {
|
||||
my $serial = Koha::Serials->find( $serial_item->serialid );
|
||||
|
||||
# The serial_item is deleted by cascade when the item is deleted
|
||||
# so we don't need to delete it here
|
||||
$serial->delete;
|
||||
}
|
||||
}
|
||||
|
||||
# Delete the item group if it has no items left
|
||||
$item_group->delete if ( $item_group && $item_group->items->count == 0 );
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
package Koha::Template::Plugin::Item;
|
||||
|
||||
# Copyright Open Fifth 2025
|
||||
|
||||
# This file is part of Koha.
|
||||
#
|
||||
# Koha is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Koha is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
use Modern::Perl;
|
||||
|
||||
use Template::Plugin;
|
||||
use base qw( Template::Plugin );
|
||||
|
||||
use Koha::Items;
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 HasSerialItem
|
||||
|
||||
Checks whether a particular item has an associated serial item
|
||||
|
||||
=cut
|
||||
|
||||
sub HasSerialItem {
|
||||
my ( $self, $itemnumber ) = @_;
|
||||
|
||||
my $serial_item = Koha::Items->find($itemnumber)->serial_item;
|
||||
|
||||
return $serial_item ? 1 : 0;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -529,7 +529,8 @@ if ( $op eq "cud-additem" ) {
|
|||
my $item = Koha::Items->find($itemnumber);
|
||||
my $deleted;
|
||||
if ($item) {
|
||||
$deleted = $item->safe_delete;
|
||||
my $delete_serial_issues = $input->param('delete-serial-issues');
|
||||
$deleted = $item->safe_delete( { delete_serial_issues => $delete_serial_issues } );
|
||||
} else {
|
||||
$deleted = Koha::Result::Boolean->new(0)->add_message( { message => 'item_not_found' } );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
[% USE Item %]
|
||||
|
||||
<!-- delete_item_confirmation.inc -->
|
||||
<!-- Item deletion confirmation dialog -->
|
||||
<div class="modal fade" id="delete-item-modal" tabindex="-1" role="dialog" aria-labelledby="claims-returned-modal-label">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" id="delete-item-modal-label">Delete item</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<h5 style="margin-bottom: 15px;">Are you sure you want to delete this item?</h5>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="checkbox">
|
||||
<label for="delete_associated_serial_issues">
|
||||
<input id="delete_associated_serial_issues" type="checkbox" value="1" />
|
||||
Delete serial issues linked to item
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" id="delete-item-itemnumber" />
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="delete-item-modal-btn-submit" type="button" class="btn btn-primary"><i class="fa fa-exclamation-circle"></i> Delete item</button>
|
||||
<button class="btn btn-default deny cancel" href="#" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i> Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
[% USE Branches %]
|
||||
[% USE KohaDates %]
|
||||
[% USE Price %]
|
||||
[% USE Item %]
|
||||
[% USE TablesSettings %]
|
||||
[% PROCESS 'i18n.inc' %]
|
||||
[% INCLUDE 'doc-head-open.inc' %]
|
||||
|
|
@ -182,8 +183,9 @@
|
|||
<input type="hidden" name="biblionumber" value="[% item.biblionumber | html %]" />
|
||||
<input type="hidden" name="itemnumber" value="[% item.itemnumber | html %]" />
|
||||
<input type="hidden" name="searchid" value="[% searchid | html %]" />
|
||||
<input type="hidden" name="delete-serial-issues" id="[% item.itemnumber | html %]-delete-serial-issues" value="" />
|
||||
</form>
|
||||
<a class="dropdown-item delete" data-item="[% item.itemnumber | html %]" href="#">Delete</a>
|
||||
<a class="dropdown-item delete" data-itemnumber="[% item.itemnumber | html %]" data-has-serial-item="[% Item.HasSerialItem(item.itemnumber) | html %]" href="#">Delete</a>
|
||||
</li>
|
||||
[% END %]
|
||||
[% END %]
|
||||
|
|
@ -422,6 +424,7 @@
|
|||
</form>
|
||||
|
||||
[% INCLUDE 'modals/cataloguing_create_av.inc' %]
|
||||
[% INCLUDE 'modals/delete_item_confirmation.inc' %]
|
||||
</div>
|
||||
<!-- /#cataloguing_additem_newitem -->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -154,9 +154,32 @@ $(document).ready(function () {
|
|||
$(document).on("click", ".delete", function (e) {
|
||||
e.preventDefault();
|
||||
if (confirmDelete(MSG_CONFIRM_DELETE_ITEM)) {
|
||||
return $("#" + $(this).data("item") + "-delete-item-form").submit();
|
||||
var itemnumber = $(this).data("itemnumber");
|
||||
var hasSerialItem = $(this).data("has-serial-item");
|
||||
|
||||
$("#delete-item-itemnumber").val(itemnumber);
|
||||
$("#delete_associated_serial_issues").attr("checked", false);
|
||||
$("#delete-item-modal-btn-submit").data("item", itemnumber);
|
||||
if (!hasSerialItem) {
|
||||
$(".form-group").hide();
|
||||
}
|
||||
$("#delete-item-modal").modal("show");
|
||||
}
|
||||
});
|
||||
$(document).on("click", "#delete-item-modal-btn-submit", function (e) {
|
||||
e.preventDefault();
|
||||
var itemnumber = $("#delete-item-itemnumber").val();
|
||||
var deleteSerialIssues = $("#delete_associated_serial_issues").prop(
|
||||
"checked"
|
||||
)
|
||||
? true
|
||||
: false;
|
||||
$("#delete-item-modal").modal("hide");
|
||||
if (deleteSerialIssues) {
|
||||
$("#" + itemnumber + "-delete-serial-issues").val("1");
|
||||
}
|
||||
return $("#" + $(this).data("item") + "-delete-item-form").submit();
|
||||
});
|
||||
|
||||
/* On page load, check for location.hash in the page URL */
|
||||
/* If present the location hash will be used to scroll to the relevant anchor */
|
||||
|
|
|
|||
Loading…
Reference in New Issue