@@ -, +, @@ --- Koha/Account/Line.pm | 10 ++++--- Koha/Schema/Result/Accountline.pm | 44 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) --- a/Koha/Account/Line.pm +++ a/Koha/Account/Line.pm @@ -62,11 +62,13 @@ Return the checkout linked to this account line if exists sub checkout { my ( $self ) = @_; - return unless $self->issue_id ; + return unless $self->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; + return undef; } =head3 void --- a/Koha/Schema/Result/Accountline.pm +++ a/Koha/Schema/Result/Accountline.pm @@ -279,4 +279,48 @@ sub koha_object_class { 'Koha::Account::Line'; } +=head2 issue + +Type: belongs_to + +Related object: L + +Note: This DBIC only relationship should be removed (as it will get automatically recreated) +if we add a proper foreign key for accountlines.issue_id + +=cut + +__PACKAGE__->belongs_to( + "issue", + "Koha::Schema::Result::Issue", + { "foriegn.issue_id" => "self.issue_id" }, + { + is_deferrable => 1, + join_type => "LEFT" + }, +); + +=head2 old_issue + +Type: belongs_to + +Related object: L + +Note: This DBIC only relationship should be removed (as it will get automatically recreated) +if we add a proper foreign key for accountlines.issue_id + +=cut + +__PACKAGE__->belongs_to( + "old_issue", + "Koha::Schema::Result::OldIssue", + { "foriegn.issue_id" => "self.issue_id" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + 1; --