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