@@ -, +, @@ library level --- C4/AuthoritiesMarc.pm | 12 +++++++++--- C4/Biblio.pm | 7 ++++++- Koha/Library.pm | 8 ++++++++ cataloguing/value_builder/marc21_orgcode.pl | 5 ++++- 4 files changed, 27 insertions(+), 5 deletions(-) --- a/C4/AuthoritiesMarc.pm +++ a/C4/AuthoritiesMarc.pm @@ -32,6 +32,7 @@ use Koha::Authorities; use Koha::Authority::MergeRequest; use Koha::Authority::Types; use Koha::Authority; +use Koha::Libraries; use Koha::SearchEngine; use Koha::SearchEngine::Search; @@ -605,12 +606,17 @@ sub AddAuthority { SetUTF8Flag($record); if ($format eq "MARC21") { + my $userenv = C4::Context->userenv; + my $library; + if ( $userenv && $userenv->{'branch'} ) { + $library = Koha::Libraries->find( $userenv->{'branch'} ); + } if (!$record->leader) { $record->leader($leader); } if (!$record->field('003')) { $record->insert_fields_ordered( - MARC::Field->new('003',C4::Context->preference('MARCOrgCode')) + MARC::Field->new('003', $library ? $library->get_effective_marcorgcode : C4::Context->preference('MARCOrgCode')) ); } my $date=POSIX::strftime("%y%m%d",localtime); @@ -629,8 +635,8 @@ sub AddAuthority { if (!$record->field('040')) { $record->insert_fields_ordered( MARC::Field->new('040','','', - 'a' => C4::Context->preference('MARCOrgCode'), - 'c' => C4::Context->preference('MARCOrgCode') + 'a' => $library ? $library->get_effective_marcorgcode : C4::Context->preference('MARCOrgCode'), + 'c' => $library ? $library->get_effective_marcorgcode : C4::Context->preference('MARCOrgCode') ) ); } --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -569,6 +569,11 @@ sub LinkBibHeadingsToAuthorities { # of change to a core API just before the 3.0 release. if ( C4::Context->preference('marcflavour') eq 'MARC21' ) { + my $userenv = C4::Context->userenv; + my $library; + if ( $userenv && $userenv->{'branch'} ) { + $library = Koha::Libraries->find( $userenv->{'branch'} ); + } $marcrecordauth->insert_fields_ordered( MARC::Field->new( '667', '', '', @@ -583,7 +588,7 @@ sub LinkBibHeadingsToAuthorities { $cite =~ s/[\s\,]*$//; $cite = "Work cat.: (" - . C4::Context->preference('MARCOrgCode') . ")" + . ( $library ? $library->get_effective_marcorgcode : C4::Context->preference('MARCOrgCode') ) . ")" . $bib->subfield( '999', 'c' ) . ": " . $cite; $marcrecordauth->insert_fields_ordered( --- a/Koha/Library.pm +++ a/Koha/Library.pm @@ -21,6 +21,8 @@ use Modern::Perl; use Carp; +use C4::Context; + use Koha::Database; use base qw(Koha::Object); @@ -54,6 +56,12 @@ sub add_to_categories { } } +sub get_effective_marcorgcode { + my ( $self ) = @_; + + return $self->marcorgcode || C4::Context->preference("MARCOrgCode"); +} + =head3 type =cut --- a/cataloguing/value_builder/marc21_orgcode.pl +++ a/cataloguing/value_builder/marc21_orgcode.pl @@ -23,9 +23,12 @@ use Modern::Perl; use C4::Context; +use Koha::Libraries; + my $builder = sub { my ( $params ) = @_; - my $org = C4::Context->preference('MARCOrgCode'); + my $library = Koha::Libraries->find( C4::Context->userenv->{'branch'} ); + my $org = $library->get_effective_marcorgcode; return <<"HERE";