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

(-)a/Koha/ArticleRequest.pm (-1 / +24 lines)
Lines 19-25 package Koha::ArticleRequest; Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
22
use Koha::Account::Lines;
23
use Koha::Database;
23
use Koha::Database;
24
use Koha::Patrons;
24
use Koha::Patrons;
25
use Koha::Biblios;
25
use Koha::Biblios;
Lines 57-62 sub request { Link Here
57
    ) unless $self->borrower->can_request_article;
57
    ) unless $self->borrower->can_request_article;
58
58
59
    $self->status(Koha::ArticleRequest::Status::Requested);
59
    $self->status(Koha::ArticleRequest::Status::Requested);
60
61
    # Handle possible fees
62
    my $debit = $self->borrower->add_article_request_fee_if_needed({ item_id => $self->itemnumber });
63
    $self->debit_id( $debit->id )
64
        if $debit;
65
60
    $self->store();
66
    $self->store();
61
    $self->notify();
67
    $self->notify();
62
    return $self;
68
    return $self;
Lines 149-154 sub biblio { Link Here
149
    return $self->{_biblio};
155
    return $self->{_biblio};
150
}
156
}
151
157
158
=head3 debit
159
160
    my $debit = $article_request->debit;
161
162
Returns the related Koha::Account::Line object for this article request
163
164
=cut
165
166
sub debit {
167
    my ($self) = @_;
168
169
    my $debit_rs = $self->_result->debit;
170
    return unless $debit_rs;
171
172
    return Koha::Account::Line->_new_from_dbic( $debit_rs );
173
}
174
152
=head3 item
175
=head3 item
153
176
154
Returns the Koha::Item object for this article request
177
Returns the Koha::Item object for this article request
(-)a/t/db_dependent/Koha/ArticleRequest.t (-4 / +31 lines)
Lines 30-41 my $builder = t::lib::TestBuilder->new; Link Here
30
30
31
subtest 'request() tests' => sub {
31
subtest 'request() tests' => sub {
32
32
33
    plan tests => 3;
33
    plan tests => 11;
34
34
35
    $schema->storage->txn_begin;
35
    $schema->storage->txn_begin;
36
36
37
    my $amount = 0;
38
39
    my $patron_mock = Test::MockModule->new('Koha::Patron');
40
    $patron_mock->mock( 'article_request_fee', sub { return $amount; } );
41
37
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
42
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
38
    my $biblio = $builder->build_sample_biblio;
43
    my $item   = $builder->build_sample_item;
39
44
40
    my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
45
    my $ar_mock = Test::MockModule->new('Koha::ArticleRequest');
41
    $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } );
46
    $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } );
Lines 43-57 subtest 'request() tests' => sub { Link Here
43
    my $ar = Koha::ArticleRequest->new(
48
    my $ar = Koha::ArticleRequest->new(
44
        {
49
        {
45
            borrowernumber => $patron->id,
50
            borrowernumber => $patron->id,
46
            biblionumber   => $biblio->id,
51
            biblionumber   => $item->biblionumber,
52
        }
53
    );
54
55
    $ar->request()->discard_changes;
56
57
    is( $ar->status, Koha::ArticleRequest::Status::Requested );
58
    ok( defined $ar->created_on, 'created_on is set' );
59
60
    is( $ar->debit_id, undef, 'No fee linked' );
61
    is( $patron->account->balance, 0, 'No outstanding fees' );
62
63
    # set a fee amount
64
    $amount = 10;
65
66
    $ar = Koha::ArticleRequest->new(
67
        {
68
            borrowernumber => $patron->id,
69
            biblionumber   => $item->biblionumber,
70
            itemnumber     => $item->id,
47
        }
71
        }
48
    );
72
    );
49
73
50
    $ar->request()->discard_changes;
74
    $ar->request()->discard_changes;
51
75
52
    is( $ar->status, Koha::ArticleRequest::Status::Requested );
76
    is( $ar->status, Koha::ArticleRequest::Status::Requested );
77
    is( $ar->itemnumber, $item->id, 'itemnumber set' );
53
    ok( defined $ar->created_on, 'created_on is set' );
78
    ok( defined $ar->created_on, 'created_on is set' );
54
79
80
    ok( defined $ar->debit_id, 'Fee linked' );
81
    is( $patron->account->balance, $amount, 'Outstanding fees with the right value' );
82
55
    $schema->storage->txn_rollback;
83
    $schema->storage->txn_rollback;
56
};
84
};
57
85
58
- 

Return to bug 27946