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

(-)a/Koha/AdditionalField.pm (+1 lines)
Lines 62-67 sub to_api { Link Here
62
        'erm_licenses'        => 'license',
62
        'erm_licenses'        => 'license',
63
        'erm_agreements'      => 'agreement',
63
        'erm_agreements'      => 'agreement',
64
        'erm_packages'        => 'package',
64
        'erm_packages'        => 'package',
65
        'bookings'            => 'booking',
65
        'aqorders'            => 'order',
66
        'aqorders'            => 'order',
66
    };
67
    };
67
68
(-)a/Koha/Booking.pm (-1 / +1 lines)
Lines 29-35 use C4::Letters; Link Here
29
29
30
use List::Util qw(any);
30
use List::Util qw(any);
31
31
32
use base qw(Koha::Object);
32
use base qw( Koha::Object Koha::Object::Mixin::AdditionalFields );
33
33
34
=head1 NAME
34
=head1 NAME
35
35
(-)a/Koha/Bookings.pm (-1 / +1 lines)
Lines 22-28 use Modern::Perl; Link Here
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Booking;
23
use Koha::Booking;
24
24
25
use base qw(Koha::Objects);
25
use base qw( Koha::Objects::Mixin::AdditionalFields Koha::Objects );
26
26
27
=head1 NAME
27
=head1 NAME
28
28
(-)a/Koha/REST/V1/Bookings.pm (-6 / +16 lines)
Lines 75-83 sub add { Link Here
75
    my $c = shift->openapi->valid_input or return;
75
    my $c = shift->openapi->valid_input or return;
76
76
77
    return try {
77
    return try {
78
        my $booking = Koha::Booking->new_from_api( $c->req->json );
78
        my $body                = $c->req->json;
79
        $booking->store;
79
        my $extended_attributes = delete $body->{extended_attributes} // [];
80
        $booking->discard_changes;
80
81
        my $booking = Koha::Booking->new_from_api($body)->store;
82
83
        my @extended_attributes = map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes};
84
        $booking->extended_attributes( \@extended_attributes );
85
81
        $c->res->headers->location( $c->req->url->to_string . '/' . $booking->booking_id );
86
        $c->res->headers->location( $c->req->url->to_string . '/' . $booking->booking_id );
82
        return $c->render(
87
        return $c->render(
83
            status  => 201,
88
            status  => 201,
Lines 117-125 sub update { Link Here
117
        unless $booking;
122
        unless $booking;
118
123
119
    return try {
124
    return try {
120
        $booking->set_from_api( $c->req->json );
125
        my $body                = $c->req->json;
121
        $booking->store();
126
        my $extended_attributes = delete $body->{extended_attributes} // [];
122
        $booking->discard_changes;
127
128
        $booking->set_from_api($body)->store;
129
130
        my @extended_attributes = map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes};
131
        $booking->extended_attributes( \@extended_attributes );
132
123
        return $c->render( status => 200, openapi => $c->objects->to_api($booking) );
133
        return $c->render( status => 200, openapi => $c->objects->to_api($booking) );
124
    } catch {
134
    } catch {
125
        $c->unhandled_exception($_);
135
        $c->unhandled_exception($_);
(-)a/Koha/REST/V1/ExtendedAttributeTypes.pm (+1 lines)
Lines 53-58 sub list { Link Here
53
        license   => 'erm_licenses',
53
        license   => 'erm_licenses',
54
        agreement => 'erm_agreements',
54
        agreement => 'erm_agreements',
55
        package   => 'erm_packages',
55
        package   => 'erm_packages',
56
        booking   => 'bookings',
56
        order     => 'aqorders',
57
        order     => 'aqorders',
57
    };
58
    };
58
59
(-)a/Koha/Schema/Result/Booking.pm (-1 / +27 lines)
Lines 260-265 __PACKAGE__->belongs_to( Link Here
260
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2024-10-24 16:23:05
260
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2024-10-24 16:23:05
261
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:kTR2kwiwY2PnjU1E0P+CMQ
261
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:kTR2kwiwY2PnjU1E0P+CMQ
262
262
263
__PACKAGE__->has_many(
264
    "additional_field_values",
265
    "Koha::Schema::Result::AdditionalFieldValue",
266
    sub {
267
        my ($args) = @_;
268
        return {
269
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.booking_id" },
270
            "$args->{foreign_alias}.field_id"  =>
271
                { -in => \'(SELECT id FROM additional_fields WHERE tablename="bookings")' },
272
        };
273
    },
274
    { cascade_copy => 0, cascade_delete => 0 },
275
);
276
277
__PACKAGE__->has_many(
278
    "extended_attributes",
279
    "Koha::Schema::Result::AdditionalFieldValue",
280
    sub {
281
        my ($args) = @_;
282
        return {
283
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.booking_id" },
284
            "$args->{foreign_alias}.field_id"  =>
285
                { -in => \'(SELECT id FROM additional_fields WHERE tablename="bookings")' },
286
        };
287
    },
288
    { cascade_copy => 0, cascade_delete => 0 },
289
);
263
290
264
# You can replace this text with custom code or comments, and it will be preserved on regeneration
291
# You can replace this text with custom code or comments, and it will be preserved on regeneration
265
1;
292
1;
266
- 

Return to bug 37829