From 08992ab7119403d24bedfeca1c5b0e4a7b1c1798 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Wed, 17 Apr 2024 10:31:27 +0000 Subject: [PATCH] Bug 36618: Make biblio creation optional for ERM local titles This patch makes biblio creation on local title creation optional. Test plan: 1) Navigate to the local title creation form 2) Create a title and leave the "Create record" box unchecked 3) Submit the form 4) Search the catalogue for the title you have just created - no biblio result will be available 5) Repeat steps 2 - 3 but this time check the box to create a record 6) You should now be able to find a record in the catalogue for the title you just imported Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer --- Koha/ERM/EHoldings/Title.pm | 43 +++++++++++-------- Koha/REST/V1/ERM/EHoldings/Titles/Local.pm | 11 +++-- .../definitions/erm_eholdings_title.yaml | 5 +++ .../ERM/EHoldingsLocalTitlesFormAdd.vue | 22 ++++++++++ 4 files changed, 58 insertions(+), 23 deletions(-) diff --git a/Koha/ERM/EHoldings/Title.pm b/Koha/ERM/EHoldings/Title.pm index 129924b028..e11c06abf5 100644 --- a/Koha/ERM/EHoldings/Title.pm +++ b/Koha/ERM/EHoldings/Title.pm @@ -38,30 +38,35 @@ Koha::ERM::EHoldings::Title - Koha ERM Title Object class =cut sub store { - my ($self) = @_; + my ( $self, $args ) = @_; + + my $create_linked_biblio = $args->{create_linked_biblio} || 0; # FIXME This is terrible and ugly, we need to: # * Provide a mapping for each attribute of title # * Create a txn - # If the 'title' is already linked to a biblio, then we update the title subfield only - if ( $self->biblio_id ) { - my $biblio = Koha::Biblios->find( $self->biblio_id ); - my ( $title_tag, $title_subfield ) = GetMarcFromKohaField('biblio.title'); - my $record = $biblio->metadata->record(); - my $title_field = $record->field($title_tag); - $title_field->update( $title_subfield => $self->publication_title ); - C4::Biblio::ModBiblio( $record, $self->biblio_id, '' ); - } else { - - # If it's not linked, we create a simple biblio and save the biblio id to the 'title' - my $marc_record = TransformKohaToMarc( - { - 'biblio.title' => $self->publication_title, - } - ); - my ($biblio_id) = C4::Biblio::AddBiblio( $marc_record, '' ); - $self->biblio_id($biblio_id); + if ($create_linked_biblio) { + + # If the 'title' is already linked to a biblio, then we update the title subfield only + if ( $self->biblio_id ) { + my $biblio = Koha::Biblios->find( $self->biblio_id ); + my ( $title_tag, $title_subfield ) = GetMarcFromKohaField('biblio.title'); + my $record = $biblio->metadata->record(); + my $title_field = $record->field($title_tag); + $title_field->update( $title_subfield => $self->publication_title ); + C4::Biblio::ModBiblio( $record, $self->biblio_id, '' ); + } else { + + # If it's not linked, we create a simple biblio and save the biblio id to the 'title' + my $marc_record = TransformKohaToMarc( + { + 'biblio.title' => $self->publication_title, + } + ); + my ($biblio_id) = C4::Biblio::AddBiblio( $marc_record, '' ); + $self->biblio_id($biblio_id); + } } $self = $self->SUPER::store; diff --git a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm b/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm index 10c1a9ee8f..d8d16741be 100644 --- a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm +++ b/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm @@ -87,9 +87,11 @@ sub add { my $body = $c->req->json; - my $resources = delete $body->{resources} // []; + my $resources = delete $body->{resources} // []; + my $create_linked_biblio = delete $body->{create_linked_biblio} // 0; - my $title = Koha::ERM::EHoldings::Title->new_from_api($body)->store; + my $title = Koha::ERM::EHoldings::Title->new_from_api($body) + ->store( { create_linked_biblio => $create_linked_biblio } ); $title->resources($resources); @@ -158,9 +160,10 @@ sub update { my $body = $c->req->json; - my $resources = delete $body->{resources} // []; + my $resources = delete $body->{resources} // []; + my $create_linked_biblio = delete $body->{create_linked_biblio} // 0; - $title->set_from_api($body)->store; + $title->set_from_api($body)->store( { create_linked_biblio => $create_linked_biblio } ); $title->resources($resources); diff --git a/api/v1/swagger/definitions/erm_eholdings_title.yaml b/api/v1/swagger/definitions/erm_eholdings_title.yaml index 7185009fef..7ed823fcad 100644 --- a/api/v1/swagger/definitions/erm_eholdings_title.yaml +++ b/api/v1/swagger/definitions/erm_eholdings_title.yaml @@ -144,6 +144,11 @@ properties: description: Resource containing this title items: $ref: erm_eholdings_resource.yaml + create_linked_biblio: + description: should a linked biblio be created + type: + - boolean + - "null" additionalProperties: false required: diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue index 30f9bbb8df..bd4ff14f66 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue @@ -366,6 +366,27 @@ +
+ + {{ + $__("%s linked biblio record").format( + title.title_id ? "Update" : "Create" + ) + }}: + + + +
@@ -429,6 +450,7 @@ export default { preceding_publication_title_id: "", access_type: "", resources: [], + create_linked_biblio: false, }, initialized: false, } -- 2.39.5