From 1c5202e719d4845df78068a680a3732ada99c995 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 15 Oct 2025 18:58:42 +0000 Subject: [PATCH] Bug 41029: Add option for marc overlay rules to apply when adding to a basket This patch adds a new option to allow defining overlay rules for 'Add to basket' - such that they will be used when adding orders in acquisition. Existing 'Staged MARC Import' rules will be copied to the new fitler in order to preserve behavior To test: 1 - Paste the following into MarcFieldsToOrder and save price: 975$p quantity: 975$q budget_code: 975$h 2 - Paste the following into MarcItemFieldsToOrder and save homebranch: 949$a holdingbranch: 949$b itype: 949$y nonpublic_note: 949$x public_note: 949$z loc: 949$c ccode: 949$8 notforloan: 949$7 uri: 949$u copyno: 949$t price: 949$g replacementprice: 949$v itemcallnumber: 949$o quantity: 949$k budget_code: 949$l 3 - Go to Admin -> Record overlay rules 4 - Define 2 rules: Source - Staged Marc Import - 949 - Add and append (the rest of the options are set when add and append is selected Source - Staged Marc Import - * - Protect (the rest of the options are set when add and append is selected 5 - Grab test file from bug 39518 6 - Import the records, ignoring items 7 - Edit the test file and change some values for the 949 rows 8 - Go to Acquisitions, find a basket for a vendor, add to basket from a new file 9 - Stage the file to find matches (already imported above) and to replace 10 - Complete the orders 11 - View the record and confirm the new 949 are added 12 - Edit the 949 in the file again 13 - Apply patch, update database, restart all 14 - Edit overlay rules and remove the 'Staged Marc Import' rules, leaving only the 'Add to basket rules' 15 - Add to basket again using the updated file and confirm new 949 are added 16 - Success! --- Koha/Import/Record.pm | 2 +- .../data/mysql/atomicupdate/bug_41029.pl | 40 +++++++++++++++++++ .../en/modules/admin/marc-overlay-rules.tt | 3 ++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100755 installer/data/mysql/atomicupdate/bug_41029.pl diff --git a/Koha/Import/Record.pm b/Koha/Import/Record.pm index 9b1e1c3f675..2f888bfd432 100644 --- a/Koha/Import/Record.pm +++ b/Koha/Import/Record.pm @@ -132,7 +132,7 @@ sub replace { if ($biblio) { my $record = $biblio->metadata->record; $xmlrecord = $record->as_xml; - my $context = { source => 'batchimport' }; + my $context = { source => 'add_to_basket' }; if ($logged_in_patron) { $context->{categorycode} = $logged_in_patron->categorycode; $context->{userid} = $logged_in_patron->userid; diff --git a/installer/data/mysql/atomicupdate/bug_41029.pl b/installer/data/mysql/atomicupdate/bug_41029.pl new file mode 100755 index 00000000000..b252c6d1dfb --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_41029.pl @@ -0,0 +1,40 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_success say_info); + +return { + bug_number => "41029", + description => "Add 'add_to_basket' source option for MARC overlay rules", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + my $existing_batchimport_rules_count = ( + $dbh->selectrow_array( + 'SELECT COUNT(*) FROM marc_overlay_rules WHERE module="source" and filter="batchimport"', undef + ) + )[0]; + my $existing_add_to_basket_rules_count = ( + $dbh->selectrow_array( + 'SELECT COUNT(*) FROM marc_overlay_rules WHERE module="source" and filter="add_to_basket"', undef + ) + )[0]; + if ( $existing_batchimport_rules_count > 0 && $existing_add_to_basket_rules_count == 0 ) { + say_info( $out, "Existing batchimport marc_overlay_rules found and no add_to_basket rules found" ); + $dbh->do( + q{ + INSERT INTO marc_overlay_rules (`tag`, `module`, `filter`, `add`, `append`, `remove`, `delete`) + SELECT `tag`, `module`, "add_to_basket", `add`, `append`, `remove`, `delete` + FROM marc_overlay_rules + WHERE module = 'source' AND filter = 'batchimport' + } + ); + say $out "Added existing batchimport overlay rules as add_to_basket rules"; + } else { + say_info( + $out, + "No existing batchimport marc_overlay_rules found or existing add_to_basket rules found, not updating" + ); + } + + }, +}; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc-overlay-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc-overlay-rules.tt index afd9a028d82..af0302f7976 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc-overlay-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc-overlay-rules.tt @@ -273,6 +273,8 @@ Staff interface MARC editor [% CASE 'batchimport' %] Staged MARC import + [% CASE 'add_to_basket' %] + Add to basket [% CASE 'z3950' %] Z39.50 [% CASE 'bulkmarkimport' %] @@ -505,6 +507,7 @@ batchmod: _("Batch record modification"), intranet: _("Staff interface MARC editor"), batchimport: _("Staged MARC import"), + add_to_basket: _("Add to basket"), z3950: _("Z39.50"), bulkmarcimport: _("bulkmarcimport.pl"), import_lexile: _("import_lexile.pl") -- 2.39.5