From 6c72cc1f211c10f0cfdefec605b594441d49582d Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Fri, 25 Aug 2023 15:49:09 +0000 Subject: [PATCH] Bug 34620: Do not throw expection if payment type is writeoff To test: 1. Turn on RequirePaymentType 2. Create a manual invoice and then attempt to write it off. 3. 500 error 4. Turn of RequirePaymentType, no error. 5. Apply patch, restart_all 6. Try step 2 again, you should not get an error 7. prove t/db_dependent/Koha/Account.t 8. Make sure tests pass Signed-off-by: David Nind Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi (cherry picked from commit d77aa887e4b9df61493837b9d88a80537c525471) Signed-off-by: Fridolin Somers (cherry picked from commit 5cc97ab746463f9a48b54a6b5f9a81a83dc80d25) Signed-off-by: Matt Blenkinsop --- Koha/Account.pm | 18 +++++++++--------- t/db_dependent/Koha/Account.t | 12 +++++++++++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Koha/Account.pm b/Koha/Account.pm index f1529476bf..5e52eb980f 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -84,18 +84,18 @@ sub pay { my $userenv = C4::Context->userenv; - Koha::Exceptions::Account::PaymentTypeRequired->throw() - if ( C4::Context->preference("RequirePaymentType") - && !defined($payment_type) ); + unless ( $type eq 'WRITEOFF' ) { + Koha::Exceptions::Account::PaymentTypeRequired->throw() + if ( C4::Context->preference("RequirePaymentType") + && !defined($payment_type) ); - my $av = Koha::AuthorisedValues->search_with_library_limits({ category => 'PAYMENT_TYPE', authorised_value => $payment_type }); + my $av = Koha::AuthorisedValues->search_with_library_limits( + { category => 'PAYMENT_TYPE', authorised_value => $payment_type } ); - if ( !$av->count && C4::Context->preference("RequirePaymentType")) { - Koha::Exceptions::Account::InvalidPaymentType->throw( - error => 'Invalid payment type' - ); + if ( !$av->count && C4::Context->preference("RequirePaymentType") ) { + Koha::Exceptions::Account::InvalidPaymentType->throw( error => 'Invalid payment type' ); + } } - my $manager_id = $userenv ? $userenv->{number} : undef; my $interface = $params ? ( $params->{interface} || C4::Context->interface ) : C4::Context->interface; my $payment = $self->payin_amount( diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t index aaba8fe702..489f4c02b5 100755 --- a/t/db_dependent/Koha/Account.t +++ b/t/db_dependent/Koha/Account.t @@ -665,7 +665,7 @@ subtest 'reconcile_balance' => sub { subtest 'pay() tests' => sub { - plan tests => 8; + plan tests => 9; $schema->storage->txn_begin; @@ -701,6 +701,16 @@ subtest 'pay() tests' => sub { 'Koha::Exceptions::Account::InvalidPaymentType', 'Exception thrown for InvalidPaymentType:1 + payment_type:FOOBAR'; + my $writeoff_id = $account->pay( + { + amount => 10, + interface => 'intranet', + type => 'WRITEOFF', + } + )->{payment_id}; + my $writeoff = Koha::Account::Lines->find($writeoff_id); + is( $writeoff->payment_type, undef, "Writeoff should not have a payment_type " ); + t::lib::Mocks::mock_preference( 'RequirePaymentType', 0 ); my $context = Test::MockModule->new('C4::Context'); $context->mock( 'userenv', { branch => $library->id } ); -- 2.39.5