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

(-)a/Koha/AdditionalField.pm (-1 / +2 lines)
Lines 65-71 sub to_api { Link Here
65
        'aqorders'              => 'order',
65
        'aqorders'              => 'order',
66
        'aqbooksellers:vendor'  => 'vendor',
66
        'aqbooksellers:vendor'  => 'vendor',
67
        'erm_titles'            => 'title',
67
        'erm_titles'            => 'title',
68
        'erm_agreement_periods' => 'agreement_period'
68
        'erm_agreement_periods' => 'agreement_period',
69
        'bookings'            => 'booking',
69
    };
70
    };
70
71
71
    my $json = $self->SUPER::to_api($params);
72
    my $json = $self->SUPER::to_api($params);
(-)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 (+12 lines)
Lines 76-81 sub add { Link Here
76
76
77
    return try {
77
    return try {
78
        my $body = $c->req->json;
78
        my $body = $c->req->json;
79
        my $extended_attributes = delete $body->{extended_attributes} // [];
79
80
80
        # Validate that exactly one of item_id or itemtype_id is provided
81
        # Validate that exactly one of item_id or itemtype_id is provided
81
        my $has_item_id     = defined $body->{item_id};
82
        my $has_item_id     = defined $body->{item_id};
Lines 106-112 sub add { Link Here
106
        }
107
        }
107
108
108
        $booking->store;
109
        $booking->store;
110
111
        my @extended_attributes = map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes};
112
        $booking->extended_attributes( \@extended_attributes );
113
109
        $booking->discard_changes;
114
        $booking->discard_changes;
115
110
        $c->res->headers->location( $c->req->url->to_string . '/' . $booking->booking_id );
116
        $c->res->headers->location( $c->req->url->to_string . '/' . $booking->booking_id );
111
        return $c->render(
117
        return $c->render(
112
            status  => 201,
118
            status  => 201,
Lines 147-152 sub update { Link Here
147
153
148
    return try {
154
    return try {
149
        my $body = $c->req->json;
155
        my $body = $c->req->json;
156
        my $extended_attributes = delete $body->{extended_attributes} // [];
150
157
151
        # Extract and remove itemtype_id from body (it's not a database column)
158
        # Extract and remove itemtype_id from body (it's not a database column)
152
        my $itemtype_id = delete $body->{itemtype_id};
159
        my $itemtype_id = delete $body->{itemtype_id};
Lines 159-165 sub update { Link Here
159
        }
166
        }
160
167
161
        $booking->store();
168
        $booking->store();
169
170
        my @extended_attributes = map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes};
171
        $booking->extended_attributes( \@extended_attributes );
172
162
        $booking->discard_changes;
173
        $booking->discard_changes;
174
163
        return $c->render( status => 200, openapi => $c->objects->to_api($booking) );
175
        return $c->render( status => 200, openapi => $c->objects->to_api($booking) );
164
    } catch {
176
    } catch {
165
        $c->unhandled_exception($_);
177
        $c->unhandled_exception($_);
(-)a/Koha/REST/V1/ExtendedAttributeTypes.pm (-1 / +2 lines)
Lines 54-60 sub _list { Link Here
54
        order            => 'aqorders',
54
        order            => 'aqorders',
55
        vendor           => 'aqbooksellers:vendor',
55
        vendor           => 'aqbooksellers:vendor',
56
        title            => 'erm_titles',
56
        title            => 'erm_titles',
57
        agreement_period => 'erm_agreement_periods'
57
        agreement_period => 'erm_agreement_periods',
58
        booking   => 'bookings',
58
    };
59
    };
59
60
60
    my @tables;
61
    my @tables;
(-)a/Koha/Schema/Result/Booking.pm (-1 / +27 lines)
Lines 290-295 __PACKAGE__->belongs_to( Link Here
290
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-09-05 20:52:03
290
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-09-05 20:52:03
291
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:MzP+qYbMutu0qNgndBHHFQ
291
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:MzP+qYbMutu0qNgndBHHFQ
292
292
293
__PACKAGE__->has_many(
294
    "additional_field_values",
295
    "Koha::Schema::Result::AdditionalFieldValue",
296
    sub {
297
        my ($args) = @_;
298
        return {
299
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.booking_id" },
300
            "$args->{foreign_alias}.field_id"  =>
301
                { -in => \'(SELECT id FROM additional_fields WHERE tablename="bookings")' },
302
        };
303
    },
304
    { cascade_copy => 0, cascade_delete => 0 },
305
);
306
307
__PACKAGE__->has_many(
308
    "extended_attributes",
309
    "Koha::Schema::Result::AdditionalFieldValue",
310
    sub {
311
        my ($args) = @_;
312
        return {
313
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.booking_id" },
314
            "$args->{foreign_alias}.field_id"  =>
315
                { -in => \'(SELECT id FROM additional_fields WHERE tablename="bookings")' },
316
        };
317
    },
318
    { cascade_copy => 0, cascade_delete => 0 },
319
);
293
320
294
# You can replace this text with custom code or comments, and it will be preserved on regeneration
321
# You can replace this text with custom code or comments, and it will be preserved on regeneration
295
1;
322
1;
296
- 

Return to bug 37829