From ff20c8418ccbbb766dca2a93db1eeb7b51ad2a86 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 28 Apr 2025 12:50:22 +0200 Subject: [PATCH] Bug 39711: (bugfix) Allow to clear basket's contract --- C4/Acquisition.pm | 9 ++++----- t/db_dependent/Acquisition.t | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 685d6217a2a..724f0f23ab2 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -622,11 +622,10 @@ sub ModBasketHeader { $create_items || undef, $basketno ); - if ($contractnumber) { - my $query2 = "UPDATE aqbasket SET contractnumber=? WHERE basketno=?"; - my $sth2 = $dbh->prepare($query2); - $sth2->execute( $contractnumber, $basketno ); - } + if ( !$contractnumber ) { $contractnumber = undef; } + my $query2 = "UPDATE aqbasket SET contractnumber=? WHERE basketno=?"; + my $sth2 = $dbh->prepare($query2); + $sth2->execute( $contractnumber, $basketno ); # Log the basket update if ( C4::Context->preference("AcquisitionLog") ) { diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 7552a2d3458..513c4004042 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -20,7 +20,7 @@ use Modern::Perl; use POSIX qw(strftime); use Test::NoWarnings; -use Test::More tests => 74; +use Test::More tests => 75; use t::lib::Mocks; use Koha::Database; use Koha::DateUtils qw(dt_from_string output_pref); @@ -1390,3 +1390,19 @@ subtest 'GetInvoices() tests with additional fields' => sub { $schema->storage->txn_rollback; }; + +subtest 'ModBasketHeader' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + my $basket = $builder->build_object( { class => 'Koha::Acquisition::Baskets' } ); + isnt( $basket->contractnumber, undef ); + C4::Acquisition::ModBasketHeader( + $basket->basketno, $basket->basketname, $basket->note, $basket->booksellernote, + undef, $basket->booksellerid + ); + $basket = $basket->get_from_storage; + is( $basket->contractnumber, undef ); + + $schema->storage->txn_rollback; +}; -- 2.34.1