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

(-)a/Koha/Patron.pm (-2 / +19 lines)
Lines 29-35 use Koha::DateUtils; Link Here
29
use Koha::Issues;
29
use Koha::Issues;
30
use Koha::OldIssues;
30
use Koha::OldIssues;
31
use Koha::Patron::Categories;
31
use Koha::Patron::Categories;
32
use Koha::Patron::HouseboundProfiles;
32
use Koha::Patron::HouseboundProfile;
33
use Koha::Patron::HouseboundRole;
33
use Koha::Patron::Images;
34
use Koha::Patron::Images;
34
use Koha::Patrons;
35
use Koha::Patrons;
35
36
Lines 85-92 Returns the HouseboundProfile associated with this patron. Link Here
85
86
86
sub housebound_profile {
87
sub housebound_profile {
87
    my ( $self ) = @_;
88
    my ( $self ) = @_;
89
    my $profile = $self->_result->housebound_profile;
90
    return Koha::Patron::HouseboundProfile->_new_from_dbic($profile)
91
        if ( $profile );
92
    return 0;
93
}
94
95
=head3 housebound_role
96
97
Returns the HouseboundRole associated with this patron.
98
99
=cut
100
101
sub housebound_role {
102
    my ( $self ) = @_;
88
103
89
    return Koha::Patron::HouseboundProfiles->find($self->borrowernumber);
104
    my $role = $self->_result->housebound_role;
105
    return Koha::Patron::HouseboundRole->_new_from_dbic($role) if ( $role );
106
    return 0;
90
}
107
}
91
108
92
=head3 siblings
109
=head3 siblings
(-)a/Koha/Patrons.pm (-8 / +6 lines)
Lines 45-54 Returns all Patrons which are Housebound choosers. Link Here
45
45
46
sub search_housebound_choosers {
46
sub search_housebound_choosers {
47
    my ( $self ) = @_;
47
    my ( $self ) = @_;
48
    my $cho = $self->_resultset->search
48
    my $cho = $self->_resultset
49
        ->search_related('borrower_attributes', {
49
        ->search_related('housebound_role', {
50
            code => 'HSBND',
50
            housebound_chooser => 1,
51
            attribute => 'CHO',
52
        })->search_related('borrowernumber');
51
        })->search_related('borrowernumber');
53
    return Koha::Patrons->_new_from_dbic($cho);
52
    return Koha::Patrons->_new_from_dbic($cho);
54
}
53
}
Lines 61-70 Returns all Patrons which are Housebound deliverers. Link Here
61
60
62
sub search_housebound_deliverers {
61
sub search_housebound_deliverers {
63
    my ( $self ) = @_;
62
    my ( $self ) = @_;
64
    my $del = $self->_resultset->search
63
    my $del = $self->_resultset
65
        ->search_related('borrower_attributes', {
64
        ->search_related('housebound_role', {
66
            code => 'HSBND',
65
            housebound_deliverer => 1,
67
            attribute => 'DEL',
68
        })->search_related('borrowernumber');
66
        })->search_related('borrowernumber');
69
    return Koha::Patrons->_new_from_dbic($del);
67
    return Koha::Patrons->_new_from_dbic($del);
70
}
68
}
(-)a/t/db_dependent/Patron/Housebound.t (-37 / +1 lines)
Lines 6-12 use C4::Circulation; Link Here
6
use Koha::Database;
6
use Koha::Database;
7
use Koha::Patrons;
7
use Koha::Patrons;
8
8
9
use Test::More tests => 6;
9
use Test::More tests => 2;
10
10
11
use_ok('Koha::Patron');
11
use_ok('Koha::Patron');
12
12
Lines 34-75 is( Link Here
34
    "Fetch housebound_profile."
34
    "Fetch housebound_profile."
35
);
35
);
36
36
37
# patron_choosers and patron_deliverers Tests
38
39
# Current Patron Chooser / Deliverer count
40
my $orig_del_count = Koha::Patrons->search_housebound_deliverers->count;
41
my $orig_cho_count = Koha::Patrons->search_housebound_choosers->count;
42
43
# We add one, just in case the above is 0, so we're guaranteed one of each.
44
my $patron_chooser = $builder->build({ source => 'Borrower' });
45
$builder->build({
46
    source => 'BorrowerAttribute',
47
    value  => {
48
        borrowernumber => $patron_chooser->{borrowernumber},
49
        code           => 'HSBND',
50
        attribute      => 'CHO',
51
        password       => undef,
52
    },
53
});
54
55
my $patron_deliverer = $builder->build({ source => 'Borrower' });
56
$builder->build({
57
    source => 'BorrowerAttribute',
58
    value  => {
59
        borrowernumber => $patron_deliverer->{borrowernumber},
60
        code           => 'HSBND',
61
        attribute      => 'DEL',
62
        password       => undef,
63
    },
64
});
65
66
# Test search_housebound_choosers
67
is(Koha::Patrons->search_housebound_choosers->count, $orig_cho_count + 1, "Correct count of choosers.");
68
is(Koha::Patrons->search_housebound_deliverers->count, $orig_del_count + 1, "Correct count of deliverers");
69
70
isa_ok(Koha::Patrons->search_housebound_choosers->next, "Koha::Patron");
71
isa_ok(Koha::Patrons->search_housebound_deliverers->next, "Koha::Patron");
72
73
$schema->storage->txn_rollback;
37
$schema->storage->txn_rollback;
74
38
75
1;
39
1;
(-)a/t/db_dependent/Patron/HouseboundRoles.t (-1 / +88 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 6;
21
22
use Koha::Database;
23
use Koha::Patron::HouseboundRoles;
24
use Koha::Patrons;
25
26
use t::lib::TestBuilder;
27
28
my $schema = Koha::Database->new->schema;
29
$schema->storage->txn_begin;
30
31
my $builder = t::lib::TestBuilder->new;
32
33
# Profile Tests
34
35
my $role = $builder->build({ source => 'HouseboundRole' });
36
37
is(
38
    Koha::Patron::HouseboundRoles
39
          ->find($role->{borrowernumber_id})->borrowernumber_id,
40
    $role->{borrowernumber_id},
41
    "Find created role."
42
);
43
44
my @roles = Koha::Patron::HouseboundRoles
45
    ->search({ borrowernumber_id => $role->{borrowernumber_id} });
46
my $found_role = shift @roles;
47
is(
48
    $found_role->borrowernumber_id,
49
    $role->{borrowernumber_id},
50
    "Search for created role."
51
);
52
53
# patron_choosers and patron_deliverers Tests
54
55
# Current Patron Chooser / Deliverer count
56
my $orig_del_count = Koha::Patrons->search_housebound_deliverers->count;
57
my $orig_cho_count = Koha::Patrons->search_housebound_choosers->count;
58
59
# We add one, just in case the above is 0, so we're guaranteed one of each.
60
my $patron_chooser = $builder->build({ source => 'Borrower' });
61
$builder->build({
62
    source => 'HouseboundRole',
63
    value  => {
64
        borrowernumber_id  => $patron_chooser->{borrowernumber},
65
        housebound_chooser => 1,
66
    },
67
});
68
69
my $patron_deliverer = $builder->build({ source => 'Borrower' });
70
$builder->build({
71
    source => 'HouseboundRole',
72
    value  => {
73
        borrowernumber_id    => $patron_deliverer->{borrowernumber},
74
        housebound_deliverer => 1,
75
    },
76
});
77
78
# Test search_housebound_choosers
79
is(Koha::Patrons->search_housebound_choosers->count, $orig_cho_count + 1, "Correct count of choosers.");
80
is(Koha::Patrons->search_housebound_deliverers->count, $orig_del_count + 1, "Correct count of deliverers");
81
82
isa_ok(Koha::Patrons->search_housebound_choosers->next, "Koha::Patron");
83
isa_ok(Koha::Patrons->search_housebound_deliverers->next, "Koha::Patron");
84
85
86
$schema->storage->txn_rollback;
87
88
1;

Return to bug 5670