From 7afc67a5103985e2ed971eeddbe6ab73466c8000 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 6 Jun 2022 07:16:45 +0300 Subject: [PATCH] Bug 34142: Add new column sub_location to (deleted)items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new column sub_location to items and deleteditems table. Column can be used to indicate e.g. if item has some other more specific location than permanent location. To test: 1) Add new authorized value for sublocation e.g. "SUBLOC" and add some values to it. 2) Add new 952 subfield e.g. S to MARC framework and link your new authorized value "SUBLOC" to it. 3) Link subfield to items.sub_location field in "Koha to MARC mapping" (add 952,S). 4) Find a record and attempt to add new item to it. => Note that new subfield S is now displayed on item form and dropdown selector contains values added to "SUBLOC". => Saving should be successfull. => After saving confirm that sublocation is displayed in its own column in items listing above item form and that sublocation is displayed with correct description. 5) Attempt to modify item. => Confirm that sublocation is displayed and it's correct. 6) Attempt to delete item. => Deleting should be successfull. Also confirm that sub location is displayed on these pages: 1) detail.pl 2) moredetail.pl 3) returns.pl Sponsored-by: Koha-Suomi Oy Signed-off-by: Tadeusz „tadzik” Sośnierz Signed-off-by: PhilipOrr --- Koha/Database/Columns.pm | 1 + Koha/Item.pm | 1 + api/v1/swagger/definitions/item.yaml | 5 +++++ circ/returns.pl | 9 +++++++++ .../data/mysql/atomicupdate/bug_34142.pl | 20 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 2 ++ .../tables/items/catalogue_detail.inc | 7 +++++++ .../prog/en/modules/catalogue/moredetail.tt | 6 ++++++ .../prog/en/modules/circ/returns.tt | 2 +- 9 files changed, 52 insertions(+), 1 deletion(-) create mode 100755 installer/data/mysql/atomicupdate/bug_34142.pl diff --git a/Koha/Database/Columns.pm b/Koha/Database/Columns.pm index d23d7cc871..ee279bd2f3 100644 --- a/Koha/Database/Columns.pm +++ b/Koha/Database/Columns.pm @@ -234,6 +234,7 @@ sub columns { "notforloan" => __("Not for loan"), "onloan" => __("Due date"), "permanent_location" => __("Permanent shelving location"), + "sub_location" => __("Sublocation"), "price" => __("Price"), "renewals" => __("Total renewals"), "replacementprice" => __("Replacement price"), diff --git a/Koha/Item.pm b/Koha/Item.pm index e950118336..55447be568 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1856,6 +1856,7 @@ sub to_api_mapping { stocknumber => 'inventory_number', new_status => 'new_status', deleted_on => undef, + sub_location => 'sub_location' }; } diff --git a/api/v1/swagger/definitions/item.yaml b/api/v1/swagger/definitions/item.yaml index b254eb2dc3..7e237b55cb 100644 --- a/api/v1/swagger/definitions/item.yaml +++ b/api/v1/swagger/definitions/item.yaml @@ -237,6 +237,11 @@ properties: - string - "null" description: "'new' value, whatever free-text information." + sub_location: + type: + - string + - "null" + description: sub_location for this item exclude_from_local_holds_priority: type: boolean description: Exclude this item from local holds priority. diff --git a/circ/returns.pl b/circ/returns.pl index c9c89593a8..14c7795bf4 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -749,6 +749,11 @@ my $shelflocations = { { frameworkcode => '', kohafield => 'items.location' } ) }; +my $sublocation = { + map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( + { frameworkcode => '', kohafield => 'items.sub_location' } + ) +}; for my $checkin (@checkins) { my $item = Koha::Items->find( { barcode => $checkin->{barcode} } ); next unless $item; # FIXME The item has been deleted in the meantime, @@ -777,6 +782,10 @@ for my $checkin (@checkins) { my $shelfcode = $checkin->{item_location}; $checkin->{item_location} = $shelflocations->{$shelfcode} if ( defined($shelfcode) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) ); + $checkin->{sub_location} = $sublocation->{ $item->sub_location } + if ( defined( $item->sub_location ) + && defined($sublocation) + && exists( $sublocation->{ $item->sub_location } ) ); } $template->param( diff --git a/installer/data/mysql/atomicupdate/bug_34142.pl b/installer/data/mysql/atomicupdate/bug_34142.pl new file mode 100755 index 0000000000..47150091a6 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_34142.pl @@ -0,0 +1,20 @@ +use Modern::Perl; + +return { + bug_number => "34142", + description => "Add column sub_location to (deleted)items table", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + if ( !column_exists( 'items', 'sub_location' ) ) { + $dbh->do(q{ALTER TABLE items ADD COLUMN sub_location VARCHAR(80) DEFAULT NULL AFTER permanent_location}); + say $out "Added new column items.sub_location"; + } + if ( !column_exists( 'deleteditems', 'sub_location' ) ) { + $dbh->do( + q{ALTER TABLE deleteditems ADD COLUMN sub_location VARCHAR(80) DEFAULT NULL AFTER permanent_location}); + say $out "Added new column deleteditems.sub_location"; + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 9b7dc7fc6e..382d611d6b 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2818,6 +2818,7 @@ CREATE TABLE `deleteditems` ( `deleted_on` datetime DEFAULT NULL COMMENT 'date/time of deletion', `location` varchar(80) DEFAULT NULL COMMENT 'authorized value for the shelving location for this item (MARC21 952$c)', `permanent_location` varchar(80) DEFAULT NULL COMMENT 'linked to the CART and PROC temporary locations feature, stores the permanent shelving location', + `sub_location` varchar(80) DEFAULT NULL COMMENT 'authorized value for the sublocation for this item', `onloan` date DEFAULT NULL COMMENT 'defines if item is checked out (NULL for not checked out, and due date for checked out)', `cn_source` varchar(10) DEFAULT NULL COMMENT 'classification source used on this item (MARC21 952$2)', `cn_sort` varchar(255) DEFAULT NULL COMMENT 'normalized form of the call number (MARC21 952$o) used for sorting', @@ -4139,6 +4140,7 @@ CREATE TABLE `items` ( `deleted_on` datetime DEFAULT NULL COMMENT 'date/time of deletion', `location` varchar(80) DEFAULT NULL COMMENT 'authorized value for the shelving location for this item (MARC21 952$c)', `permanent_location` varchar(80) DEFAULT NULL COMMENT 'linked to the CART and PROC temporary locations feature, stores the permanent shelving location', + `sub_location` varchar(80) DEFAULT NULL COMMENT 'authorized value for the sublocation for this item', `onloan` date DEFAULT NULL COMMENT 'defines if item is checked out (NULL for not checked out, and due date for checked out)', `cn_source` varchar(10) DEFAULT NULL COMMENT 'classification source used on this item (MARC21 952$2)', `cn_sort` varchar(255) DEFAULT NULL COMMENT 'normalized form of the call number (MARC21 952$o) used for sorting', diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc index 3746af5f3c..fe327ba874 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc @@ -223,6 +223,7 @@ const can_edit_items_from = [% To.json(can_edit_items_from || []) | $raw %]; const item_type_image_locations = [% To.json(item_type_image_locations) | $raw %]; const av_loc = new Map([% To.json(AuthorisedValues.Get('LOC')) | $raw %].map( av => [av.authorised_value, av.lib])); + const av_subloc = new Map([% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.sub_location' })) | $raw %].map( av => [av.authorised_value, av.lib])); const av_lost = new Map([% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.itemlost' })) | $raw %].map( av => [av.authorised_value, av.lib])); const av_withdrawn = new Map([% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.withdrawn' })) | $raw %].map( av => [av.authorised_value, av.lib])); const av_damaged = new Map([% To.json(AuthorisedValues.GetDescriptionsByKohaField({ kohafield => 'items.damaged' })) | $raw %].map( av => [av.authorised_value, av.lib])); @@ -421,6 +422,12 @@ } else { nodes += escape_str(loc_str); } + if ( row.sub_location ) { + nodes += ''; + let sub_location_str = av_subloc.get(row.sub_location.toString()); + nodes += '(%s)'.format(escape_str(sub_location_str)); + nodes += ''; + } nodes += ''; return nodes; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt index e6ca9c6ae9..e479b66226 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt @@ -183,6 +183,12 @@ [% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => ITEM_DAT.location ) | html %] [% END %] + [% IF ( ITEM_DAT.sub_location ) %] +
  • + Sublocation: + [% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.sub_location', authorised_value => ITEM_DAT.sub_location ) | html %] +
  • + [% END %] [% IF ( ITEM_DAT.replacementprice ) %]
  • Replacement price: [% ITEM_DAT.replacementprice | $Price %] 
  • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index d2b1f67678..95f78f2605 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -1381,7 +1381,7 @@ [%- END -%] - [% checkin.item_location | html %] + [% checkin.location | html %] [% IF ( checkin.sub_location ) %] ([% checkin.sub_location | html %]) [% END %] [% checkin.item.itemcallnumber | html %] [% checkin.item.dateaccessioned | $KohaDates %] -- 2.39.5