Bug 37070: Incorrect barcode generation when adding orders to basket

When the autoBarcode preference is set to « generated in the form 1, 2, 3 » and the maximum barcode is length 16 (ex 1000000000000000),
when adding orders to the basket,the numbers generated are in the hexadecimal form.

to reproduce:

1- Set the system preference autoBarcode to « generated in the form 1, 2, 3 »
2- Search for a biblio record
3- In the record details, click on New -> New item
4- fill the Barcode field to a number with length 16 (1000000000000000) and add the item
5- Create a suggestion
    5-1- Go to Acquisitions and click on suggestions
    5-2- Create a suggestion and accept it
6- Add a new order to a basket
    6-1- Go to Acquisitions and find a vendor
    6-2- Create a new Basket
    6-3- on the Basket click on 'Add to basket' and select 'From a suggestion'
    6-4- Add the order created on 5-2- to the basket
    6-5- On the item form click on Add item
    6-6- Select a Fund and save the order
7- In the orders table click on the record and check the item Barcode
    ---> the Barcode is in hexadecimal form
8- Cancel order and delete the catalog record
9- Apply the patch
10- Repeat step 6-4, 6-5, 6-6
11- Check the item Barcode
    ---> the Barcode is not in hexadecimal form
12- run prove t/db_dependent/Barcodes.t

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit 898cb34fef)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Hammat Wele 2024-06-11 14:08:45 +00:00 committed by Lucas Gass
parent b5ac0ad18b
commit 0cc899ac3d
2 changed files with 24 additions and 2 deletions

View File

@ -95,7 +95,7 @@ sub max {
}
sub db_max {
my $self = shift;
my $query = "SELECT max(abs(barcode)) FROM items LIMIT 1"; # Possible problem if multiple barcode types populated
my $query = "SELECT max(abs(CAST(barcode AS UNSIGNED))) FROM items LIMIT 1"; # Possible problem if multiple barcode types populated
my $sth = C4::Context->dbh->prepare($query);
$sth->execute();
return $sth->fetchrow_array || $self->initial;

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 75;
use Test::More tests => 76;
use Test::Warn;
use Test::MockModule;
use t::lib::TestBuilder;
@ -132,6 +132,28 @@ subtest 'Test generation of hbyymmincr barcodes from DB values' => sub {
$schema->storage->txn_rollback;
};
subtest 'Test generation of incremental barcodes from DB values' => sub {
plan tests => 2;
$schema->storage->txn_begin;
$builder->schema->resultset('Issue')->delete_all;
$builder->schema->resultset('Item')->delete_all;
my $barcodeobj;
my $item_1 = $builder->build_sample_item(
{
barcode => '1000000000000000'
}
);
$barcodeobj = C4::Barcodes->new('incremental');
is( $barcodeobj->db_max(), '1000000000000000', "(hbyymmincr) First barcode saved to db is equal to db_max" );
is( $barcodeobj->value(), '1000000000000001', 'incremental barcode' );
$schema->storage->txn_rollback;
};
$schema->storage->txn_begin;