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

(-)a/Koha/Illbatch.pm (-39 / +48 lines)
Lines 18-26 package Koha::Illbatch; Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
use Koha::Database;
22
use Koha::Database;
23
24
use Koha::Illrequests;
22
use Koha::Illrequest::Logger;
25
use Koha::Illrequest::Logger;
23
use Koha::IllbatchStatus;
26
use Koha::IllbatchStatuses;
27
use Koha::Libraries;
28
use Koha::Patrons;
29
24
use JSON qw( to_json );
30
use JSON qw( to_json );
25
use base qw(Koha::Object);
31
use base qw(Koha::Object);
26
32
Lines 40-74 Return the status object associated with this batch Link Here
40
46
41
sub status {
47
sub status {
42
    my ($self) = @_;
48
    my ($self) = @_;
43
    return Koha::IllbatchStatus->_new_from_dbic( scalar $self->_result->statuscode );
49
    return Koha::IllbatchStatus->_new_from_dbic( scalar $self->_result->status_code );
44
}
50
}
45
51
46
=head3 patron
52
=head3 patron
47
53
48
    my $patron = Koha::Illbatch->patron;
54
    my $patron = Koha::Illbatch->patron;
49
55
50
Return the patron object associated with this batch
56
Return the I<Koha::Patron> object associated with this batch
51
57
52
=cut
58
=cut
53
59
54
sub patron {
60
sub patron {
55
    my ($self) = @_;
61
    my ($self) = @_;
56
    my $patron = return Koha::Patrons->find( { borrowernumber => $self->borrowernumber } );
62
    my $patron = $self->_result->patron;
57
    return unless $patron;
63
    return unless $patron;
64
    return Koha::Patron->_new_from_dbic($patron);
58
}
65
}
59
66
60
=head3 branch
67
=head3 library
61
68
62
    my $branch = Koha::Illbatch->branch;
69
    my $library = Koha::Illbatch->library;
63
70
64
Return the branch object associated with this batch
71
Return the I<Koha::Library> object associated with this batch
65
72
66
=cut
73
=cut
67
74
68
sub branch {
75
sub library {
69
    my ($self) = @_;
76
    my ($self) = @_;
70
    my $library = return Koha::Libraries->find( { branchcode => $self->branchcode } );
77
    my $library = $self->_result->library;
71
    return unless $library;
78
    return unless $library;
79
    return Koha::Library->_new_from_dbic($library);
72
}
80
}
73
81
74
=head3 requests_count
82
=head3 requests_count
Lines 86-98 sub requests_count { Link Here
86
94
87
=head3 requests
95
=head3 requests
88
96
89
Return the requests for this batch
97
Return the I<Koha::Illrequests> for this batch
90
98
91
=cut
99
=cut
92
100
93
sub requests {
101
sub requests {
94
    my ($self) = @_;
102
    my ($self) = @_;
95
    my $requests = $self->_result->illrequests;
103
    my $requests = $self->_result->requests;
96
    return Koha::Illrequests->_new_from_dbic($requests);
104
    return Koha::Illrequests->_new_from_dbic($requests);
97
}
105
}
98
106
Lines 134-140 sub update_and_log { Link Here
134
142
135
    my $before = {
143
    my $before = {
136
        name       => $self->name,
144
        name       => $self->name,
137
        branchcode => $self->branchcode
145
        library_id => $self->library_id,
138
    };
146
    };
139
147
140
    $self->set($params);
148
    $self->set($params);
Lines 142-148 sub update_and_log { Link Here
142
150
143
    my $after = {
151
    my $after = {
144
        name       => $self->name,
152
        name       => $self->name,
145
        branchcode => $self->branchcode
153
        library_id => $self->library_id,
146
    };
154
    };
147
155
148
    my $logger = Koha::Illrequest::Logger->new;
156
    my $logger = Koha::Illrequest::Logger->new;
Lines 192-197 sub delete_and_log { Link Here
192
200
193
=head3 strings_map
201
=head3 strings_map
194
202
203
Returns a map of column name to string representations including the string,
204
the mapping type and the mapping category where appropriate.
205
206
Currently handles library and ILL batch status expansions.
207
expansions.
208
209
Accepts a param hashref where the I<public> key denotes whether we want the public
210
or staff client strings.
211
212
Note: the I<public> parameter is not currently used.
213
195
=cut
214
=cut
196
215
197
sub strings_map {
216
sub strings_map {
Lines 199-239 sub strings_map { Link Here
199
218
200
    my $strings = {};
219
    my $strings = {};
201
220
202
    if ( defined $self->statuscode ) {
221
    if ( defined $self->status_code ) {
203
        my $ill_batch_status = Koha::IllbatchStatuses->search( { code => $self->statuscode } );
222
        my $status = $self->status;
204
        my $ill_batch_status_str =
205
            $ill_batch_status->count
206
                ? $ill_batch_status->next->name
207
        : $self->statuscode;
208
223
209
        $strings->{status} = {
224
        if ( $status ) {
210
            name => $ill_batch_status_str,
225
            $strings->{status_code} = {
211
        };
226
                str  => $status->name,
227
                type => 'ill_batch_status',
228
            };
229
        }
212
    }
230
    }
213
231
214
    if ( defined $self->branchcode ) {
232
    if ( defined $self->library_id ) {
215
        my $ill_batch_branch = Koha::Libraries->find( $self->branchcode );
233
        my $library = $self->library;
216
        my $ill_batch_branchname_str = $ill_batch_branch ? $ill_batch_branch->branchname : $self->branchcode;
217
234
218
        $strings->{branchname} = $ill_batch_branchname_str;
235
        if ($library) {
236
            $strings->{library_id} = {
237
                str  => $library->branchname,
238
                type => 'library',
239
            };
240
        }
219
    }
241
    }
220
242
221
    return $strings;
243
    return $strings;
222
}
244
}
223
245
224
=head3 to_api_mapping
225
226
=cut
227
228
sub to_api_mapping {
229
    return {
230
        id             => 'batch_id',
231
        branchcode     => 'library_id',
232
        borrowernumber => 'patron_id',
233
        status         => 'batch_status',
234
    };
235
}
236
237
=head3 _type
246
=head3 _type
238
247
239
    my $type = Koha::Illbatch->_type;
248
    my $type = Koha::Illbatch->_type;
(-)a/Koha/REST/V1/Illbatches.pm (-10 / +9 lines)
Lines 41-52 sub list { Link Here
41
    my $c = shift->openapi->valid_input or return;
41
    my $c = shift->openapi->valid_input or return;
42
42
43
    return try {
43
    return try {
44
        my $illbatches = $c->objects->search( Koha::Illbatches->new );
44
        return $c->render(
45
        return $c->render( status => 200, openapi => $illbatches );
45
            status  => 200,
46
            openapi => $c->objects->search( Koha::Illbatches->new )
47
        );
46
    } catch {
48
    } catch {
49
        warn "$_";
47
        $c->unhandled_exception($_);
50
        $c->unhandled_exception($_);
48
    };
51
    };
49
50
}
52
}
51
53
52
=head3 get
54
=head3 get
Lines 59-65 sub get { Link Here
59
    my $c = shift->openapi->valid_input or return;
61
    my $c = shift->openapi->valid_input or return;
60
62
61
    return try {
63
    return try {
62
        my $ill_batch = $c->objects->find( Koha::Illbatches->search, $c->param('ill_batch_id') );
64
        my $ill_batch = $c->objects->find( Koha::Illbatches->new, $c->param('ill_batch_id') );
63
65
64
        unless ($ill_batch) {
66
        unless ($ill_batch) {
65
            return $c->render(
67
            return $c->render(
Lines 98-105 sub add { Link Here
98
    }
100
    }
99
101
100
    delete $body->{cardnumber};
102
    delete $body->{cardnumber};
101
    $body->{borrowernumber} = $patron->borrowernumber;
103
    $body->{patron_id} = $patron->id;
102
    $body->{branchcode}     = delete $body->{library_id};
103
104
104
    return try {
105
    return try {
105
        my $batch = Koha::Illbatch->new_from_api($body);
106
        my $batch = Koha::Illbatch->new_from_api($body);
Lines 107-113 sub add { Link Here
107
108
108
        $c->res->headers->location( $c->req->url->to_string . '/' . $batch->id );
109
        $c->res->headers->location( $c->req->url->to_string . '/' . $batch->id );
109
110
110
        my $ill_batch = $c->objects->find( Koha::Illbatches->search, $batch->id );
111
        my $ill_batch = $c->objects->find( Koha::Illbatches->new, $batch->id );
111
112
112
        return $c->render(
113
        return $c->render(
113
            status  => 201,
114
            status  => 201,
Lines 146-160 sub update { Link Here
146
147
147
    my $params = $c->req->json;
148
    my $params = $c->req->json;
148
    delete $params->{cardnumber};
149
    delete $params->{cardnumber};
149
    $params->{borrowernumber} = delete $params->{patron_id}  if $params->{patron_id};
150
    $params->{branchcode}     = delete $params->{library_id} if $params->{library_id};
151
150
152
    return try {
151
    return try {
153
        $batch->update_and_log($params);
152
        $batch->update_and_log($params);
154
153
155
        return $c->render(
154
        return $c->render(
156
            status  => 200,
155
            status  => 200,
157
            openapi => $batch->to_api
156
            openapi => $c->objects->to_api($batch),
158
        );
157
        );
159
    } catch {
158
    } catch {
160
        $c->unhandled_exception($_);
159
        $c->unhandled_exception($_);
(-)a/Koha/Schema/Result/Borrower.pm (-3 / +3 lines)
Lines 1413-1419 Related object: L<Koha::Schema::Result::Illbatch> Link Here
1413
__PACKAGE__->has_many(
1413
__PACKAGE__->has_many(
1414
  "illbatches",
1414
  "illbatches",
1415
  "Koha::Schema::Result::Illbatch",
1415
  "Koha::Schema::Result::Illbatch",
1416
  { "foreign.borrowernumber" => "self.borrowernumber" },
1416
  { "foreign.patron_id" => "self.borrowernumber" },
1417
  { cascade_copy => 0, cascade_delete => 0 },
1417
  { cascade_copy => 0, cascade_delete => 0 },
1418
);
1418
);
1419
1419
Lines 2118-2125 Composing rels: L</user_permissions> -> permission Link Here
2118
__PACKAGE__->many_to_many("permissions", "user_permissions", "permission");
2118
__PACKAGE__->many_to_many("permissions", "user_permissions", "permission");
2119
2119
2120
2120
2121
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-04-28 11:24:21
2121
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-10-10 14:16:46
2122
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RUWvcq9kgQvACo14H/u9jQ
2122
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nIMnqyBVBam7NvIx4aDfHw
2123
2123
2124
__PACKAGE__->has_many(
2124
__PACKAGE__->has_many(
2125
  "restrictions",
2125
  "restrictions",
(-)a/Koha/Schema/Result/Branch.pm (-3 / +3 lines)
Lines 703-709 Related object: L<Koha::Schema::Result::Illbatch> Link Here
703
__PACKAGE__->has_many(
703
__PACKAGE__->has_many(
704
  "illbatches",
704
  "illbatches",
705
  "Koha::Schema::Result::Illbatch",
705
  "Koha::Schema::Result::Illbatch",
706
  { "foreign.branchcode" => "self.branchcode" },
706
  { "foreign.library_id" => "self.branchcode" },
707
  { cascade_copy => 0, cascade_delete => 0 },
707
  { cascade_copy => 0, cascade_delete => 0 },
708
);
708
);
709
709
Lines 933-940 __PACKAGE__->has_many( Link Here
933
);
933
);
934
934
935
935
936
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-04-28 11:24:21
936
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-10-10 14:16:46
937
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:GGYhqyTVMmaFo9hAY4Jy5w
937
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LjdauIP6C1I1/1liCIddJQ
938
938
939
__PACKAGE__->add_columns(
939
__PACKAGE__->add_columns(
940
    '+pickup_location' => { is_boolean => 1 },
940
    '+pickup_location' => { is_boolean => 1 },
(-)a/Koha/Schema/Result/Illbatch.pm (-39 / +46 lines)
Lines 23-29 __PACKAGE__->table("illbatches"); Link Here
23
23
24
=head1 ACCESSORS
24
=head1 ACCESSORS
25
25
26
=head2 id
26
=head2 ill_batch_id
27
27
28
  data_type: 'integer'
28
  data_type: 'integer'
29
  is_auto_increment: 1
29
  is_auto_increment: 1
Lines 47-53 Unique name of batch Link Here
47
47
48
Name of batch backend
48
Name of batch backend
49
49
50
=head2 borrowernumber
50
=head2 patron_id
51
51
52
  data_type: 'integer'
52
  data_type: 'integer'
53
  is_foreign_key: 1
53
  is_foreign_key: 1
Lines 55-61 Name of batch backend Link Here
55
55
56
Patron associated with batch
56
Patron associated with batch
57
57
58
=head2 branchcode
58
=head2 library_id
59
59
60
  data_type: 'varchar'
60
  data_type: 'varchar'
61
  is_foreign_key: 1
61
  is_foreign_key: 1
Lines 64-70 Patron associated with batch Link Here
64
64
65
Branch associated with batch
65
Branch associated with batch
66
66
67
=head2 statuscode
67
=head2 status_code
68
68
69
  data_type: 'varchar'
69
  data_type: 'varchar'
70
  is_foreign_key: 1
70
  is_foreign_key: 1
Lines 76-92 Status of batch Link Here
76
=cut
76
=cut
77
77
78
__PACKAGE__->add_columns(
78
__PACKAGE__->add_columns(
79
  "id",
79
  "ill_batch_id",
80
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
80
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
81
  "name",
81
  "name",
82
  { data_type => "varchar", is_nullable => 0, size => 100 },
82
  { data_type => "varchar", is_nullable => 0, size => 100 },
83
  "backend",
83
  "backend",
84
  { data_type => "varchar", is_nullable => 0, size => 20 },
84
  { data_type => "varchar", is_nullable => 0, size => 20 },
85
  "borrowernumber",
85
  "patron_id",
86
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
86
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
87
  "branchcode",
87
  "library_id",
88
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 50 },
88
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 50 },
89
  "statuscode",
89
  "status_code",
90
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 20 },
90
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 20 },
91
);
91
);
92
92
Lines 94-106 __PACKAGE__->add_columns( Link Here
94
94
95
=over 4
95
=over 4
96
96
97
=item * L</id>
97
=item * L</ill_batch_id>
98
98
99
=back
99
=back
100
100
101
=cut
101
=cut
102
102
103
__PACKAGE__->set_primary_key("id");
103
__PACKAGE__->set_primary_key("ill_batch_id");
104
104
105
=head1 UNIQUE CONSTRAINTS
105
=head1 UNIQUE CONSTRAINTS
106
106
Lines 118-144 __PACKAGE__->add_unique_constraint("u_illbatches__name", ["name"]); Link Here
118
118
119
=head1 RELATIONS
119
=head1 RELATIONS
120
120
121
=head2 borrowernumber
121
=head2 illrequests
122
122
123
Type: belongs_to
123
Type: has_many
124
124
125
Related object: L<Koha::Schema::Result::Borrower>
125
Related object: L<Koha::Schema::Result::Illrequest>
126
126
127
=cut
127
=cut
128
128
129
__PACKAGE__->belongs_to(
129
__PACKAGE__->has_many(
130
  "borrowernumber",
130
  "illrequests",
131
  "Koha::Schema::Result::Borrower",
131
  "Koha::Schema::Result::Illrequest",
132
  { borrowernumber => "borrowernumber" },
132
  { "foreign.batch_id" => "self.ill_batch_id" },
133
  {
133
  { cascade_copy => 0, cascade_delete => 0 },
134
    is_deferrable => 1,
135
    join_type     => "LEFT",
136
    on_delete     => "SET NULL",
137
    on_update     => "CASCADE",
138
  },
139
);
134
);
140
135
141
=head2 branchcode
136
=head2 library
142
137
143
Type: belongs_to
138
Type: belongs_to
144
139
Lines 147-155 Related object: L<Koha::Schema::Result::Branch> Link Here
147
=cut
142
=cut
148
143
149
__PACKAGE__->belongs_to(
144
__PACKAGE__->belongs_to(
150
  "branchcode",
145
  "library",
151
  "Koha::Schema::Result::Branch",
146
  "Koha::Schema::Result::Branch",
152
  { branchcode => "branchcode" },
147
  { branchcode => "library_id" },
153
  {
148
  {
154
    is_deferrable => 1,
149
    is_deferrable => 1,
155
    join_type     => "LEFT",
150
    join_type     => "LEFT",
Lines 158-179 __PACKAGE__->belongs_to( Link Here
158
  },
153
  },
159
);
154
);
160
155
161
=head2 illrequests
156
=head2 patron
162
157
163
Type: has_many
158
Type: belongs_to
164
159
165
Related object: L<Koha::Schema::Result::Illrequest>
160
Related object: L<Koha::Schema::Result::Borrower>
166
161
167
=cut
162
=cut
168
163
169
__PACKAGE__->has_many(
164
__PACKAGE__->belongs_to(
170
  "illrequests",
165
  "patron",
171
  "Koha::Schema::Result::Illrequest",
166
  "Koha::Schema::Result::Borrower",
172
  { "foreign.batch_id" => "self.id" },
167
  { borrowernumber => "patron_id" },
173
  { cascade_copy => 0, cascade_delete => 0 },
168
  {
169
    is_deferrable => 1,
170
    join_type     => "LEFT",
171
    on_delete     => "SET NULL",
172
    on_update     => "CASCADE",
173
  },
174
);
174
);
175
175
176
=head2 statuscode
176
=head2 status_code
177
177
178
Type: belongs_to
178
Type: belongs_to
179
179
Lines 182-190 Related object: L<Koha::Schema::Result::IllbatchStatus> Link Here
182
=cut
182
=cut
183
183
184
__PACKAGE__->belongs_to(
184
__PACKAGE__->belongs_to(
185
  "statuscode",
185
  "status_code",
186
  "Koha::Schema::Result::IllbatchStatus",
186
  "Koha::Schema::Result::IllbatchStatus",
187
  { code => "statuscode" },
187
  { code => "status_code" },
188
  {
188
  {
189
    is_deferrable => 1,
189
    is_deferrable => 1,
190
    join_type     => "LEFT",
190
    join_type     => "LEFT",
Lines 194-201 __PACKAGE__->belongs_to( Link Here
194
);
194
);
195
195
196
196
197
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-09-08 13:49:29
197
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-10-10 18:12:30
198
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YKxQxJMKxdBP9X4+i0Rfzw
198
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:81afdstzxyW2hhIx6mu4KA
199
200
__PACKAGE__->has_many(
201
  "requests",
202
  "Koha::Schema::Result::Illrequest",
203
  { "foreign.batch_id" => "self.ill_batch_id" },
204
  { cascade_copy => 0, cascade_delete => 0 },
205
);
199
206
200
sub koha_object_class {
207
sub koha_object_class {
201
    'Koha::Illbatch';
208
    'Koha::Illbatch';
(-)a/Koha/Schema/Result/IllbatchStatus.pm (-3 / +3 lines)
Lines 106-118 Related object: L<Koha::Schema::Result::Illbatch> Link Here
106
__PACKAGE__->has_many(
106
__PACKAGE__->has_many(
107
  "illbatches",
107
  "illbatches",
108
  "Koha::Schema::Result::Illbatch",
108
  "Koha::Schema::Result::Illbatch",
109
  { "foreign.statuscode" => "self.code" },
109
  { "foreign.status_code" => "self.code" },
110
  { cascade_copy => 0, cascade_delete => 0 },
110
  { cascade_copy => 0, cascade_delete => 0 },
111
);
111
);
112
112
113
113
114
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-09-08 13:49:29
114
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-10-10 18:12:30
115
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yo60FJ+kyRj8QuEMac8CFA
115
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sRgblQWtTH/cdtdMT3KP+w
116
116
117
__PACKAGE__->add_columns(
117
__PACKAGE__->add_columns(
118
    '+is_system' => { is_boolean => 1 },
118
    '+is_system' => { is_boolean => 1 },
(-)a/Koha/Schema/Result/Illrequest.pm (-3 / +3 lines)
Lines 276-282 Related object: L<Koha::Schema::Result::Illbatch> Link Here
276
__PACKAGE__->belongs_to(
276
__PACKAGE__->belongs_to(
277
  "batch",
277
  "batch",
278
  "Koha::Schema::Result::Illbatch",
278
  "Koha::Schema::Result::Illbatch",
279
  { id => "batch_id" },
279
  { ill_batch_id => "batch_id" },
280
  {
280
  {
281
    is_deferrable => 1,
281
    is_deferrable => 1,
282
    join_type     => "LEFT",
282
    join_type     => "LEFT",
Lines 391-398 __PACKAGE__->belongs_to( Link Here
391
);
391
);
392
392
393
393
394
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-09-08 13:51:09
394
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-10-10 14:49:40
395
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:QS3E1jO/d797B0ADcjT0yQ
395
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:DQl+7uwLCz5GeqU2hBFmMA
396
396
397
__PACKAGE__->has_many(
397
__PACKAGE__->has_many(
398
  "comments",
398
  "comments",
(-)a/api/v1/swagger/definitions/ill_batch.yaml (-15 / +22 lines)
Lines 1-8 Link Here
1
---
1
---
2
type: object
2
type: object
3
properties:
3
properties:
4
  batch_id:
4
  ill_batch_id:
5
    type: string
5
    type: integer
6
    description: Internal ILL batch identifier
6
    description: Internal ILL batch identifier
7
  name:
7
  name:
8
    type: string
8
    type: string
Lines 12-45 properties: Link Here
12
    description: Backend name
12
    description: Backend name
13
  cardnumber:
13
  cardnumber:
14
    type: string
14
    type: string
15
    description: Card number of the patron of the ILL batch
15
    description: Library assigned user identifier of the ILL batch
16
  patron_id:
16
  patron_id:
17
    type: string
17
    type: string
18
    description: Borrower number of the patron of the ILL batch
18
    description: Internal identifier the patron of the ILL batch
19
  library_id:
19
  library_id:
20
    type: string
20
    type: string
21
    description: Branch code of the branch of the ILL batch
21
    description: Internal identifier for the ILL batch's library
22
  status_code:
23
    type: string
24
    description: Code of the status of the ILL batch
22
  patron:
25
  patron:
23
    type:
26
    type:
24
      - object
27
      - object
25
      - "null"
28
      - "null"
26
    description: The patron associated with the batch
29
    description: The patron associated with the batch
27
  branch:
30
  library:
28
    type:
31
    type:
29
      - object
32
      - object
30
      - "null"
33
      - "null"
31
    description: The branch associated with the batch
34
    description: The library associated with the batch
32
  statuscode:
35
  requests:
33
    type: string
36
    type:
34
    description: Code of the status of the ILL batch
37
      - array
38
      - "null"
39
    description: The requests in this batch (x-koha-embed)
40
  requests_count:
41
    type:
42
      - integer
43
      - "null"
44
    description: The number of requests in this batch (x-koha-embed)  
35
  status:
45
  status:
36
    type:
46
    type:
37
      - object
47
      - object
38
      - "null"
48
      - "null"
39
    description: The status associated with the batch
49
    description: The status associated with the batch (x-koha-embed)
40
  requests_count:
41
    type: string
42
    description: The number of requests in this batch
43
  _strings:
50
  _strings:
44
    type:
51
    type:
45
      - object
52
      - object
Lines 50-53 required: Link Here
50
  - name
57
  - name
51
  - backend
58
  - backend
52
  - library_id
59
  - library_id
53
  - statuscode
60
  - status_code
(-)a/api/v1/swagger/paths/ill_batches.yaml (-3 / +6 lines)
Lines 23-31 Link Here
23
          type: string
23
          type: string
24
          enum:
24
          enum:
25
            - +strings
25
            - +strings
26
            - requests
26
            - requests+count
27
            - requests+count
27
            - patron
28
            - patron
28
            - branch
29
            - library
29
        collectionFormat: csv
30
        collectionFormat: csv
30
    produces:
31
    produces:
31
      - application/json
32
      - application/json
Lines 82-90 Link Here
82
          type: string
83
          type: string
83
          enum:
84
          enum:
84
            - +strings
85
            - +strings
86
            - requests
85
            - requests+count
87
            - requests+count
86
            - patron
88
            - patron
87
            - branch
89
            - library
88
        collectionFormat: csv
90
        collectionFormat: csv
89
    produces:
91
    produces:
90
      - application/json
92
      - application/json
Lines 156-164 Link Here
156
          type: string
158
          type: string
157
          enum:
159
          enum:
158
            - +strings
160
            - +strings
161
            - requests
159
            - requests+count
162
            - requests+count
160
            - patron
163
            - patron
161
            - branch
164
            - library
162
        collectionFormat: csv
165
        collectionFormat: csv
163
    produces:
166
    produces:
164
      - application/json
167
      - application/json
(-)a/installer/data/mysql/kohastructure.sql (-9 / +9 lines)
Lines 3319-3335 CREATE TABLE `illbatch_statuses` ( Link Here
3319
--
3319
--
3320
DROP TABLE IF EXISTS `illbatches`;
3320
DROP TABLE IF EXISTS `illbatches`;
3321
CREATE TABLE `illbatches` (
3321
CREATE TABLE `illbatches` (
3322
    `id` int(11) NOT NULL auto_increment COMMENT "Batch ID",
3322
    `ill_batch_id` int(11) NOT NULL auto_increment COMMENT "Batch ID",
3323
    `name` varchar(100) NOT NULL COMMENT "Unique name of batch",
3323
    `name` varchar(100) NOT NULL COMMENT "Unique name of batch",
3324
    `backend` varchar(20) NOT NULL COMMENT "Name of batch backend",
3324
    `backend` varchar(20) NOT NULL COMMENT "Name of batch backend",
3325
    `borrowernumber` int(11) COMMENT "Patron associated with batch",
3325
    `patron_id` int(11) NULL DEFAULT NULL COMMENT "Patron associated with batch",
3326
    `branchcode` varchar(50) COMMENT "Branch associated with batch",
3326
    `library_id` varchar(50) NULL DEFAULT NULL COMMENT "Branch associated with batch",
3327
    `statuscode` varchar(20) COMMENT "Status of batch",
3327
    `status_code` varchar(20) NULL DEFAULT NULL COMMENT "Status of batch",
3328
    PRIMARY KEY (`id`),
3328
    PRIMARY KEY (`ill_batch_id`),
3329
    UNIQUE KEY `u_illbatches__name` (`name`),
3329
    UNIQUE KEY `u_illbatches__name` (`name`),
3330
    CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3330
    CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`patron_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3331
    CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
3331
    CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`library_id`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
3332
    CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
3332
    CONSTRAINT `illbatches_sfk` FOREIGN KEY (`status_code`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
3333
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3333
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3334
3334
3335
--
3335
--
Lines 3370-3376 CREATE TABLE `illrequests` ( Link Here
3370
  CONSTRAINT `illrequests_bibfk` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3370
  CONSTRAINT `illrequests_bibfk` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3371
  CONSTRAINT `illrequests_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3371
  CONSTRAINT `illrequests_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3372
  CONSTRAINT `illrequests_safk` FOREIGN KEY (`status_alias`) REFERENCES `authorised_values` (`authorised_value`) ON DELETE SET NULL ON UPDATE CASCADE,
3372
  CONSTRAINT `illrequests_safk` FOREIGN KEY (`status_alias`) REFERENCES `authorised_values` (`authorised_value`) ON DELETE SET NULL ON UPDATE CASCADE,
3373
  CONSTRAINT `illrequests_ibfk` FOREIGN KEY (`batch_id`) REFERENCES `illbatches` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
3373
  CONSTRAINT `illrequests_ibfk` FOREIGN KEY (`batch_id`) REFERENCES `illbatches` (`ill_batch_id`) ON DELETE SET NULL ON UPDATE CASCADE
3374
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3374
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3375
/*!40101 SET character_set_client = @saved_cs_client */;
3375
/*!40101 SET character_set_client = @saved_cs_client */;
3376
3376
(-)a/t/db_dependent/IllbatchStatuses.t (-5 / +5 lines)
Lines 193-203 my $status5 = Koha::IllbatchStatus->new( Link Here
193
$status5->create_and_log;
193
$status5->create_and_log;
194
my $batch = Koha::Illbatch->new(
194
my $batch = Koha::Illbatch->new(
195
    {
195
    {
196
        name           => "My test batch",
196
        name       => "My test batch",
197
        borrowernumber => $patron->borrowernumber,
197
        patron_id  => $patron->borrowernumber,
198
        branchcode     => $library->branchcode,
198
        library_id => $library->branchcode,
199
        backend        => "TEST",
199
        backend    => "TEST",
200
        statuscode     => $status5->code
200
        statuscode => $status5->code
201
    }
201
    }
202
);
202
);
203
$batch->create_and_log;
203
$batch->create_and_log;
(-)a/t/db_dependent/Illbatches.t (-14 / +11 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use File::Basename qw/basename/;
21
use Koha::Database;
20
use Koha::Database;
22
use Koha::Illbatch;
21
use Koha::Illbatch;
23
use Koha::Illbatches;
22
use Koha::Illbatches;
Lines 28-34 use t::lib::TestBuilder; Link Here
28
use Test::MockObject;
27
use Test::MockObject;
29
use Test::MockModule;
28
use Test::MockModule;
30
29
31
use Test::More tests => 8;
30
use Test::More tests => 7;
32
31
33
my $schema  = Koha::Database->new->schema;
32
my $schema  = Koha::Database->new->schema;
34
my $builder = t::lib::TestBuilder->new;
33
my $builder = t::lib::TestBuilder->new;
Lines 54-72 my $librarian = $builder->build( Link Here
54
my $branch = $builder->build( { source => 'Branch' } );
53
my $branch = $builder->build( { source => 'Branch' } );
55
54
56
# Create a batch
55
# Create a batch
57
my $illbatch = $builder->build(
56
my $illbatch = $builder->build_object(
58
    {
57
    {
59
        source => 'Illbatch',
58
        class => 'Koha::Illbatches',
60
        value  => {
59
        value  => {
61
            name           => "My test batch",
60
            name       => "My test batch",
62
            backend        => "Mock",
61
            backend    => "Mock",
63
            borrowernumber => $librarian->{borrowernumber},
62
            patron_id  => $librarian->{borrowernumber},
64
            branchcode     => $branch->{branchcode}
63
            library_id => $branch->{branchcode}
65
        }
64
        }
66
    }
65
    }
67
);
66
);
68
my $batch_obj = Koha::Illbatches->find( $illbatch->{id} );
69
isa_ok( $batch_obj, 'Koha::Illbatch' );
70
67
71
# Create an ILL request in the batch
68
# Create an ILL request in the batch
72
my $illrq = $builder->build(
69
my $illrq = $builder->build(
Lines 74-96 my $illrq = $builder->build( Link Here
74
        source => 'Illrequest',
71
        source => 'Illrequest',
75
        value  => {
72
        value  => {
76
            borrowernumber => $patron->{borrowernumber},
73
            borrowernumber => $patron->{borrowernumber},
77
            batch_id       => $illbatch->{id}
74
            batch_id       => $illbatch->id
78
        }
75
        }
79
    }
76
    }
80
);
77
);
81
my $illrq_obj = Koha::Illrequests->find( $illrq->{illrequest_id} );
78
my $illrq_obj = Koha::Illrequests->find( $illrq->{illrequest_id} );
82
79
83
# Check requests_count
80
# Check requests_count
84
my $requests_count = $batch_obj->requests_count;
81
my $requests_count = $illbatch->requests_count;
85
is( $requests_count, 1, 'requests_count returns correctly' );
82
is( $requests_count, 1, 'requests_count returns correctly' );
86
83
87
# Check patron
84
# Check patron
88
my $batch_patron = $batch_obj->patron;
85
my $batch_patron = $illbatch->patron;
89
isa_ok( $batch_patron, 'Koha::Patron' );
86
isa_ok( $batch_patron, 'Koha::Patron' );
90
is( $batch_patron->firstname, "Grogu", "patron returns correctly" );
87
is( $batch_patron->firstname, "Grogu", "patron returns correctly" );
91
88
92
# Check branch
89
# Check branch
93
my $batch_branch = $batch_obj->branch;
90
my $batch_branch = $illbatch->library;
94
isa_ok( $batch_branch, 'Koha::Library' );
91
isa_ok( $batch_branch, 'Koha::Library' );
95
is( $batch_branch->branchcode, $branch->{branchcode}, "branch returns correctly" );
92
is( $batch_branch->branchcode, $branch->{branchcode}, "branch returns correctly" );
96
93
(-)a/t/db_dependent/api/v1/ill_batches.t (-63 / +67 lines)
Lines 23-28 use Test::Mojo; Link Here
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
25
26
use JSON qw(encode_json);
27
26
use Koha::Illbatch;
28
use Koha::Illbatch;
27
use Koha::Illbatches;
29
use Koha::Illbatches;
28
use Koha::Illrequests;
30
use Koha::Illrequests;
Lines 37-48 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); Link Here
37
39
38
subtest 'list() tests' => sub {
40
subtest 'list() tests' => sub {
39
41
40
    plan tests => 19;
42
    plan tests => 21;
41
43
42
    $schema->storage->txn_begin;
44
    $schema->storage->txn_begin;
43
45
44
    Koha::Illbatches->search->delete;
45
46
    my $librarian = $builder->build_object(
46
    my $librarian = $builder->build_object(
47
        {
47
        {
48
            class => 'Koha::Patrons',
48
            class => 'Koha::Patrons',
Lines 52-106 subtest 'list() tests' => sub { Link Here
52
        }
52
        }
53
    );
53
    );
54
54
55
    my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
55
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
56
56
57
    my $password = 'sheev_is_da_boss!';
57
    my $password = 'sheev_is_da_boss!';
58
    $librarian->set_password( { password => $password, skip_validation => 1 } );
58
    $librarian->set_password( { password => $password, skip_validation => 1 } );
59
    my $userid = $librarian->userid;
59
    my $userid = $librarian->userid;
60
60
61
    my $batch_to_delete  = $builder->build_object( { class => 'Koha::Illbatches' } );
62
    my $deleted_batch_id = $batch_to_delete->id;
63
    $batch_to_delete->delete;
64
65
    my $query = { ill_batch_id => [$deleted_batch_id] };
66
61
    ## Authorized user tests
67
    ## Authorized user tests
62
    # No batches, so empty array should be returned
68
    # No batches, so empty array should be returned
63
    $t->get_ok("//$userid:$password@/api/v1/ill/batches")->status_is(200)->json_is( [] );
69
    $t->get_ok( "//$userid:$password@/api/v1/ill/batches?q=" . encode_json($query) )->status_is(200)->json_is( [] );
64
70
65
    my $batch = $builder->build_object(
71
    my $batch_1 = $builder->build_object(
66
        {
72
        {
67
            class => 'Koha::Illbatches',
73
            class => 'Koha::Illbatches',
68
            value => {
74
            value => {
69
                name           => "PapaPalpatine",
75
                backend    => "Mock",
70
                backend        => "Mock",
76
                patron_id  => $librarian->id,
71
                borrowernumber => $librarian->borrowernumber,
77
                library_id => $library->id,
72
                branchcode     => $branch->branchcode
73
            }
78
            }
74
        }
79
        }
75
    );
80
    );
76
81
77
    my $illrq = $builder->build(
82
    my $illrq = $builder->build_object(
78
        {
83
        {
79
            source => 'Illrequest',
84
            class => 'Koha::Illrequests',
80
            value  => {
85
            value => {
81
                borrowernumber => $librarian->borrowernumber,
86
                batch_id       => $batch_1->id,
82
                batch_id       => $batch->id
87
                borrowernumber => $librarian->id,
83
            }
88
            }
84
        }
89
        }
85
    );
90
    );
86
91
87
    # One batch created, should get returned
92
    $query = { ill_batch_id => [ $batch_1->id ] };
88
    $t->get_ok(
89
        "//$userid:$password@/api/v1/ill/batches" => { 'x-koha-embed' => '+strings,requests+count,patron,branch' } )
90
        ->status_is(200)->json_has( '/0/batch_id', 'Batch ID' )->json_has( '/0/name', 'Batch name' )
91
        ->json_has( '/0/backend',    'Backend name' )->json_has( '/0/patron_id', 'Borrowernumber' )
92
        ->json_has( '/0/library_id', 'Branchcode' )->json_has( '/0/patron', 'patron embedded' )
93
        ->json_has( '/0/branch',     'branch embedded' )->json_has( '/0/requests_count', 'request count' );
94
93
95
    # Try to create a second batch with the same name, this should fail
94
    # One batch created, should get returned
96
    my $another_batch = $builder->build_object( { class => 'Koha::Illbatches', value => { name => $batch->name } } );
95
    $t->get_ok( "//$userid:$password@/api/v1/ill/batches?q="
96
            . encode_json($query) => { 'x-koha-embed' => '+strings,requests+count,patron,library' } )->status_is(200)
97
        ->json_has( '/0/ill_batch_id', 'Batch ID' )->json_has( '/0/name', 'Batch name' )
98
        ->json_has( '/0/backend',      'Backend name' )->json_has( '/0/patron_id', 'Borrowernumber' )
99
        ->json_has( '/0/library_id',   'Branchcode' )->json_has( '/0/patron', 'patron embedded' )
100
        ->json_has( '/0/library',      'branch embedded' )->json_has( '/0/requests_count', 'request count' );
97
101
98
    # Create a second batch with a different name
102
    # Create a second batch with a different name
99
    my $batch_with_another_name = $builder->build_object( { class => 'Koha::Illbatches' } );
103
    my $batch_2 = $builder->build_object( { class => 'Koha::Illbatches' } );
104
105
    $query = { ill_batch_id => [ $batch_1->id, $batch_2->id ] };
100
106
101
    # Two batches created, they should both be returned
107
    # Two batches created, they should both be returned
102
    $t->get_ok("//$userid:$password@/api/v1/ill/batches")->status_is(200)->json_has( '/0', 'has first batch' )
108
    $t->get_ok( "//$userid:$password@/api/v1/ill/batches?q=" . encode_json($query) )->status_is(200)
103
        ->json_has( '/1', 'has second batch' );
109
        ->json_has( '/0', 'has first batch' )->json_is( '/0/ill_batch_id', $batch_1->id )
110
        ->json_has( '/1', 'has second batch' )->json_is( '/1/ill_batch_id', $batch_2->id );
104
111
105
    my $patron = $builder->build_object(
112
    my $patron = $builder->build_object(
106
        {
113
        {
Lines 144-159 subtest 'get() tests' => sub { Link Here
144
        }
151
        }
145
    );
152
    );
146
153
147
    my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
154
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
148
155
149
    my $batch = $builder->build_object(
156
    my $batch = $builder->build_object(
150
        {
157
        {
151
            class => 'Koha::Illbatches',
158
            class => 'Koha::Illbatches',
152
            value => {
159
            value => {
153
                name           => "LeiaOrgana",
160
                backend    => "Mock",
154
                backend        => "Mock",
161
                patron_id  => $librarian->id,
155
                borrowernumber => $librarian->borrowernumber,
162
                library_id => $library->id,
156
                branchcode     => $branch->branchcode
157
            }
163
            }
158
        }
164
        }
159
    );
165
    );
Lines 162-172 subtest 'get() tests' => sub { Link Here
162
    my $unauth_userid = $patron->userid;
168
    my $unauth_userid = $patron->userid;
163
169
164
    $t->get_ok( "//$userid:$password@/api/v1/ill/batches/"
170
    $t->get_ok( "//$userid:$password@/api/v1/ill/batches/"
165
            . $batch->id => { 'x-koha-embed' => '+strings,requests+count,patron,branch' } )->status_is(200)
171
            . $batch->id => { 'x-koha-embed' => '+strings,requests+count,patron,library' } )->status_is(200)
166
        ->json_has( '/batch_id',   'Batch ID' )->json_has( '/name', 'Batch name' )
172
        ->json_has( '/ill_batch_id', 'Batch ID' )->json_has( '/name', 'Batch name' )
167
        ->json_has( '/backend',    'Backend name' )->json_has( '/patron_id', 'Borrowernumber' )
173
        ->json_has( '/backend',      'Backend name' )->json_has( '/patron_id', 'Borrowernumber' )
168
        ->json_has( '/library_id', 'Branchcode' )->json_has( '/patron', 'patron embedded' )
174
        ->json_has( '/library_id',   'Branchcode' )->json_has( '/patron', 'patron embedded' )
169
        ->json_has( '/branch',     'branch embedded' )->json_has( '/requests_count', 'request count' );
175
        ->json_has( '/library',      'library embedded' )->json_has( '/requests_count', 'request count' );
170
176
171
    $t->get_ok( "//$unauth_userid:$password@/api/v1/ill/batches/" . $batch->id )->status_is(403);
177
    $t->get_ok( "//$unauth_userid:$password@/api/v1/ill/batches/" . $batch->id )->status_is(403);
172
178
Lines 182-188 subtest 'get() tests' => sub { Link Here
182
188
183
subtest 'add() tests' => sub {
189
subtest 'add() tests' => sub {
184
190
185
    plan tests => 19;
191
    plan tests => 20;
186
192
187
    $schema->storage->txn_begin;
193
    $schema->storage->txn_begin;
188
194
Lines 206-221 subtest 'add() tests' => sub { Link Here
206
    $patron->set_password( { password => $password, skip_validation => 1 } );
212
    $patron->set_password( { password => $password, skip_validation => 1 } );
207
    my $unauth_userid = $patron->userid;
213
    my $unauth_userid = $patron->userid;
208
214
209
    my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
215
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
210
216
211
    my $batch_status = $builder->build_object( { class => 'Koha::IllbatchStatuses' } );
217
    my $batch_status = $builder->build_object( { class => 'Koha::IllbatchStatuses' } );
212
218
213
    my $batch_metadata = {
219
    my $batch_metadata = {
214
        name       => "Anakin's requests",
220
        name        => "Anakin's requests",
215
        backend    => "Mock",
221
        backend     => "Mock",
216
        cardnumber => $librarian->cardnumber,
222
        cardnumber  => $librarian->cardnumber,
217
        library_id => $branch->branchcode,
223
        library_id  => $library->branchcode,
218
        statuscode => $batch_status->code
224
        status_code => $batch_status->code
219
    };
225
    };
220
226
221
    # Unauthorized attempt to write
227
    # Unauthorized attempt to write
Lines 239-251 subtest 'add() tests' => sub { Link Here
239
245
240
    # Authorized attempt to write
246
    # Authorized attempt to write
241
    my $batch_id =
247
    my $batch_id =
242
        $t->post_ok( "//$userid:$password@/api/v1/ill/batches" =>
248
        $t->post_ok(
243
                { 'x-koha-embed' => '+strings,requests+count,patron,branch' } => json => $batch_metadata )
249
        "//$userid:$password@/api/v1/ill/batches" => { 'x-koha-embed' => '+strings,requests+count,patron,library' } =>
244
            ->status_is(201)
250
            json => $batch_metadata )->status_is(201)->json_is( '/name' => $batch_metadata->{name} )
245
        ->json_is( '/name'       => $batch_metadata->{name} )->json_is( '/backend' => $batch_metadata->{backend} )
251
        ->json_is( '/backend'    => $batch_metadata->{backend} )->json_is( '/patron_id' => $librarian->borrowernumber )
246
        ->json_is( '/patron_id'  => $librarian->borrowernumber )
252
        ->json_is( '/library_id' => $batch_metadata->{library_id} )->json_is( '/status_code' => $batch_status->code )
247
        ->json_is( '/library_id' => $batch_metadata->{library_id} )->json_is( '/statuscode' => $batch_status->code )
253
        ->json_has('/patron')->json_has('/_strings/status_code')->json_has('/_strings/library_id')
248
        ->json_has('/patron')->json_has('/_strings/status')->json_has('/requests_count')->json_has('/branch');
254
        ->json_has('/requests_count')->json_has('/library');
249
255
250
    # Authorized attempt to create with null id
256
    # Authorized attempt to create with null id
251
    $batch_metadata->{id} = undef;
257
    $batch_metadata->{id} = undef;
Lines 281-288 subtest 'update() tests' => sub { Link Here
281
    $patron->set_password( { password => $password, skip_validation => 1 } );
287
    $patron->set_password( { password => $password, skip_validation => 1 } );
282
    my $unauth_userid = $patron->userid;
288
    my $unauth_userid = $patron->userid;
283
289
284
    my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
290
    my $library  = $builder->build_object( { class => 'Koha::Libraries' } );
285
286
    my $batch_id = $builder->build_object( { class => 'Koha::Illbatches' } )->id;
291
    my $batch_id = $builder->build_object( { class => 'Koha::Illbatches' } )->id;
287
292
288
    # Unauthorized attempt to update
293
    # Unauthorized attempt to update
Lines 293-302 subtest 'update() tests' => sub { Link Here
293
298
294
    # Attempt partial update on a PUT
299
    # Attempt partial update on a PUT
295
    my $batch_with_missing_field = {
300
    my $batch_with_missing_field = {
296
        backend    => "Mock",
301
        backend     => "Mock",
297
        patron_id  => $librarian->borrowernumber,
302
        patron_id   => $librarian->borrowernumber,
298
        library_id => $branch->branchcode,
303
        library_id  => $library->branchcode,
299
        statuscode => $batch_status->code
304
        status_code => $batch_status->code
300
    };
305
    };
301
306
302
    $t->put_ok( "//$userid:$password@/api/v1/ill/batches/$batch_id" => json => $batch_with_missing_field )
307
    $t->put_ok( "//$userid:$password@/api/v1/ill/batches/$batch_id" => json => $batch_with_missing_field )
Lines 304-314 subtest 'update() tests' => sub { Link Here
304
309
305
    # Full object update on PUT
310
    # Full object update on PUT
306
    my $batch_with_updated_field = {
311
    my $batch_with_updated_field = {
307
        name       => "Master Ploo Koon",
312
        name        => "Master Ploo Koon",
308
        backend    => "Mock",
313
        backend     => "Mock",
309
        patron_id  => $librarian->borrowernumber,
314
        patron_id   => $librarian->borrowernumber,
310
        library_id => $branch->branchcode,
315
        library_id  => $library->branchcode,
311
        statuscode => $batch_status->code
316
        status_code => $batch_status->code
312
    };
317
    };
313
318
314
    $t->put_ok( "//$userid:$password@/api/v1/ill/batches/$batch_id" => json => $batch_with_updated_field )
319
    $t->put_ok( "//$userid:$password@/api/v1/ill/batches/$batch_id" => json => $batch_with_updated_field )
315
- 

Return to bug 30719