Bugzilla – Attachment 190553 Details for
Bug 41456
Item type filter on the hold history view does not work correctly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 41456: Fix item type searching and filtering on the holds history table
Bug-41456-Fix-item-type-searching-and-filtering-on.patch (text/plain), 10.50 KB, created by
David Nind
on 2025-12-16 16:27:54 UTC
(
hide
)
Description:
Bug 41456: Fix item type searching and filtering on the holds history table
Filename:
MIME Type:
Creator:
David Nind
Created:
2025-12-16 16:27:54 UTC
Size:
10.50 KB
patch
obsolete
>From 0f4ca331ed83c87e71839716fd2dd49340c70469 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 16 Dec 2025 12:02:23 +0100 >Subject: [PATCH] Bug 41456: Fix item type searching and filtering on the holds > history table > >Use should use coded_values for the library and item type column so that >we can search using the code and the description. > >With this patch we now have a dropdown list with the libraries and item >types in the table's headers. > >Test plan: >0. Turn on AllowHoldItemTypeSelection >1. Create a hold and select an item type >Note: I think there is a bug if you select it from "Hold next available >item", use "Hold details". Please confirm? >2. Go to the holds history view >3. Filter and search by item type description and code. Same for > library. > Use the dropdown list in the headers. > >Signed-off-by: David Nind <david@davidnind.com> >--- > Koha/Hold.pm | 19 +++++++- > api/v1/swagger/definitions/hold.yaml | 2 +- > .../prog/en/modules/members/holdshistory.tt | 46 ++++++++++++++++--- > t/db_dependent/Koha/Hold.t | 45 ++++++++++++++++-- > 4 files changed, 99 insertions(+), 13 deletions(-) > >diff --git a/Koha/Hold.pm b/Koha/Hold.pm >index 66a236a853..78eb4a5d38 100644 >--- a/Koha/Hold.pm >+++ b/Koha/Hold.pm >@@ -695,6 +695,19 @@ sub item { > return Koha::Item->_new_from_dbic($rs); > } > >+=head3 item_type >+ >+Returns the related Koha::ItemType object for this hold >+ >+=cut >+ >+sub item_type { >+ my ($self) = @_; >+ my $rs = $self->_result->itemtype; >+ return unless $rs; >+ return Koha::ItemType->_new_from_dbic($rs); >+} >+ > =head3 item_group > > Returns the related Koha::Biblio::ItemGroup object for this Hold >@@ -1281,7 +1294,7 @@ sub to_api_mapping { > lowestPriority => 'lowest_priority', > suspend => 'suspended', > suspend_until => 'suspended_until', >- itemtype => 'item_type', >+ itemtype => 'item_type_id', > item_level_hold => 'item_level', > }; > } >@@ -1319,6 +1332,10 @@ sub strings_map { > pickup_library_id => { str => $self->pickup_library->branchname, type => 'library' }, > }; > >+ if ( defined $self->itemtype ) { >+ $strings->{item_type_id} = { str => $self->item_type->description, type => 'item_type' }; >+ } >+ > if ( defined $self->cancellation_reason ) { > my $av = Koha::AuthorisedValues->search( > { >diff --git a/api/v1/swagger/definitions/hold.yaml b/api/v1/swagger/definitions/hold.yaml >index f09580f874..9a62c768c4 100644 >--- a/api/v1/swagger/definitions/hold.yaml >+++ b/api/v1/swagger/definitions/hold.yaml >@@ -101,7 +101,7 @@ properties: > non_priority: > description: Set this hold as non priority > type: boolean >- item_type: >+ item_type_id: > type: > - string > - "null" >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt >index 909f021204..3145bc1424 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt >@@ -1,3 +1,4 @@ >+[% USE To %] > [% USE raw %] > [% USE Asset %] > [% USE KohaDates %] >@@ -158,6 +159,29 @@ > [% INCLUDE 'str/members-menu.inc' %] > [% Asset.js("js/members-menu.js") | $raw %] > [% INCLUDE 'js-biblio-format.inc' %] >+ <script> >+ const all_libraries = [% To.json(Branches.all) | $raw %].map(e => { >+ e["_id"] = e["branchcode"]; >+ e["_str"] = e["branchname"]; >+ return e; >+ }); >+ >+ const all_item_types = [% To.json(ItemTypes.Get) | $raw %].map(e => { >+ e["_id"] = e["itemtype"]; >+ e["_str"] = e["translated_description"]; >+ return e; >+ }); >+ >+ var coded_values = { >+ library: new Map(all_libraries.map( l => [l.branchname, l.branchcode] )), >+ item_type: new Map(all_item_types.map( i => [i.translated_description, i.itemtype] )), >+ }; >+ >+ let filters_options = { >+ item_types: all_item_types, >+ libraries: all_libraries, >+ }; >+ </script> > <script> > $(document).ready(function() { > var table_settings = [% TablesSettings.GetTableSettings('members', 'holdshistory', 'holdshistory-table', 'json') | $raw %]; >@@ -165,6 +189,7 @@ > //Remove item type column settings > table_settings['columns'] = table_settings['columns'].filter(function(c){return c['columnname'] != 'itemtype';}); > [% END %] >+ > let current_holds_table = build_holds_table("#table_holdshistory"); > let old_holds_table = build_holds_table("#table_oldholdshistory", 1); > function build_holds_table(table_id, old){ >@@ -253,11 +278,13 @@ > } > }, > { >- data: "pickup_library_id:pickup_library.name", >+ data: "me.pickup_library_id", >+ datatype: "coded_value:library", >+ dataFilter: "libraries", > searchable: true, > orderable: true, > render: function (data, type, row, meta) { >- return row.pickup_library.name; >+ return escape_str(row._strings.pickup_library_id ? row._strings.pickup_library_id.str : row.pickup_library_id); > } > }, > { >@@ -298,12 +325,14 @@ > }, > [% IF show_itemtype_column %] > { >- data: "item_type", >+ data: "item_type_id", >+ datatype: "coded_value:item_type", >+ dataFilter: "item_types", > searchable: true, > orderable: true, > render: function (data, type, row, meta) { >- if ( row.item_type ) { >- return row.item_type; >+ if ( row.item_type_id ) { >+ return row._strings.item_type_id ? row._strings.item_type_id.str : row.item_type_id; > } else { > return _("Any item type"); > } >@@ -343,7 +372,12 @@ > } > }, > ], >- }, table_settings, true, additional_filters); >+ }, >+ table_settings, >+ true, >+ additional_filters, >+ filters_options, >+ ); > } > $("#current_holds_filters :checkbox, #old_holds_filters :checkbox").on("change", function(e){ > e.preventDefault(); >diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t >index 19a15a85f7..6dc608b2ab 100755 >--- a/t/db_dependent/Koha/Hold.t >+++ b/t/db_dependent/Koha/Hold.t >@@ -20,7 +20,7 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 20; >+use Test::More tests => 21; > > use Test::Exception; > use Test::MockModule; >@@ -92,6 +92,27 @@ subtest 'biblio() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'item_type() tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $hold = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { itemtype => undef }, >+ } >+ ); >+ >+ is( $hold->item_type, undef, 'Koha::Hold->item_type returns undef if no item type selected' ); >+ my $item_type = $builder->build_object( { class => "Koha::ItemTypes" } ); >+ $hold->itemtype( $item_type->itemtype )->store; >+ is( $hold->item_type->itemtype, $item_type->itemtype, 'Koha::Hold->item_type returns the correct item type' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'pickup_library/branch tests' => sub { > > plan tests => 1; >@@ -1207,7 +1228,7 @@ subtest 'change_type() tests' => sub { > > subtest 'strings_map() tests' => sub { > >- plan tests => 3; >+ plan tests => 4; > > $schema->txn_begin; > >@@ -1233,7 +1254,8 @@ subtest 'strings_map() tests' => sub { > is_deeply( > $strings_map, > { >- pickup_library_id => { str => $library->branchname, type => 'library' }, >+ pickup_library_id => { str => $library->branchname, type => 'library' }, >+ item_type_id => { str => $hold->item_type->description, type => 'item_type' }, > cancellation_reason => { str => $av->lib, type => 'av', category => 'HOLD_CANCELLATION' }, > }, > 'Strings map is correct' >@@ -1243,7 +1265,8 @@ subtest 'strings_map() tests' => sub { > is_deeply( > $strings_map, > { >- pickup_library_id => { str => $library->branchname, type => 'library' }, >+ pickup_library_id => { str => $library->branchname, type => 'library' }, >+ item_type_id => { str => $hold->item_type->description, type => 'item_type' }, > cancellation_reason => { str => $av->lib_opac, type => 'av', category => 'HOLD_CANCELLATION' }, > }, > 'Strings map is correct (OPAC)' >@@ -1255,12 +1278,24 @@ subtest 'strings_map() tests' => sub { > is_deeply( > $strings_map, > { >- pickup_library_id => { str => $library->branchname, type => 'library' }, >+ pickup_library_id => { str => $library->branchname, type => 'library' }, >+ item_type_id => { str => $hold->item_type->description, type => 'item_type' }, > cancellation_reason => { str => $hold->cancellation_reason, type => 'av', category => 'HOLD_CANCELLATION' }, > }, > 'Strings map shows the cancellation_value when AV not present' > ); > >+ $hold->itemtype(undef)->store; >+ $strings_map = $hold->strings_map( { public => 1 } ); >+ is_deeply( >+ $strings_map, >+ { >+ pickup_library_id => { str => $library->branchname, type => 'library' }, >+ cancellation_reason => { str => $hold->cancellation_reason, type => 'av', category => 'HOLD_CANCELLATION' }, >+ }, >+ 'Strings map does not show item_type_id if none selected' >+ ); >+ > $schema->txn_rollback; > }; > >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 41456
:
190537
| 190553