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!

Signed-off-by: Benjamin Daeuber <BDaeuber@fargolibrary.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Nick Clemens 2025-10-15 18:58:42 +00:00 committed by Pedro Amorim
parent 9fc9f84b8d
commit f473c7d451
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
3 changed files with 46 additions and 3 deletions

View File

@ -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;

View File

@ -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"
);
}
},
};

View File

@ -215,6 +215,8 @@
<span>Staff interface MARC editor</span>
[% CASE 'batchimport' %]
<span>Staged MARC import</span>
[% CASE 'add_to_basket' %]
<span>Add to basket</span>
[% CASE 'z3950' %]
<span>Z39.50</span>
[% CASE 'bulkmarcimport' %]
@ -326,11 +328,12 @@
[% FOREACH record_source IN record_sources %]
[% SWITCH record_source %]
[% CASE 'batchmod' %]'[% record_source | html %]': _("Batch record modification"),
[% CASE 'intranet' %]'[% record_source | html %]':_("Staff interface MARC editor"),
[% CASE 'intranet' %]'[% record_source | html %]': _("Staff interface MARC editor"),
[% CASE 'batchimport' %]'[% record_source | html %]': _("Staged MARC import"),
[% CASE 'add_to_basket' %]'[% record_source | html %]': _("Add to basket"),
[% CASE 'z3950' %]'[% record_source | html %]': _("Z39.50"),
[% CASE 'bulkmarcimport' %]'[% record_source | html %]': _("bulkmarcimport.pl"),
[% CASE 'import_lexile' %]'[% record_source | html %]': _("import_lexile.pl"),
[% CASE 'import_lexile' %]'[% record_source | html %]': _("import_lexile.pl"),
[% CASE %] '[% record_source | html %]' : '[% record_source | html %]',
[% END %]
[% END %]