Lines 24-29
use Koha::Ratings;
Link Here
|
24 |
use Koha::RecordProcessor; |
24 |
use Koha::RecordProcessor; |
25 |
use C4::Biblio qw( DelBiblio ); |
25 |
use C4::Biblio qw( DelBiblio ); |
26 |
|
26 |
|
|
|
27 |
use C4::Barcodes::ValueBuilder; |
28 |
use C4::Context; |
29 |
|
30 |
use Koha::Items; |
31 |
use Koha::Item; |
32 |
|
27 |
use List::MoreUtils qw( any ); |
33 |
use List::MoreUtils qw( any ); |
28 |
use MARC::Record::MiJ; |
34 |
use MARC::Record::MiJ; |
29 |
|
35 |
|
Lines 270-275
sub get_items {
Link Here
|
270 |
}; |
276 |
}; |
271 |
} |
277 |
} |
272 |
|
278 |
|
|
|
279 |
=head3 add_item |
280 |
|
281 |
Controller function that handles creating a biblio's item |
282 |
|
283 |
=cut |
284 |
|
285 |
sub add_item { |
286 |
my $c = shift->openapi->valid_input or return; |
287 |
|
288 |
try { |
289 |
my $biblio_id = $c->validation->param('biblio_id'); |
290 |
my $biblio = Koha::Biblios->find( $biblio_id ); |
291 |
|
292 |
unless ($biblio) { |
293 |
return $c->render( |
294 |
status => 404, |
295 |
openapi => { error => "Biblio not found" } |
296 |
); |
297 |
} |
298 |
|
299 |
my $body = $c->validation->param('body'); |
300 |
|
301 |
$body->{biblio_id} = $biblio_id; |
302 |
|
303 |
# Don't save extended subfields yet. To be done in another bug. |
304 |
$body->{extended_subfields} = undef; |
305 |
|
306 |
my $item = Koha::Item->new_from_api($body); |
307 |
|
308 |
if ( ! defined $item->barcode && C4::Context->preference('autoBarcode') eq 'incremental' ) { |
309 |
my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode; |
310 |
$item->barcode($barcode); |
311 |
} |
312 |
|
313 |
if ( defined $item->barcode |
314 |
&& Koha::Items->search( { barcode => $item->barcode } )->count ) |
315 |
{ |
316 |
return $c->render( |
317 |
status => 400, |
318 |
openapi => { error => "Barcode not unique" } |
319 |
); |
320 |
} |
321 |
|
322 |
my $storedItem = $item->store; |
323 |
$storedItem->discard_changes; |
324 |
|
325 |
$c->render( |
326 |
status => 201, |
327 |
openapi => $storedItem->to_api |
328 |
); |
329 |
} |
330 |
catch { |
331 |
$c->unhandled_exception($_); |
332 |
} |
333 |
} |
334 |
|
273 |
=head3 get_checkouts |
335 |
=head3 get_checkouts |
274 |
|
336 |
|
275 |
List Koha::Checkout objects |
337 |
List Koha::Checkout objects |