From 6ecd8ac38580fd5a7b215fad1dd6ff81fc61ced6 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 10 Jan 2020 10:08:50 +0000 Subject: [PATCH] Bug 15985: (QA follow-up) Revert to Koha::Object bases Being pragmatic to try and move this bug on, I've reverted the changed base class for the Old:: classes and cloned the required code from the corresponding Object classes. Signed-off-by: Martin Renvoize --- Koha/Checkout.pm | 2 +- Koha/Old/Checkout.pm | 66 ++++++++++++++++++++++++++++++++-- Koha/Old/Checkouts.pm | 2 +- Koha/Schema/Result/OldIssue.pm | 44 +++++++++++++++++------ 4 files changed, 100 insertions(+), 14 deletions(-) diff --git a/Koha/Checkout.pm b/Koha/Checkout.pm index 8ec94176f7..afeb48284c 100644 --- a/Koha/Checkout.pm +++ b/Koha/Checkout.pm @@ -26,7 +26,7 @@ use Try::Tiny; use Koha::Checkouts::ReturnClaims; use Koha::Database; -use Koha::DateUtils; +use Koha::DateUtils qw(dt_from_string); use Koha::Items; use Koha::Libraries; diff --git a/Koha/Old/Checkout.pm b/Koha/Old/Checkout.pm index f7be2c9783..eab58be484 100644 --- a/Koha/Old/Checkout.pm +++ b/Koha/Old/Checkout.pm @@ -18,8 +18,9 @@ package Koha::Old::Checkout; use Modern::Perl; use Koha::Database; +use Koha::DateUtils qw(dt_from_string); -use base qw(Koha::Checkout); +use base qw(Koha::Object); =head1 NAME @@ -54,7 +55,6 @@ Return the patron for who the checkout has been done sub patron { my ( $self ) = @_; my $patron_rs = $self->_result->borrower; - return unless $patron_rs; return Koha::Patron->_new_from_dbic( $patron_rs ); } @@ -79,6 +79,68 @@ sub to_api_mapping { }; } +=head3 claim_returned + +my $return_claim = $checkout->claim_returned(); + +=cut + +sub claim_returned { + my ( $self, $params ) = @_; + + my $charge_lost_fee = $params->{charge_lost_fee}; + + try { + $self->_result->result_source->schema->txn_do( + sub { + my $claim = Koha::Checkouts::ReturnClaim->new( + { + issue_id => $self->id, + itemnumber => $self->itemnumber, + borrowernumber => $self->borrowernumber, + notes => $params->{notes}, + created_by => $params->{created_by}, + created_on => dt_from_string, + } + )->store(); + + my $ClaimReturnedLostValue = C4::Context->preference('ClaimReturnedLostValue'); + C4::Items::ModItem( { itemlost => $ClaimReturnedLostValue }, undef, $self->itemnumber ); + + my $ClaimReturnedChargeFee = C4::Context->preference('ClaimReturnedChargeFee'); + $charge_lost_fee = + $ClaimReturnedChargeFee eq 'charge' ? 1 + : $ClaimReturnedChargeFee eq 'no_charge' ? 0 + : $charge_lost_fee; # $ClaimReturnedChargeFee eq 'ask' + C4::Circulation::LostItem( $self->itemnumber, 'claim_returned' ) if $charge_lost_fee; + + return $claim; + } + ); + } + catch { + if ( $_->isa('Koha::Exceptions::Exception') ) { + $_->rethrow(); + } + else { + # ? + Koha::Exceptions::Exception->throw( "Unhandled exception" ); + } + }; +} + +=head3 library + +my $library = $checkout->library; + +=cut + +sub library { + my ($self) = @_; + + my $library_rs = $self->_result->branch; + return Koha::Library->_new_from_dbic( $library_rs ); +} =head2 Internal methods =head3 _type diff --git a/Koha/Old/Checkouts.pm b/Koha/Old/Checkouts.pm index ed961428cc..af598efab1 100644 --- a/Koha/Old/Checkouts.pm +++ b/Koha/Old/Checkouts.pm @@ -20,7 +20,7 @@ use Modern::Perl; use Koha::Database; use Koha::Old::Checkout; -use base qw(Koha::Checkouts); +use base qw(Koha::Objects); sub _type { return 'OldIssue'; diff --git a/Koha/Schema/Result/OldIssue.pm b/Koha/Schema/Result/OldIssue.pm index 2ecbcab0d6..a0e2fc59aa 100644 --- a/Koha/Schema/Result/OldIssue.pm +++ b/Koha/Schema/Result/OldIssue.pm @@ -233,16 +233,6 @@ __PACKAGE__->belongs_to( }, ); -__PACKAGE__->belongs_to( - "branch", - "Koha::Schema::Result::Branch", - { branchcode => "branchcode" }, - { - is_deferrable => 1, - join_type => "LEFT", - }, -); - # Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-04-10 19:55:44 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:E2N2paWcCHg916100ry+2A @@ -252,6 +242,14 @@ __PACKAGE__->add_columns( '+onsite_checkout' => { is_boolean => 1 } ); +=head2 borrower + +Type: belongs_to + +Related object: L + +=cut + __PACKAGE__->belongs_to( "borrower", "Koha::Schema::Result::Borrower", @@ -259,6 +257,14 @@ __PACKAGE__->belongs_to( { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" }, ); +=head2 item + +Type: belongs_to + +Related object: L + +=cut + __PACKAGE__->belongs_to( "item", "Koha::Schema::Result::Item", @@ -271,6 +277,24 @@ __PACKAGE__->belongs_to( }, ); +=head2 branch + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "branch", + "Koha::Schema::Result::Branch", + { branchcode => "branchcode" }, + { + is_deferrable => 1, + join_type => "LEFT", + }, +); + sub koha_object_class { 'Koha::Old::Checkout'; } -- 2.25.0