Bugzilla – Attachment 173793 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.64 KB, created by
Martin Renvoize (ashimema)
on 2024-10-31 13:14:50 UTC
(
hide
)
Description:
Bug 22421: (follow-up) Correct checkout relation
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-10-31 13:14:50 UTC
Size:
4.64 KB
patch
obsolete
>From 6e85eb8c31079868b168afacc3f4cda4f54e0306 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> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > 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 64d2b5176ab..a8cd9e262ff 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -2651,9 +2651,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 2dc50293750..16752ff0329 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 41b76c96627..229bae28d4b 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.47.0
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