Bugzilla – Attachment 187920 Details for
Bug 35612
Record branch context in accountlines.branchcode for OVERDUE, LOST, and PROCESSING fees
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35612: Unit test Circulation.t
Bug-35612-Unit-test-Circulationt.patch (text/plain), 8.72 KB, created by
Laura Escamilla
on 2025-10-15 16:10:54 UTC
(
hide
)
Description:
Bug 35612: Unit test Circulation.t
Filename:
MIME Type:
Creator:
Laura Escamilla
Created:
2025-10-15 16:10:54 UTC
Size:
8.72 KB
patch
obsolete
>From 5c99842e6f027f8fb577662044902685c8967e00 Mon Sep 17 00:00:00 2001 >From: Laura_Escamilla <laura.escamilla@bywatersolutions.com> >Date: Wed, 15 Oct 2025 15:17:15 +0000 >Subject: [PATCH] Bug 35612: Unit test Circulation.t > >--- > t/db_dependent/Circulation.t | 159 ++++++++++++++++++++++++++++++++++- > 1 file changed, 157 insertions(+), 2 deletions(-) > >diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t >index edc3b7ea26..7d8e0c288c 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -41,7 +41,7 @@ use C4::Biblio; > use C4::Items qw( ModItemTransfer ); > use C4::Log; > use C4::Reserves qw( AddReserve ModReserve ModReserveCancelAll ModReserveAffect CheckReserves ); >-use C4::Overdues qw( CalcFine UpdateFine get_chargeable_units ); >+use C4::Overdues qw( CalcFine UpdateFine get_chargeable_units branch_for_fee_context ); > use C4::Members::Messaging qw( SetMessagingPreference ); > use Koha::DateUtils qw( dt_from_string output_pref ); > use Koha::Database; >@@ -77,6 +77,14 @@ sub str { > return $s; > } > >+sub _latest_lost_line_for_item { >+ my ($itemnumber) = @_; >+ return Koha::Account::Lines->search( >+ { itemnumber => $itemnumber, debit_type_code => 'LOST' }, >+ { order_by => { -desc => 'accountlines_id' } } >+ )->next; >+} >+ > sub test_debarment_on_checkout { > my ($params) = @_; > my $item = $params->{item}; >@@ -495,7 +503,7 @@ subtest "GetIssuingCharges tests" => sub { > > my ( $reused_itemnumber_1, $reused_itemnumber_2 ); > subtest "CanBookBeRenewed tests" => sub { >- plan tests => 114; >+ plan tests => 116; > > C4::Context->set_preference( 'ItemsDeniedRenewal', '' ); > >@@ -1818,6 +1826,152 @@ subtest "CanBookBeRenewed tests" => sub { > "Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" > ); > >+ subtest 'LostItem records accountlines.branchcode per LostChargesControl' => sub { >+ plan tests => 8; >+ my $FPL = $builder->build( { source => 'Branch' } )->{branchcode}; >+ my $CPL = $builder->build( { source => 'Branch' } )->{branchcode}; >+ my $PVL = $builder->build( { source => 'Branch' } )->{branchcode}; >+ >+ my $p = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $PVL } } ); >+ my $it = $builder->build_object( >+ { >+ class => 'Koha::Items', >+ value => { >+ homebranch => $FPL, >+ holdingbranch => $CPL, >+ replacementprice => 12.34, >+ } >+ } >+ ); >+ >+ t::lib::Mocks::mock_userenv( >+ { >+ patron => $builder->build_object( { class => 'Koha::Patrons' } ), >+ branchcode => $CPL, >+ } >+ ); >+ >+ t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 ); >+ >+ my $chk = C4::Circulation::AddIssue( $p, $it->barcode ); >+ for my $path ( [ cron => 'cronjob' ], [ intranet => 'intranet' ] ) { >+ my ( $label, $mark_from ) = @$path; >+ >+ Koha::Account::Lines->search( { itemnumber => $it->itemnumber, debit_type_code => 'LOST' } )->delete; >+ >+ $it->itemlost(0)->store; >+ $it->discard_changes; >+ unless ( Koha::Checkouts->find( { itemnumber => $it->itemnumber } ) ) { >+ C4::Circulation::AddIssue( $p, $it->barcode ); >+ } >+ >+ t::lib::Mocks::mock_preference( 'LostChargesControl', 'ItemHomeLibrary' ); >+ t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', 'homebranch' ); >+ C4::Circulation::LostItem( $it->itemnumber, $mark_from, 0 ); >+ my $l = _latest_lost_line_for_item( $it->itemnumber ); >+ ok( $l, "[$label] LOST line created" ); >+ is( $l->branchcode, $FPL, "[$label] branchcode = item home (FPL) for ItemHomeLibrary/homebranch" ); >+ >+ Koha::Account::Lines->search( { itemnumber => $it->itemnumber, debit_type_code => 'LOST' } )->delete; >+ >+ $it->itemlost(0)->store; >+ $it->discard_changes; >+ >+ unless ( Koha::Checkouts->find( { itemnumber => $it->itemnumber } ) ) { >+ C4::Circulation::AddIssue( $p, $it->barcode ); >+ } >+ t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', 'holdingbranch' ); >+ C4::Circulation::LostItem( $it->itemnumber, $mark_from, 0 ); >+ $l = _latest_lost_line_for_item( $it->itemnumber ); >+ ok( $l, "[$label] LOST line created (holding)" ); >+ is( $l->branchcode, $CPL, "[$label] branchcode = item holding (CPL) for ItemHomeLibrary/holdingbranch" ); >+ } >+ }; >+ >+ subtest 'UpdateFine records accountlines.branchcode per CircControl' => sub { >+ plan tests => 6; >+ >+ my $FPL = $builder->build( { source => 'Branch' } )->{branchcode}; >+ my $CPL = $builder->build( { source => 'Branch' } )->{branchcode}; >+ my $PVL = $builder->build( { source => 'Branch' } )->{branchcode}; >+ >+ my $pat = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $PVL } } ); >+ my $itm = $builder->build_object( >+ { class => 'Koha::Items', value => { homebranch => $FPL, holdingbranch => $CPL } } ); >+ >+ set_userenv( { branchcode => $CPL } ); >+ >+ my $due = dt_from_string->clone->subtract( days => 5 ); >+ my $issue = C4::Circulation::AddIssue( $pat, $itm->barcode, $due ); >+ >+ Koha::Account::Lines->search( >+ { >+ borrowernumber => $pat->borrowernumber, >+ itemnumber => $itm->itemnumber, >+ debit_type_code => 'OVERDUE', >+ } >+ )->delete; >+ >+ # 1) PatronLibrary -> PVL >+ t::lib::Mocks::mock_preference( 'CircControl', 'PatronLibrary' ); >+ t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', 'homebranch' ); >+ C4::Overdues::UpdateFine( >+ { >+ issue_id => $issue->id, >+ itemnumber => $itm->itemnumber, >+ borrowernumber => $pat->borrowernumber, >+ amount => 1.50, >+ due => Koha::DateUtils::output_pref($due), >+ } >+ ); >+ >+ my $od = Koha::Account::Lines->search( >+ { borrowernumber => $pat->borrowernumber, itemnumber => $itm->itemnumber, debit_type_code => 'OVERDUE' }, >+ { order_by => { -desc => 'accountlines_id' } } >+ )->next; >+ ok( $od, 'OVERDUE line created (PatronLibrary)' ); >+ is( $od->branchcode, $PVL, 'branchcode = patron home (PVL)' ); >+ $od->delete; >+ >+ # 2) PickupLibrary -> CPL >+ t::lib::Mocks::mock_preference( 'CircControl', 'PickupLibrary' ); >+ C4::Overdues::UpdateFine( >+ { >+ issue_id => $issue->id, >+ itemnumber => $itm->itemnumber, >+ borrowernumber => $pat->borrowernumber, >+ amount => 1.50, >+ due => Koha::DateUtils::output_pref($due), >+ } >+ ); >+ $od = Koha::Account::Lines->search( >+ { borrowernumber => $pat->borrowernumber, itemnumber => $itm->itemnumber, debit_type_code => 'OVERDUE' }, >+ { order_by => { -desc => 'accountlines_id' } } >+ )->next; >+ ok( $od, 'OVERDUE line created (PickupLibrary)' ); >+ is( $od->branchcode, $CPL, 'branchcode = issuing branch (CPL)' ); >+ $od->delete; >+ >+ # 3) ItemHomeLibrary + homebranch -> FPL >+ t::lib::Mocks::mock_preference( 'CircControl', 'ItemHomeLibrary' ); >+ t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', 'homebranch' ); >+ C4::Overdues::UpdateFine( >+ { >+ issue_id => $issue->id, >+ itemnumber => $itm->itemnumber, >+ borrowernumber => $pat->borrowernumber, >+ amount => 1.50, >+ due => Koha::DateUtils::output_pref($due), >+ } >+ ); >+ $od = Koha::Account::Lines->search( >+ { borrowernumber => $pat->borrowernumber, itemnumber => $itm->itemnumber, debit_type_code => 'OVERDUE' }, >+ { order_by => { -desc => 'accountlines_id' } } >+ )->next; >+ ok( $od, 'OVERDUE line created (ItemHomeLibrary/homebranch)' ); >+ is( $od->branchcode, $FPL, 'branchcode = item home (FPL)' ); >+ }; >+ > # Recalls > t::lib::Mocks::mock_preference( 'UseRecalls', 1 ); > Koha::CirculationRules->set_rules( >@@ -4881,6 +5035,7 @@ subtest 'Set waiting flag' => sub { > ); > > set_userenv($library_2); >+ > my $reserve_id = AddReserve( > { > branchcode => $library_2->{branchcode}, >-- >2.39.5
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 35612
:
186567
|
186568
|
186569
|
186570
|
186571
|
187919
|
187920
|
187921
|
187922
|
189137