View | Details | Raw Unified | Return to bug 17796
Collapse All | Expand All

(-)a/Koha/Issue.pm (-28 lines)
Lines 1-28 Link Here
1
package Koha::Issue;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Koha::Database;
21
22
use base qw(Koha::Object);
23
24
sub _type {
25
    return 'Issue';
26
}
27
28
1;
(-)a/Koha/Issues.pm (-33 lines)
Lines 1-33 Link Here
1
package Koha::Issues;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Koha::Database;
21
use Koha::Issue;
22
23
use base qw(Koha::Objects);
24
25
sub _type {
26
    return 'Issue';
27
}
28
29
sub object_class {
30
    return 'Koha::Issue';
31
}
32
33
1;
(-)a/Koha/Patron.pm (-3 / +3 lines)
Lines 24-33 use Carp; Link Here
24
24
25
use C4::Context;
25
use C4::Context;
26
use C4::Log;
26
use C4::Log;
27
use Koha::Checkouts;
27
use Koha::Database;
28
use Koha::Database;
28
use Koha::DateUtils;
29
use Koha::DateUtils;
29
use Koha::Holds;
30
use Koha::Holds;
30
use Koha::Issues;
31
use Koha::OldIssues;
31
use Koha::OldIssues;
32
use Koha::Patron::Categories;
32
use Koha::Patron::Categories;
33
use Koha::Patron::HouseboundProfile;
33
use Koha::Patron::HouseboundProfile;
Lines 257-263 sub do_check_for_previous_checkout { Link Here
257
    };
257
    };
258
258
259
    # Check current issues table
259
    # Check current issues table
260
    my $issues = Koha::Issues->search($criteria);
260
    my $issues = Koha::Checkouts->search($criteria);
261
    return 1 if $issues->count; # 0 || N
261
    return 1 if $issues->count; # 0 || N
262
262
263
    # Check old issues table
263
    # Check old issues table
Lines 512-518 Return the overdued items Link Here
512
sub get_overdues {
512
sub get_overdues {
513
    my ($self) = @_;
513
    my ($self) = @_;
514
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
514
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
515
    my $issues = Koha::Issues->search(
515
    my $issues = Koha::Checkouts->search(
516
        {
516
        {
517
            'me.borrowernumber' => $self->borrowernumber,
517
            'me.borrowernumber' => $self->borrowernumber,
518
            'me.date_due' => { '<' => $dtf->format_datetime(dt_from_string) },
518
            'me.date_due' => { '<' => $dtf->format_datetime(dt_from_string) },
(-)a/Koha/REST/V1.pm (-3 / +3 lines)
Lines 21-27 use Mojo::Base 'Mojolicious'; Link Here
21
use C4::Auth qw( check_cookie_auth get_session haspermission );
21
use C4::Auth qw( check_cookie_auth get_session haspermission );
22
use C4::Context;
22
use C4::Context;
23
use Koha::Account::Lines;
23
use Koha::Account::Lines;
24
use Koha::Issues;
24
use Koha::Checkouts;
25
use Koha::Holds;
25
use Koha::Holds;
26
use Koha::OldIssues;
26
use Koha::OldIssues;
27
use Koha::Patrons;
27
use Koha::Patrons;
Lines 259-265 sub _object_ownership_by_borrowernumber { Link Here
259
259
260
=head3 _object_ownership_by_checkout_id
260
=head3 _object_ownership_by_checkout_id
261
261
262
First, attempts to find a Koha::Issue-object by C<$issue_id>. If we find one,
262
First, attempts to find a Koha::Checkout-object by C<$issue_id>. If we find one,
263
compare its borrowernumber to currently logged in C<$user>. However, if an issue
263
compare its borrowernumber to currently logged in C<$user>. However, if an issue
264
is not found, attempt to find a Koha::OldIssue-object instead and compare its
264
is not found, attempt to find a Koha::OldIssue-object instead and compare its
265
borrowernumber to currently logged in C<$user>.
265
borrowernumber to currently logged in C<$user>.
Lines 269-275 borrowernumber to currently logged in C<$user>. Link Here
269
sub _object_ownership_by_checkout_id {
269
sub _object_ownership_by_checkout_id {
270
    my ($c, $user, $issue_id) = @_;
270
    my ($c, $user, $issue_id) = @_;
271
271
272
    my $issue = Koha::Issues->find($issue_id);
272
    my $issue = Koha::Checkouts->find($issue_id);
273
    $issue = Koha::OldIssues->find($issue_id) unless $issue;
273
    $issue = Koha::OldIssues->find($issue_id) unless $issue;
274
    return $issue && $issue->borrowernumber
274
    return $issue && $issue->borrowernumber
275
            && $user->borrowernumber == $issue->borrowernumber;
275
            && $user->borrowernumber == $issue->borrowernumber;
(-)a/t/db_dependent/Circulation.t (-2 / +2 lines)
Lines 1049-1055 subtest 'CanBookBeIssued & AllowReturnToBranch' => sub { Link Here
1049
    set_userenv($holdingbranch);
1049
    set_userenv($holdingbranch);
1050
1050
1051
    my $issue = AddIssue( $patron_1, $item->{barcode} );
1051
    my $issue = AddIssue( $patron_1, $item->{barcode} );
1052
    is( ref($issue), 'Koha::Schema::Result::Issue' );    # FIXME Should be Koha::Issue
1052
    is( ref($issue), 'Koha::Schema::Result::Issue' );    # FIXME Should be Koha::Checkout
1053
1053
1054
    my ( $error, $question, $alerts );
1054
    my ( $error, $question, $alerts );
1055
1055
Lines 1138-1144 subtest 'AddIssue & AllowReturnToBranch' => sub { Link Here
1138
1138
1139
    set_userenv($holdingbranch);
1139
    set_userenv($holdingbranch);
1140
1140
1141
    my $ref_issue = 'Koha::Schema::Result::Issue'; # FIXME Should be Koha::Issue
1141
    my $ref_issue = 'Koha::Schema::Result::Issue'; # FIXME Should be Koha::Checkout
1142
    my $issue = AddIssue( $patron_1, $item->{barcode} );
1142
    my $issue = AddIssue( $patron_1, $item->{barcode} );
1143
1143
1144
    my ( $error, $question, $alerts );
1144
    my ( $error, $question, $alerts );
(-)a/t/db_dependent/Koha/Issues.t (-60 lines)
Lines 1-60 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2015 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 4;
23
24
use Koha::Issue;
25
use Koha::Issues;
26
use Koha::Database;
27
28
use t::lib::TestBuilder;
29
30
my $schema = Koha::Database->new->schema;
31
$schema->storage->txn_begin;
32
33
my $builder      = t::lib::TestBuilder->new;
34
my $patron       = $builder->build( { source => 'Borrower' } );
35
my $item_1       = $builder->build( { source => 'Item' } );
36
my $item_2       = $builder->build( { source => 'Item' } );
37
my $nb_of_issues = Koha::Issues->search->count;
38
my $new_issue_1  = Koha::Issue->new(
39
    {   borrowernumber => $patron->{borrowernumber},
40
        itemnumber     => $item_1->{itemnumber},
41
    }
42
)->store;
43
my $new_issue_2 = Koha::Issue->new(
44
    {   borrowernumber => $patron->{borrowernumber},
45
        itemnumber     => $item_2->{itemnumber},
46
    }
47
)->store;
48
49
like( $new_issue_1->issue_id, qr|^\d+$|, 'Adding a new issue should have set the issue_id' );
50
is( Koha::Issues->search->count, $nb_of_issues + 2, 'The 2 issues should have been added' );
51
52
my $retrieved_issue_1 = Koha::Issues->find( $new_issue_1->issue_id );
53
is( $retrieved_issue_1->itemnumber, $new_issue_1->itemnumber, 'Find a issue by id should return the correct issue' );
54
55
$retrieved_issue_1->delete;
56
is( Koha::Issues->search->count, $nb_of_issues + 1, 'Delete should delete the issue' );
57
58
$schema->storage->txn_rollback;
59
60
1;
(-)a/t/db_dependent/Koha/Patrons.t (-4 / +4 lines)
Lines 146-156 subtest 'has_overdues' => sub { Link Here
146
    is( $retrieved_patron->has_overdues, 0, );
146
    is( $retrieved_patron->has_overdues, 0, );
147
147
148
    my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 );
148
    my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 );
149
    my $issue = Koha::Issue->new({ borrowernumber => $new_patron_1->id, itemnumber => $item_1->{itemnumber}, date_due => $tomorrow, branchcode => $library->{branchcode} })->store();
149
    my $issue = Koha::Checkout->new({ borrowernumber => $new_patron_1->id, itemnumber => $item_1->{itemnumber}, date_due => $tomorrow, branchcode => $library->{branchcode} })->store();
150
    is( $retrieved_patron->has_overdues, 0, );
150
    is( $retrieved_patron->has_overdues, 0, );
151
    $issue->delete();
151
    $issue->delete();
152
    my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 );
152
    my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 );
153
    $issue = Koha::Issue->new({ borrowernumber => $new_patron_1->id, itemnumber => $item_1->{itemnumber}, date_due => $yesterday, branchcode => $library->{branchcode} })->store();
153
    $issue = Koha::Checkout->new({ borrowernumber => $new_patron_1->id, itemnumber => $item_1->{itemnumber}, date_due => $yesterday, branchcode => $library->{branchcode} })->store();
154
    $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber );
154
    $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber );
155
    is( $retrieved_patron->has_overdues, 1, );
155
    is( $retrieved_patron->has_overdues, 1, );
156
    $issue->delete();
156
    $issue->delete();
Lines 468-479 subtest 'get_overdues' => sub { Link Here
468
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
468
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
469
    my $overdues = $patron->get_overdues;
469
    my $overdues = $patron->get_overdues;
470
    is( $overdues->count, 2, 'Patron should have 2 overdues');
470
    is( $overdues->count, 2, 'Patron should have 2 overdues');
471
    is( ref($overdues), 'Koha::Issues', 'Koha::Patron->get_overdues should return Koha::Issues' );
471
    is( ref($overdues), 'Koha::Checkouts', 'Koha::Patron->get_overdues should return Koha::Checkouts' );
472
    is( $overdues->next->itemnumber, $item_1->{itemnumber}, 'The issue should be returned in the same order as they have been done, first is correct' );
472
    is( $overdues->next->itemnumber, $item_1->{itemnumber}, 'The issue should be returned in the same order as they have been done, first is correct' );
473
    is( $overdues->next->itemnumber, $item_2->{itemnumber}, 'The issue should be returned in the same order as they have been done, second is correct' );
473
    is( $overdues->next->itemnumber, $item_2->{itemnumber}, 'The issue should be returned in the same order as they have been done, second is correct' );
474
474
475
    # Clean stuffs
475
    # Clean stuffs
476
    Koha::Issues->search( { borrowernumber => $patron->borrowernumber } )->delete;
476
    Koha::Checkouts->search( { borrowernumber => $patron->borrowernumber } )->delete;
477
    $patron->delete;
477
    $patron->delete;
478
};
478
};
479
479
(-)a/t/db_dependent/Template/Plugin/Categories.t (-3 / +2 lines)
Lines 21-27 use Test::More tests => 4; Link Here
21
use t::lib::TestBuilder;
21
use t::lib::TestBuilder;
22
22
23
use Koha::Patron::Categories;
23
use Koha::Patron::Categories;
24
use Koha::Issues;
24
use Koha::Checkouts;
25
use Koha::Patrons;
25
use Koha::Patrons;
26
use Koha::Database;
26
use Koha::Database;
27
use Koha::Template::Plugin::Categories;
27
use Koha::Template::Plugin::Categories;
Lines 30-36 my $schema = Koha::Database->new->schema; Link Here
30
$schema->storage->txn_begin;
30
$schema->storage->txn_begin;
31
31
32
# Delete all categories
32
# Delete all categories
33
Koha::Issues->search->delete;
33
Koha::Checkouts->search->delete;
34
Koha::Patrons->search->delete;
34
Koha::Patrons->search->delete;
35
Koha::Patron::Categories->search->delete;
35
Koha::Patron::Categories->search->delete;
36
36
37
- 

Return to bug 17796