Bug 38271: Handle missing 008 fields in EDI
This patch adds handling to create a default 008 field on MARC records that are missing one when created through EDI. Test plan: 1) prove t/db_dependent/Koha/EDI.t Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de> (cherry picked from commitb00fb3d557) Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> (cherry picked from commit4eccb57f06) Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
b439619e06
commit
2606b4ee2e
24
Koha/EDI.pm
24
Koha/EDI.pm
|
|
@ -45,6 +45,7 @@ use Koha::Plugins; # Adds plugin dirs to @INC
|
|||
use Koha::Plugins::Handler;
|
||||
use Koha::Acquisition::Baskets;
|
||||
use Koha::Acquisition::Booksellers;
|
||||
use Koha::Util::FrameworkPlugin qw( biblio_008 );
|
||||
|
||||
our $VERSION = 1.1;
|
||||
|
||||
|
|
@ -685,6 +686,10 @@ sub quote_item {
|
|||
if ( !defined $bib ) {
|
||||
$bib = {};
|
||||
my $bib_record = _create_bib_from_quote( $item, $quote );
|
||||
|
||||
# Check for and add default 008 as this is a mandatory field
|
||||
$bib_record = _handle_008_field($bib_record);
|
||||
|
||||
( $bib->{biblionumber}, $bib->{biblioitemnumber} ) =
|
||||
AddBiblio( $bib_record, q{} );
|
||||
$logger->trace("New biblio added $bib->{biblionumber}");
|
||||
|
|
@ -1216,6 +1221,17 @@ sub _create_item_from_quote {
|
|||
return $item_hash;
|
||||
}
|
||||
|
||||
sub _handle_008_field {
|
||||
my ( $bib_record ) = @_;
|
||||
|
||||
if ( !$bib_record->field('008') ) {
|
||||
my $default008 = biblio_008();
|
||||
$bib_record->insert_fields_ordered( MARC::Field->new('008', $default008));
|
||||
}
|
||||
|
||||
return $bib_record
|
||||
}
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
|
|
@ -1374,6 +1390,14 @@ Koha::EDI
|
|||
Returns the Aqbudget object for the active budget given the passed budget_code
|
||||
or undefined if one does not exist
|
||||
|
||||
=head2 _handle_008_field
|
||||
|
||||
bib_record = _handle_008_field($bib_record)
|
||||
|
||||
Checks whether an 008 field exists on the record and adds a default field it does not
|
||||
|
||||
Returns the bib_record
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Colin Campbell <colin.campbell@ptfs-europe.com>
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@
|
|||
use Modern::Perl;
|
||||
use FindBin qw( $Bin );
|
||||
|
||||
use Test::More tests => 1;
|
||||
use Test::More tests => 2;
|
||||
use Test::Warn;
|
||||
use Test::MockModule;
|
||||
|
||||
use t::lib::Mocks;
|
||||
use t::lib::TestBuilder;
|
||||
|
|
@ -123,3 +124,168 @@ subtest 'process_quote' => sub {
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest '_handle_008_field' => sub {
|
||||
plan tests => 4;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
# Add our test quote file to the database for testing against
|
||||
my $account = $builder->build(
|
||||
{
|
||||
source => 'VendorEdiAccount',
|
||||
value => {
|
||||
description => 'test vendor', transport => 'FILE',
|
||||
}
|
||||
}
|
||||
);
|
||||
my $dirname = ( $Bin =~ /^(.*\/t\/)/ ? $1 . 'edi_testfiles/' : q{} );
|
||||
my $filename = 'QUOTES_SMALL.CEQ';
|
||||
ok( -e $dirname . $filename, 'File QUOTES_SMALL.CEQ found' );
|
||||
|
||||
my $trans = Koha::Edifact::Transport->new( $account->{id} );
|
||||
$trans->working_directory($dirname);
|
||||
|
||||
my $mhash = $trans->message_hash();
|
||||
$mhash->{message_type} = 'QUOTE';
|
||||
$trans->ingest( $mhash, $filename );
|
||||
|
||||
my $quote = $schema->resultset('EdifactMessage')->find( { filename => $filename } );
|
||||
|
||||
# Test quote expects REF to be a valid and active fund code
|
||||
my $active_period = $builder->build(
|
||||
{
|
||||
source => 'Aqbudgetperiod',
|
||||
value => { budget_period_active => 1 }
|
||||
}
|
||||
);
|
||||
my $fund = $builder->build(
|
||||
{
|
||||
source => 'Aqbudget',
|
||||
value => {
|
||||
budget_code => 'REF',
|
||||
budget_period_id => $active_period->{budget_period_id}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
# The quote expects a ROT1 stock rotation roata to exist
|
||||
my $rota = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::StockRotationRotas',
|
||||
value => { title => 'ROT1' }
|
||||
}
|
||||
);
|
||||
$builder->build(
|
||||
{
|
||||
source => 'Stockrotationstage',
|
||||
value => { rota_id => $rota->rota_id },
|
||||
}
|
||||
);
|
||||
|
||||
# Process the test quote file
|
||||
process_quote($quote);
|
||||
|
||||
$quote->get_from_storage;
|
||||
|
||||
# Tests for generated basket for passed quote file
|
||||
my $baskets = Koha::Acquisition::Baskets->search( { booksellerid => $account->{vendor_id} } );
|
||||
my $basket = $baskets->next;
|
||||
|
||||
my $orders = $basket->orders;
|
||||
my $order = $orders->next;
|
||||
|
||||
my $biblio = $order->biblio;
|
||||
my $record = $biblio->record;
|
||||
my $record_field = $record->field('008');
|
||||
|
||||
is(exists($record_field->{_data}), 1, 'Field has been added');
|
||||
|
||||
# Test without calling the 008 handler
|
||||
$account = $builder->build(
|
||||
{
|
||||
source => 'VendorEdiAccount',
|
||||
value => {
|
||||
description => 'test vendor', transport => 'FILE',
|
||||
}
|
||||
}
|
||||
);
|
||||
$dirname = ( $Bin =~ /^(.*\/t\/)/ ? $1 . 'edi_testfiles/' : q{} );
|
||||
$filename = 'QUOTES_SMALL_2.CEQ';
|
||||
ok( -e $dirname . $filename, 'File QUOTES_SMALL_2.CEQ found' );
|
||||
|
||||
$trans = Koha::Edifact::Transport->new( $account->{id} );
|
||||
$trans->working_directory($dirname);
|
||||
|
||||
$mhash = $trans->message_hash();
|
||||
$mhash->{message_type} = 'QUOTE';
|
||||
$trans->ingest( $mhash, $filename );
|
||||
|
||||
$quote = $schema->resultset('EdifactMessage')->find( { filename => $filename } );
|
||||
|
||||
# Test quote expects REF to be a valid and active fund code
|
||||
$active_period = $builder->build(
|
||||
{
|
||||
source => 'Aqbudgetperiod',
|
||||
value => { budget_period_active => 1 }
|
||||
}
|
||||
);
|
||||
$fund = $builder->build(
|
||||
{
|
||||
source => 'Aqbudget',
|
||||
value => {
|
||||
budget_code => 'REF2',
|
||||
budget_period_id => $active_period->{budget_period_id}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
# The quote expects a ROT1 stock rotation roata to exist
|
||||
$rota = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::StockRotationRotas',
|
||||
value => { title => 'ROT2' }
|
||||
}
|
||||
);
|
||||
$builder->build(
|
||||
{
|
||||
source => 'Stockrotationstage',
|
||||
value => { rota_id => $rota->rota_id },
|
||||
}
|
||||
);
|
||||
|
||||
# Process the test quote file
|
||||
my $edi_module = Test::MockModule->new('Koha::EDI');
|
||||
$edi_module->mock(
|
||||
'_check_for_existing_bib',
|
||||
sub {
|
||||
my $bib_record = shift;
|
||||
return undef;
|
||||
}
|
||||
);
|
||||
$edi_module->mock(
|
||||
'_handle_008_field',
|
||||
sub {
|
||||
my $bib_record = shift;
|
||||
return $bib_record;
|
||||
}
|
||||
);
|
||||
process_quote($quote);
|
||||
|
||||
$quote->get_from_storage;
|
||||
|
||||
# Tests for generated basket for passed quote file
|
||||
$baskets = Koha::Acquisition::Baskets->search( { booksellerid => $account->{vendor_id} } );
|
||||
$basket = $baskets->next;
|
||||
|
||||
$orders = $basket->orders;
|
||||
$order = $orders->next;
|
||||
|
||||
$biblio = $order->biblio;
|
||||
$record = $biblio->record;
|
||||
$record_field = $record->field('008');
|
||||
|
||||
is( $record_field->{_data}, undef, 'Field has not been added' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
UNA:+.? 'UNB+UNOC:3+5013546027173+5013546098818+240123:0945+1044416+ASKEDI:+QUOTES++++'UNH+1044416001+QUOTES:D:96A:UN:EAN002'BGM+31C::28+WO0800131+9'DTM+137:20240123:102'RFF+ON:orders 23/1'CUX+2:GBP:12'NAD+BY+5013546098818::9'NAD+SU+5013546027173::9'LIN+1++9781529923766:EN'PIA+5+152992376X:IB'IMD+L+010+:::Thompson'IMD+L+011+:::Louise'IMD+L+050+:::Lucky'IMD+L+060+:::learning to live again'IMD+L+120+:::Ebury Spotlight'IMD+L+170+:::2024'IMD+L+180+:::304'IMD+L+220+:::Hbk'IMD+L+230+:::791.45'IMD+L+250+:::AN'QTY+1:1'GIR+001+BOOK:LST+ANF:LSQ+CPL:LLO+REF:LFN+791.45:LCL'GIR+001+22.00:LCV'GIR+001+ROT1:LRP'PRI+AAE:22.00'RFF+QLI:WO0800131000001'UNS+S'CNT+2:1'UNT+27+1044416001'UNZ+1+1044416'
|
||||
Loading…
Reference in New Issue