From 1deb225616a62734187bf745cb1e42c136d635ba 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 | 6 +++ .../prog/en/includes/html_helpers.inc | 10 ++++ .../prog/en/modules/cataloguing/additem.tt | 2 +- .../prog/en/modules/tools/batchMod-edit.tt | 2 +- t/db_dependent/Koha/UI/Form/Builder/Item.t | 48 ++++++++++++++++++- 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/Koha/UI/Form/Builder/Item.pm b/Koha/UI/Form/Builder/Item.pm index 033037d43d9..a4c6490a7ab 100644 --- a/Koha/UI/Form/Builder/Item.pm +++ b/Koha/UI/Form/Builder/Item.pm @@ -368,6 +368,12 @@ sub generate_subfield_form { id => $subfield_data{id}, 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 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 f3924534546..d0d1484606e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc @@ -235,6 +235,16 @@ data-flatpickr-enable-time="true" data-flatpickr-set-to-today="true" /> + [% 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 76758d3deb6..0ed438293c0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -229,7 +229,7 @@
[% INCLUDE 'biblio-view-menu.inc' %]
-
+ [% 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 1d5511c9a49..5b26678ee09 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 @@ -162,7 +162,7 @@ [% END %] [% 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 2eab4bfcec1..e4c5968ddb8 100755 --- a/t/db_dependent/Koha/UI/Form/Builder/Item.t +++ b/t/db_dependent/Koha/UI/Form/Builder/Item.t @@ -17,7 +17,7 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 11; +use Test::More tests => 12; use Test::MockModule; use Data::Dumper qw( Dumper ); use utf8; @@ -83,7 +83,7 @@ subtest 'authorised values' => sub { $subfield->{marc_value}->{values}, [ "", - map { $_->authorised_value } + map { $_->authorised_value } sort { $a->lib cmp $b->lib } $avs->as_list ], 'AVs are sorted by lib and en empty option is created first' @@ -446,4 +446,48 @@ sub setup_mss { tagfield => $itemtag, } )->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.34.1