View | Details | Raw Unified | Return to bug 36618
Collapse All | Expand All

(-)a/Koha/ERM/EHoldings/Title.pm (-19 / +24 lines)
Lines 38-67 Koha::ERM::EHoldings::Title - Koha ERM Title Object class Link Here
38
=cut
38
=cut
39
39
40
sub store {
40
sub store {
41
    my ($self) = @_;
41
    my ( $self, $args ) = @_;
42
43
    my $create_linked_biblio = $args->{create_linked_biblio} || 0;
42
44
43
    # FIXME This is terrible and ugly, we need to:
45
    # FIXME This is terrible and ugly, we need to:
44
    # * Provide a mapping for each attribute of title
46
    # * Provide a mapping for each attribute of title
45
    # * Create a txn
47
    # * Create a txn
46
48
47
    # If the 'title' is already linked to a biblio, then we update the title subfield only
49
    if ($create_linked_biblio) {
48
    if ( $self->biblio_id ) {
50
49
        my $biblio = Koha::Biblios->find( $self->biblio_id );
51
        # If the 'title' is already linked to a biblio, then we update the title subfield only
50
        my ( $title_tag, $title_subfield ) = GetMarcFromKohaField('biblio.title');
52
        if ( $self->biblio_id ) {
51
        my $record      = $biblio->metadata->record();
53
            my $biblio = Koha::Biblios->find( $self->biblio_id );
52
        my $title_field = $record->field($title_tag);
54
            my ( $title_tag, $title_subfield ) = GetMarcFromKohaField('biblio.title');
53
        $title_field->update( $title_subfield => $self->publication_title );
55
            my $record      = $biblio->metadata->record();
54
        C4::Biblio::ModBiblio( $record, $self->biblio_id, '' );
56
            my $title_field = $record->field($title_tag);
55
    } else {
57
            $title_field->update( $title_subfield => $self->publication_title );
56
58
            C4::Biblio::ModBiblio( $record, $self->biblio_id, '' );
57
        # If it's not linked, we create a simple biblio and save the biblio id to the 'title'
59
        } else {
58
        my $marc_record = TransformKohaToMarc(
60
59
            {
61
            # If it's not linked, we create a simple biblio and save the biblio id to the 'title'
60
                'biblio.title' => $self->publication_title,
62
            my $marc_record = TransformKohaToMarc(
61
            }
63
                {
62
        );
64
                    'biblio.title' => $self->publication_title,
63
        my ($biblio_id) = C4::Biblio::AddBiblio( $marc_record, '' );
65
                }
64
        $self->biblio_id($biblio_id);
66
            );
67
            my ($biblio_id) = C4::Biblio::AddBiblio( $marc_record, '' );
68
            $self->biblio_id($biblio_id);
69
        }
65
    }
70
    }
66
71
67
    $self = $self->SUPER::store;
72
    $self = $self->SUPER::store;
(-)a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm (-4 / +7 lines)
Lines 87-95 sub add { Link Here
87
87
88
                my $body = $c->req->json;
88
                my $body = $c->req->json;
89
89
90
                my $resources = delete $body->{resources} // [];
90
                my $resources            = delete $body->{resources}            // [];
91
                my $create_linked_biblio = delete $body->{create_linked_biblio} // 0;
91
92
92
                my $title = Koha::ERM::EHoldings::Title->new_from_api($body)->store;
93
                my $title = Koha::ERM::EHoldings::Title->new_from_api($body)
94
                    ->store( { create_linked_biblio => $create_linked_biblio } );
93
95
94
                $title->resources($resources);
96
                $title->resources($resources);
95
97
Lines 158-166 sub update { Link Here
158
160
159
                my $body = $c->req->json;
161
                my $body = $c->req->json;
160
162
161
                my $resources = delete $body->{resources} // [];
163
                my $resources            = delete $body->{resources}            // [];
164
                my $create_linked_biblio = delete $body->{create_linked_biblio} // 0;
162
165
163
                $title->set_from_api($body)->store;
166
                $title->set_from_api($body)->store( { create_linked_biblio => $create_linked_biblio } );
164
167
165
                $title->resources($resources);
168
                $title->resources($resources);
166
169
(-)a/api/v1/swagger/definitions/erm_eholdings_title.yaml (+5 lines)
Lines 144-149 properties: Link Here
144
    description: Resource containing this title
144
    description: Resource containing this title
145
    items:
145
    items:
146
      $ref: erm_eholdings_resource.yaml
146
      $ref: erm_eholdings_resource.yaml
147
  create_linked_biblio:
148
    description: should a linked biblio be created
149
    type:
150
      - boolean
151
      - "null"
147
152
148
additionalProperties: false
153
additionalProperties: false
149
required:
154
required:
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue (-1 / +22 lines)
Lines 366-371 Link Here
366
                        </li>
366
                        </li>
367
                    </ol>
367
                    </ol>
368
                </fieldset>
368
                </fieldset>
369
                <fieldset class="rows">
370
                    <legend>
371
                        {{
372
                            $__("%s linked biblio record").format(
373
                                title.title_id ? "Update" : "Create"
374
                            )
375
                        }}:
376
                    </legend>
377
                    <label for="create_linked_biblio"
378
                        >{{
379
                            $__("%s record").format(
380
                                title.title_id ? "Update" : "Create"
381
                            )
382
                        }}:</label
383
                    >
384
                    <input
385
                        type="checkbox"
386
                        id="create_linked_biblio"
387
                        v-model="title.create_linked_biblio"
388
                    />
389
                </fieldset>
369
                <EHoldingsTitlesFormAddResources :resources="title.resources" />
390
                <EHoldingsTitlesFormAddResources :resources="title.resources" />
370
                <fieldset class="action">
391
                <fieldset class="action">
371
                    <input type="submit" :value="$__('Submit')" />
392
                    <input type="submit" :value="$__('Submit')" />
Lines 429-434 export default { Link Here
429
                preceding_publication_title_id: "",
450
                preceding_publication_title_id: "",
430
                access_type: "",
451
                access_type: "",
431
                resources: [],
452
                resources: [],
453
                create_linked_biblio: false,
432
            },
454
            },
433
            initialized: false,
455
            initialized: false,
434
        }
456
        }
435
- 

Return to bug 36618