From 11620571a508606642dc800848469daffe3ef0df Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 10 Nov 2020 08:47:29 -0300 Subject: [PATCH] Bug 23916: (QA follow-up) Adapt all the things to the new column and accessor names Signed-off-by: Tomas Cohen Arazi --- C4/Circulation.pm | 3 ++- Koha/Checkout.pm | 12 ++++++------ Koha/Old/Checkout.pm | 15 +++++++++++++++ .../prog/en/modules/catalogue/issuehistory.tt | 6 +++--- .../prog/en/modules/members/readingrec.tt | 2 +- t/db_dependent/Circulation.t | 14 ++++++-------- t/db_dependent/Koha/Checkouts.t | 12 ++++++------ 7 files changed, 39 insertions(+), 25 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index f0b8dc4d1c0..b33e6d58d10 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1527,7 +1527,7 @@ sub AddIssue { my $userenv = C4::Context->userenv(); my $usernumber = (ref($userenv) eq 'HASH') ? $userenv->{'number'} : undef; if ($usernumber) { - $issue_attributes->{issuer} = $usernumber; + $issue_attributes->{issuer_id} = $usernumber; } } @@ -1545,6 +1545,7 @@ sub AddIssue { } )->store; } + $issue->discard_changes; if ( $item_object->location && $item_object->location eq 'CART' && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) { ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart. diff --git a/Koha/Checkout.pm b/Koha/Checkout.pm index 7328a9c4b53..944c0b1d731 100644 --- a/Koha/Checkout.pm +++ b/Koha/Checkout.pm @@ -106,18 +106,19 @@ sub patron { return Koha::Patron->_new_from_dbic( $patron_rs ); } -=head3 issued_by +=head3 issuer -my $issued_by = $checkout->issued_by +my $issuer = $checkout->issuer Return the patron by whom the checkout was done =cut -sub issued_by { +sub issuer { my ( $self ) = @_; - my $issued_by_rs = $self->_result->issuer; - return Koha::Patron->_new_from_dbic( $issued_by_rs ); + my $issuer_rs = $self->_result->issuer; + return unless $issuer_rs; + return Koha::Patron->_new_from_dbic( $issuer_rs ); } =head3 to_api_mapping @@ -131,7 +132,6 @@ sub to_api_mapping { return { issue_id => 'checkout_id', borrowernumber => 'patron_id', - issuer => 'issuer_id', itemnumber => 'item_id', date_due => 'due_date', branchcode => 'library_id', diff --git a/Koha/Old/Checkout.pm b/Koha/Old/Checkout.pm index 7b62111f0cd..e0eb1e0382e 100644 --- a/Koha/Old/Checkout.pm +++ b/Koha/Old/Checkout.pm @@ -74,6 +74,21 @@ sub patron { return Koha::Patron->_new_from_dbic( $patron_rs ); } +=head3 issuer + +my $issuer = $checkout->issuer + +Return the patron by whom the checkout was done + +=cut + +sub issuer { + my ( $self ) = @_; + my $issuer_rs = $self->_result->issuer; + return unless $issuer_rs; + return Koha::Patron->_new_from_dbic( $issuer_rs ); +} + =head3 to_api_mapping This method returns the mapping for representing a Koha::Old::Checkout object diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/issuehistory.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/issuehistory.tt index 796c5e62e63..26220fee754 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/issuehistory.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/issuehistory.tt @@ -67,9 +67,9 @@   [% END %] [% IF Koha.Preference('RecordStaffUserOnCheckout') %] - [% IF checkout.issuer %] - - [% INCLUDE 'patron-title.inc' patron=checkout.issued_by %] + [% IF checkout.issuer_id %] + + [% INCLUDE 'patron-title.inc' patron=checkout.issuer_id %] [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt index 019e3b78cb9..ed734436a7f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt @@ -98,7 +98,7 @@ [% Branches.GetName( issue.branchcode ) | html %] [% IF Koha.Preference('RecordStaffUserOnCheckout') %] - [% issue.firstname | html %] [% issue.surname | html %] + [% issue.firstname | html %] [% issue.surname | html %] [% END %] [% IF issue.date_due %] diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 819c6c1f446..41b415c27f0 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -4610,20 +4610,19 @@ subtest 'AddIssue records staff who checked out item if appropriate' => sub { $module->mock( 'userenv', sub { { branch => $library->{id} } } ); - my $library = - $builder->build_object( { class => 'Koha::Libraries' } )->store; + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } - )->store; + ); my $issuer = $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } - )->store; + ); my $item = $builder->build_sample_item( { library => $library->{branchcode} @@ -4632,11 +4631,10 @@ subtest 'AddIssue records staff who checked out item if appropriate' => sub { $module->mock( 'userenv', sub { { branch => $library->id, number => $issuer->{borrowernumber} } } ); - my $dt_from = dt_from_string(); - my $dt_to = dt_from_string()->add( days => 7 ); + my $dt_from = dt_from_string(); + my $dt_to = dt_from_string()->add( days => 7 ); - my $issue = - AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from ); + my $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from ); is( $issue->issuer, undef, "Staff who checked out the item not recorded when RecordStaffUserOnCheckout turned off" ); diff --git a/t/db_dependent/Koha/Checkouts.t b/t/db_dependent/Koha/Checkouts.t index 246a986eea7..60722ce0bad 100755 --- a/t/db_dependent/Koha/Checkouts.t +++ b/t/db_dependent/Koha/Checkouts.t @@ -133,24 +133,24 @@ subtest 'issuer' => sub { my $item = $builder->build_sample_item; my $checkout = Koha::Checkout->new({ borrowernumber => $patron->borrowernumber, - issuer => $issuer->borrowernumber, + issuer_id => $issuer->borrowernumber, itemnumber => $item->itemnumber, branchcode => $library->{branchcode}, })->store; - my $i = $checkout->issued_by; + my $i = $checkout->issuer; is( ref($i), 'Koha::Patron', - 'Koha::Checkout->issued_by should return a Koha::Patron' ); + 'Koha::Checkout->issuer should return a Koha::Patron' ); is( $i->borrowernumber, $issuer->borrowernumber, - 'Koha::Checkout->issued_by should return the correct patron' ); + 'Koha::Checkout->issuer should return the correct patron' ); # Testing Koha::Old::Checkout->patron now my $issue_id = $checkout->issue_id; C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $checkout->itemnumber ); $i->delete; my $old_issue = Koha::Old::Checkouts->find($issue_id); - is( $old_issue->issuer, undef, - 'Koha::Checkout->issuer should return undef if the patron record has been deleted' + is( $old_issue->issuer_id, undef, + 'Koha::Checkout->issuer_id should return undef if the patron record has been deleted' ); }; -- 2.29.2