Bugzilla – Attachment 147464 Details for
Bug 31798
Add POST endpoint for Items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31798: (follow-up) Handle all values of autoBarcode
Bug-31798-follow-up-Handle-all-values-of-autoBarco.patch (text/plain), 3.59 KB, created by
Nick Clemens (kidclamp)
on 2023-02-27 18:11:00 UTC
(
hide
)
Description:
Bug 31798: (follow-up) Handle all values of autoBarcode
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2023-02-27 18:11:00 UTC
Size:
3.59 KB
patch
obsolete
>From 5daaefdef21a5c4e0bda2a618d71c98ecc8aaa76 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Mon, 27 Feb 2023 17:57:22 +0000 >Subject: [PATCH] Bug 31798: (follow-up) Handle all values of autoBarcode > >--- > Koha/REST/V1/Biblios.pm | 62 +++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 59 insertions(+), 3 deletions(-) > >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index 3e278fae52..a560fe443d 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/Koha/REST/V1/Biblios.pm >@@ -20,6 +20,7 @@ use Modern::Perl; > use Mojo::Base 'Mojolicious::Controller'; > > use Koha::Biblios; >+use Koha::DateUtils; > use Koha::Ratings; > use Koha::RecordProcessor; > use C4::Biblio qw( DelBiblio ); >@@ -305,9 +306,64 @@ sub add_item { > > my $item = Koha::Item->new_from_api($body); > >- if ( ! defined $item->barcode && C4::Context->preference('autoBarcode') eq 'incremental' ) { >- my ( $barcode ) = C4::Barcodes::ValueBuilder::incremental::get_barcode; >- $item->barcode($barcode); >+ if ( !defined $item->barcode ) { >+ >+ # FIXME This should be moved to Koha::Item->store >+ my $autoBarcode = C4::Context->preference('autoBarcode'); >+ my $barcode = ''; >+## Please see file perltidy.ERR >+ if ( !$autoBarcode || $autoBarcode eq 'OFF' ) { >+ >+ #We do nothing >+ } >+ elsif ( $autoBarcode eq 'incremental' ) { >+ ($barcode) = >+ C4::Barcodes::ValueBuilder::incremental::get_barcode; >+ } >+ elsif ( $autoBarcode eq 'annual' ) { >+ my $year = Koha::DateUtils::dt_from_string()->year(); >+ ($barcode) = >+ C4::Barcodes::ValueBuilder::annual::get_barcode({ year => $year }); >+ } >+ elsif ( $autoBarcode eq 'hbyymmincr' ) { >+ >+# Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit >+ my $now = Koha::DateUtils::dt_from_string(); >+ my $year = $now->year(); >+ my $month = $now->month(); >+ my $homebranch = $item->homebranch // ''; >+ ($barcode) = >+ C4::Barcodes::ValueBuilder::hbyymmincr::get_barcode({ year => $year, mon => $month }); >+ $barcode = $homebranch . $barcode; >+ } >+ elsif ( $autoBarcode eq 'EAN13' ) { >+ >+ # not the best, two catalogers could add the same barcode easily this way :/ >+ my $query = "select max(abs(barcode)) from items"; >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare($query); >+ $sth->execute(); >+ my $nextnum; >+ while ( my ($last) = $sth->fetchrow_array ) { >+ $nextnum = $last; >+ } >+ my $ean = CheckDigits('ean'); >+ if ( $ean->is_valid($nextnum) ) { >+ my $next = $ean->basenumber($nextnum) + 1; >+ $nextnum = $ean->complete($next); >+ $nextnum = >+ '0' x ( 13 - length($nextnum) ) . $nextnum; # pad zeros >+ } >+ else { >+ warn "ERROR: invalid EAN-13 $nextnum, using increment"; >+ $nextnum++; >+ } >+ $barcode = $nextnum; >+ } >+ else { >+ warn "ERROR: unknown autoBarcode: $autoBarcode"; >+ } >+ $item->barcode($barcode) if $barcode; > } > > $item->store->discard_changes; >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31798
:
144893
|
144894
|
144952
|
144953
|
144956
|
147463
|
147464
|
147655
|
147656
|
147657
|
150598
|
150599
|
150600
|
150771
|
150772
|
150773
|
150774
|
150775