From 529c396a39a4c66cdd38aa00f270679f1b5d4934 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 --- Koha/ERM/EHoldings/Title.pm | 40 ++++++++++--------- Koha/REST/V1/ERM/EHoldings/Titles/Local.pm | 8 ++-- .../definitions/erm_eholdings_title.yaml | 5 +++ .../ERM/EHoldingsLocalTitlesFormAdd.vue | 22 ++++++++++ 4 files changed, 53 insertions(+), 22 deletions(-) diff --git a/Koha/ERM/EHoldings/Title.pm b/Koha/ERM/EHoldings/Title.pm index 129924b028..21752cdd0e 100644 --- a/Koha/ERM/EHoldings/Title.pm +++ b/Koha/ERM/EHoldings/Title.pm @@ -38,30 +38,32 @@ 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 eddf02f410..45c3fe7685 100644 --- a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm +++ b/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm @@ -91,9 +91,10 @@ 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); @@ -167,8 +168,9 @@ sub update { my $body = $c->req->json; 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.37.1 (Apple Git-137.1)