Bugzilla – Attachment 162247 Details for
Bug 22421
accountlines.issue_id is missing a foreign key constraint
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22421: (follow-up) Correct checkout relation
Bug-22421-follow-up-Correct-checkout-relation.patch (text/plain), 4.57 KB, created by
Victor Grousset/tuxayo
on 2024-02-16 20:49:03 UTC
(
hide
)
Description:
Bug 22421: (follow-up) Correct checkout relation
Filename:
MIME Type:
Creator:
Victor Grousset/tuxayo
Created:
2024-02-16 20:49:03 UTC
Size:
4.57 KB
patch
obsolete
>From d3f0df90a8f0c05a4aabf0492021342bb3f0cc21 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 6 Jun 2019 13:25:01 +0100 >Subject: [PATCH] Bug 22421: (follow-up) Correct checkout relation > >The Koha::Account::Line->checkout relationship accessor needed an update >to respect the new fields and foreign keys introduced here. > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> >--- > C4/Circulation.pm | 5 ++--- > Koha/Account/Line.pm | 13 ++++++++++--- > t/db_dependent/Koha/Account/Line.t | 29 +++++++++++++++++++---------- > 3 files changed, 31 insertions(+), 16 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 5d26378082..fce5627736 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -2640,9 +2640,8 @@ sub MarkIssueReturned { > my $old_checkout = Koha::Old::Checkout->new($issue->unblessed)->store; > > # Update accountlines >- my $accountlines = >- Koha::Account::Lines->search( { issue_id => $issue->issue_id } ); >- $accountlines->update({ old_issue_id => $issue->issue_id, issue_id => undef }); >+ my $accountlines = Koha::Account::Lines->search( { issue_id => $issue->issue_id } ); >+ $accountlines->update( { old_issue_id => $issue->issue_id, issue_id => undef } ); > > # anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber > if ( $privacy && $privacy == 2) { >diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm >index 7496f17677..e375874d34 100644 >--- a/Koha/Account/Line.pm >+++ b/Koha/Account/Line.pm >@@ -91,10 +91,17 @@ Return the checkout linked to this account line if exists > > sub checkout { > my ($self) = @_; >- return unless $self->issue_id; > >- return Koha::Checkouts->find( $self->issue_id ) >- || Koha::Old::Checkouts->find( $self->issue_id ); >+ my $result; >+ if ( $self->issue_id ) { >+ my $issue_rs = $self->_result->issue; >+ $result = Koha::Checkout->_new_from_dbic($issue_rs) if $issue_rs; >+ } elsif ( $self->old_issue_id ) { >+ my $old_issue_rs = $self->_result->old_issue; >+ $result = Koha::Old::Checkout->_new_from_dbic($old_issue_rs) if $old_issue_rs; >+ } >+ >+ return $result; > } > > =head3 library >diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t >index c690d38f40..89a31cb218 100755 >--- a/t/db_dependent/Koha/Account/Line.t >+++ b/t/db_dependent/Koha/Account/Line.t >@@ -706,7 +706,7 @@ subtest 'adjust() tests' => sub { > }; > > subtest 'checkout() tests' => sub { >- plan tests => 6; >+ plan tests => 7; > > $schema->storage->txn_begin; > >@@ -718,14 +718,17 @@ subtest 'checkout() tests' => sub { > t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode }); > my $checkout = AddIssue( $patron, $item->barcode ); > >- my $line = $account->add_debit({ >- amount => 10, >- interface => 'commandline', >- item_id => $item->itemnumber, >- issue_id => $checkout->issue_id, >- type => 'OVERDUE', >- status => 'UNRETURNED' >- }); >+ my $line = $account->add_debit( >+ { >+ amount => 10, >+ interface => 'commandline', >+ item_id => $item->itemnumber, >+ issue_id => $checkout->issue_id, >+ old_issue_id => undef, >+ type => 'OVERDUE', >+ status => 'UNRETURNED' >+ } >+ ); > > my $line_checkout = $line->checkout; > is( ref($line_checkout), 'Koha::Checkout', 'Result type is correct' ); >@@ -743,9 +746,15 @@ subtest 'checkout() tests' => sub { > is( ref($old_line_checkout), 'Koha::Old::Checkout', 'Result type is correct' ); > is( $old_line_checkout->issue_id, $old_checkout->issue_id, 'Koha::Account::Line->checkout should return the correct old_checkout' ); > >- $line->issue_id(undef)->store; >+ $old_line_checkout->delete; >+ $line->discard_changes; #NOTE: discard_changes refreshes the whole resultset, get_from_storage only refreshes the unjoined row > is( $line->checkout, undef, 'Koha::Account::Line->checkout should return undef if no checkout linked' ); > >+ $line->old_issue_id(undef)->store; >+ $line->discard_changes; #NOTE: discard_changes refreshes the whole resultset, get_from_storage only refreshes the unjoined row >+ is( $line->checkout, undef, 'Koha::Account::Line->checkout should return undef if no checkout linked' ); >+ >+ > $schema->storage->txn_rollback; > }; > >-- >2.43.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 22421
:
85773
|
85774
|
85775
|
90352
|
90353
|
90354
|
90359
|
90360
|
90361
|
90362
|
90365
|
90366
|
90367
|
90368
|
161919
|
161920
|
161921
|
161922
|
161923
|
162244
|
162245
|
162246
|
162247
|
162248
|
166631
|
173287
|
173288
|
173289
|
173305
|
173790
|
173791
|
173792
|
173793
|
173794
|
173795
|
173796
|
173797
|
173798
|
173799
|
174281