51e8fc2cb6
Required for SIP checkin implementation, but also for internal correctness. AddReturn had too many things going on, with no guarantee of data being available for the later calls. At some point we started tacking on all the branch transfer logic without testing edge cases. In particular, $borrower is not checked to be sure it is defined, considering the item may not have been checked out so no borrower would be associated. That means that CircControl of "PatronLibrary" would be inaccurate, Circ Alerts will be totally confused (untargeted), and the Fix... subs would fail. Note that *many* errors are still present in _FixAccountForLostAndReturned, including those where comments are added, such that it might behave strangely even with $borrower. Renamed the internal subs with leading underscore, per convention. Changed the arguments to be scalars when only scalars are needed, not entire objects. Added depth to WrongBranch message that includes Rightbranch. Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
142 lines
4 KiB
Perl
142 lines
4 KiB
Perl
package KohaTest::Circulation;
|
|
use base qw( KohaTest );
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Test::More;
|
|
|
|
use C4::Circulation;
|
|
sub testing_class { 'C4::Circulation' };
|
|
|
|
|
|
sub methods : Test( 1 ) {
|
|
my $self = shift;
|
|
my @methods = qw( barcodedecode
|
|
decode
|
|
transferbook
|
|
TooMany
|
|
itemissues
|
|
CanBookBeIssued
|
|
AddIssue
|
|
GetLoanLength
|
|
GetIssuingRule
|
|
GetBranchBorrowerCircRule
|
|
AddReturn
|
|
MarkIssueReturned
|
|
_FixOverduesOnReturn
|
|
_FixAccountForLostAndReturned
|
|
GetItemIssue
|
|
GetItemIssues
|
|
GetBiblioIssues
|
|
GetUpcomingDueIssues
|
|
CanBookBeRenewed
|
|
AddRenewal
|
|
GetRenewCount
|
|
GetIssuingCharges
|
|
AddIssuingCharge
|
|
GetTransfers
|
|
GetTransfersFromTo
|
|
DeleteTransfer
|
|
AnonymiseIssueHistory
|
|
updateWrongTransfer
|
|
UpdateHoldingbranch
|
|
CalcDateDue
|
|
CheckValidDatedue
|
|
CheckRepeatableHolidays
|
|
CheckSpecialHolidays
|
|
CheckRepeatableSpecialHolidays
|
|
CheckValidBarcode
|
|
);
|
|
|
|
can_ok( $self->testing_class, @methods );
|
|
}
|
|
|
|
=head3 setup_add_biblios
|
|
|
|
everything in the C4::Circulation really requires items, so let's do this in the setup phase.
|
|
|
|
=cut
|
|
|
|
sub setup_add_biblios : Tests( setup => 8 ) {
|
|
my $self = shift;
|
|
|
|
# we want to use a fresh batch of items, so clear these lists:
|
|
delete $self->{'items'};
|
|
delete $self->{'biblios'};
|
|
|
|
$self->add_biblios( add_items => 1 );
|
|
}
|
|
|
|
|
|
=head3 checkout_first_item
|
|
|
|
named parameters:
|
|
borrower => borrower hashref, computed from $self->{'memberid'} if not given
|
|
barcode => item barcode, barcode of $self->{'items'}[0] if not given
|
|
issuedate => YYYY-MM-DD of date to mark issue checked out. defaults to today.
|
|
|
|
=cut
|
|
|
|
sub checkout_first_item {
|
|
my $self = shift;
|
|
my $params = shift;
|
|
|
|
# get passed in borrower, or default to the one in $self.
|
|
my $borrower = $params->{'borrower'};
|
|
if ( ! defined $borrower ) {
|
|
my $borrowernumber = $self->{'memberid'};
|
|
$borrower = C4::Members::GetMemberDetails( $borrowernumber );
|
|
}
|
|
|
|
# get the barcode passed in, or default to the first one in the items list
|
|
my $barcode = $params->{'barcode'};
|
|
if ( ! defined $barcode ) {
|
|
return unless $self->{'items'}[0]{'itemnumber'};
|
|
$barcode = $self->get_barcode_from_itemnumber( $self->{'items'}[0]{'itemnumber'} );
|
|
}
|
|
|
|
# get issuedate from parameters. Default to undef, which will be interpreted as today
|
|
my $issuedate = $params->{'issuedate'};
|
|
|
|
my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $borrower, $barcode );
|
|
|
|
my $datedue = C4::Circulation::AddIssue(
|
|
$borrower, # borrower
|
|
$barcode, # barcode
|
|
undef, # datedue
|
|
undef, # cancelreserve
|
|
$issuedate # issuedate
|
|
);
|
|
|
|
my $issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
|
|
|
|
return $issues->{'date_due'};
|
|
}
|
|
|
|
=head3 get_barcode_from_itemnumber
|
|
|
|
pass in an itemnumber, returns a barcode.
|
|
|
|
Should this get moved up to KohaTest.pm? Or, is there a better alternative in C4?
|
|
|
|
=cut
|
|
|
|
sub get_barcode_from_itemnumber {
|
|
my $self = shift;
|
|
my $itemnumber = shift;
|
|
|
|
my $sql = <<END_SQL;
|
|
SELECT barcode
|
|
FROM items
|
|
WHERE itemnumber = ?
|
|
END_SQL
|
|
my $dbh = C4::Context->dbh() or return;
|
|
my $sth = $dbh->prepare($sql) or return;
|
|
$sth->execute($itemnumber) or return;
|
|
my ($barcode) = $sth->fetchrow_array;
|
|
return $barcode;
|
|
}
|
|
|
|
1;
|
|
|