From 57c873f358a5999728c8e77f578b42d33f91bfaf Mon Sep 17 00:00:00 2001 From: Leo Stoyanov Date: Fri, 10 Jan 2025 23:01:17 +0000 Subject: [PATCH] Bug 38839: Added "decimal" validation for replacement price in item and batch modification forms. Adds validation for the replacement price on the item input and batch modification forms. This new patch utilizes the standard jQuery "decimal" validator to check if monetary input is appropriatly formatted. Test plan: 1. Search for a record in the staff interface, select any record with an item, click "Edit", and select "Manage items". 2. Click "Actions" on the item in the table, select "Edit", and input an invalid "v - Cost, replacement price" (for example, 1,00). 3. Click "Save changes" and the form will submit but with no price shown in the table on the next page. 4. Apply the patch, update the CSS (yarn build) and restart everything (restart_all). 5. Repeat steps 1-3. A red error message will now appear to the right of the input field, notifying the user that only numbers and periods are allowed. The user will not be able to submit the form. 6. The same change was also made to the batch modification form under Cataloging > Batch item modification. --- Koha/UI/Form/Builder/Item.pm | 7 +++ .../prog/en/includes/html_helpers.inc | 2 + .../prog/en/modules/cataloguing/additem.tt | 2 +- .../prog/en/modules/tools/batchMod-edit.tt | 2 +- t/db_dependent/Koha/UI/Form/Builder/Item.t | 46 ++++++++++++++++++- 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/Koha/UI/Form/Builder/Item.pm b/Koha/UI/Form/Builder/Item.pm index cbc52522c3..c05fadeebd 100644 --- a/Koha/UI/Form/Builder/Item.pm +++ b/Koha/UI/Form/Builder/Item.pm @@ -403,6 +403,13 @@ sub generate_subfield_form { value => $value, }; } + elsif ( $subfield->{kohafield} =~ /items\.(replacementprice)/ ) { + $subfield_data{marc_value} = { + type => 'replacementprice', + id => $subfield_data{id}, + value => $value + }; + } else { # it's a standard field $subfield_data{marc_value} = { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc index 50d618f392..f4f349282f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc @@ -170,6 +170,8 @@ [% ELSIF ( mv.type == 'datetime_field' ) %] + [% ELSIF ( mv.type == 'replacementprice' ) %] + [% END %] [% IF subfield.kohafield == 'items.more_subfields_xml' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index a41569fe99..5ef1388506 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -199,7 +199,7 @@
-
+ [% INCLUDE 'csrf-token.inc' %] [% IF (popup) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt index b2b3161f21..66133df5e1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt @@ -156,7 +156,7 @@ [% END # /IF notfounditemnumbers.size %] - + [% INCLUDE 'csrf-token.inc' %] diff --git a/t/db_dependent/Koha/UI/Form/Builder/Item.t b/t/db_dependent/Koha/UI/Form/Builder/Item.t index 251287a530..d63813f7af 100755 --- a/t/db_dependent/Koha/UI/Form/Builder/Item.t +++ b/t/db_dependent/Koha/UI/Form/Builder/Item.t @@ -16,7 +16,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; use Test::MockModule; use Data::Dumper qw( Dumper ); use utf8; @@ -456,3 +456,47 @@ sub setup_mss { } )->update( { display_order => \['FLOOR( 1 + RAND( ) * 10 )'] } ); } + +subtest 'replacementprice handling' => sub { + plan tests => 3; + + my $subfield = { + kohafield => 'items.replacementprice', + id => 'tag_952_subfield_v_12345', + value => '123.45', + }; + + my $expected_marc_value = { + type => 'replacementprice', + id => 'tag_952_subfield_v_12345', + value => '123.45', + }; + + my $item = Koha::Item->new(); + + my %subfield_data; + if ( $subfield->{kohafield} =~ /items\.(replacementprice)/ ) { + $subfield_data{marc_value} = { + type => 'replacementprice', + id => $subfield->{id}, + value => $subfield->{value}, + }; + } + + ok( + exists $subfield_data{marc_value}, + "Subfield data contains 'marc_value' key" + ); + + is( + $subfield_data{marc_value}->{type}, + $expected_marc_value->{type}, + "Subfield 'type' is correctly set to 'replacementprice'" + ); + + is_deeply( + $subfield_data{marc_value}, + $expected_marc_value, + 'Subfield data is processed correctly for replacementprice' + ); +}; -- 2.39.5