From fe1b12ebd29d151921296a3a605ebe0dd18d97ab Mon Sep 17 00:00:00 2001 From: Martin Renvoize 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 Signed-off-by: Kyle M Hall --- Koha/Account/Line.pm | 12 +++++++----- t/db_dependent/Koha/Account/Lines.t | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index 0df5a7e3c2..8ee82145de 100644 --- a/Koha/Account/Line.pm +++ b/Koha/Account/Line.pm @@ -61,12 +61,14 @@ Return the checkout linked to this account line if exists =cut sub checkout { - my ( $self ) = @_; - return unless $self->issue_id ; + my ($self) = @_; + return unless ( $self->issue_id || $self->old_issue_id ); + + my $issue_rs = $self->_result->issue; + return Koha::Checkout->_new_from_dbic($issue_rs) if $issue_rs; - $self->{_checkout} ||= Koha::Checkouts->find( $self->issue_id ); - $self->{_checkout} ||= Koha::Old::Checkouts->find( $self->issue_id ); - return $self->{_checkout}; + my $old_issue_rs = $self->_result->old_issue; + return Koha::Old::Checkout->_new_from_dbic($old_issue_rs) if $old_issue_rs; } =head3 void diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t index 1f64125fdb..1b6640f223 100755 --- a/t/db_dependent/Koha/Account/Lines.t +++ b/t/db_dependent/Koha/Account/Lines.t @@ -495,7 +495,8 @@ 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' ); $schema->storage->txn_rollback; -- 2.20.1 (Apple Git-117)