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

(-)a/Koha/Checkout.pm (-2 / +54 lines)
Lines 21-29 package Koha::Checkout; Link Here
21
use Modern::Perl;
21
use Modern::Perl;
22
22
23
use Carp;
23
use Carp;
24
use DateTime;
25
use Try::Tiny;
24
26
27
use Koha::Checkouts::ReturnClaims;
25
use Koha::Database;
28
use Koha::Database;
26
use DateTime;
27
use Koha::DateUtils;
29
use Koha::DateUtils;
28
use Koha::Items;
30
use Koha::Items;
29
31
Lines 35-41 Koha::Checkout - Koha Checkout object class Link Here
35
37
36
=head1 API
38
=head1 API
37
39
38
=head2 Class Methods
40
=head2 Class methods
39
41
40
=cut
42
=cut
41
43
Lines 109-114 sub to_api_mapping { Link Here
109
    };
111
    };
110
}
112
}
111
113
114
=head3 claim_returned
115
116
my $return_claim = $checkout->claim_returned();
117
118
=cut
119
120
sub claim_returned {
121
    my ( $self, $params ) = @_;
122
123
    my $charge_lost_fee = $params->{charge_lost_fee};
124
125
    try {
126
        $self->_result->result_source->schema->txn_do(
127
            sub {
128
                my $claim = Koha::Checkouts::ReturnClaim->new(
129
                    {
130
                        issue_id       => $self->id,
131
                        itemnumber     => $self->itemnumber,
132
                        borrowernumber => $self->borrowernumber,
133
                        notes          => $params->{notes},
134
                        created_by     => $params->{created_by},
135
                        created_on     => dt_from_string,
136
                    }
137
                )->store();
138
139
                my $ClaimReturnedLostValue = C4::Context->preference('ClaimReturnedLostValue');
140
                C4::Items::ModItem( { itemlost => $ClaimReturnedLostValue }, undef, $self->itemnumber );
141
142
                my $ClaimReturnedChargeFee = C4::Context->preference('ClaimReturnedChargeFee');
143
                $charge_lost_fee =
144
                    $ClaimReturnedChargeFee eq 'charge'    ? 1
145
                : $ClaimReturnedChargeFee eq 'no_charge' ? 0
146
                :   $charge_lost_fee;    # $ClaimReturnedChargeFee eq 'ask'
147
                C4::Circulation::LostItem( $self->itemnumber, 'claim_returned' ) if $charge_lost_fee;
148
149
                return $claim;
150
            }
151
        );
152
    }
153
    catch {
154
        if ( $_->isa('Koha::Exceptions::Exception') ) {
155
            $_->rethrow();
156
        }
157
        else {
158
            # ?
159
            Koha::Exceptions::Exception->throw( "Unhandled exception" );
160
        }
161
    };
162
}
163
112
=head2 Internal methods
164
=head2 Internal methods
113
165
114
=head3 _type
166
=head3 _type
(-)a/t/db_dependent/Circulation/ReturnClaims.t (-1 / +96 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 => 1;
21
use Test::MockModule;
22
use Test::Warn;
23
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
26
27
use C4::Circulation;
28
29
# Mock userenv, used by AddIssue
30
my $branch;
31
my $manager_id;
32
my $context = Test::MockModule->new('C4::Context');
33
$context->mock(
34
    'userenv',
35
    sub {
36
        return {
37
            branch    => $branch,
38
            number    => $manager_id,
39
            firstname => "Adam",
40
            surname   => "Smaith"
41
        };
42
    }
43
);
44
45
my $schema = Koha::Database->schema;
46
$schema->storage->txn_begin;
47
48
my $builder = t::lib::TestBuilder->new();
49
Koha::IssuingRules->search->delete;
50
my $rule = Koha::IssuingRule->new(
51
    {
52
        categorycode => '*',
53
        itemtype     => '*',
54
        branchcode   => '*',
55
        issuelength  => 1,
56
    }
57
);
58
$rule->store();
59
60
$branch = $builder->build( { source => 'Branch' } )->{branchcode};
61
62
subtest 'Test Koha::Checkout::claim_returned' => sub {
63
    plan tests => 6;
64
65
    t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 );
66
    my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
67
    my $item   = $builder->build_object(
68
        {
69
            class => 'Koha::Items',
70
            value => {
71
                biblionumber => $biblio->biblionumber,
72
                notforloan   => 0,
73
                itemlost     => 0,
74
                withdrawn    => 0,
75
            }
76
        }
77
    );
78
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
79
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
80
81
    my $claim = $checkout->claim_returned(
82
        {
83
            created_by => $patron->id,
84
            notes      => "Test note",
85
        }
86
    );
87
88
    is( $claim->issue_id, $checkout->id, "Claim issue id matches" );
89
    is( $claim->itemnumber, $item->id, "Claim itemnumber matches" );
90
    is( $claim->borrowernumber, $patron->id, "Claim borrowernumber matches" );
91
    is( $claim->notes, "Test note", "Claim notes match" );
92
    is( $claim->created_by, $patron->id, "Claim created_by matches" );
93
    ok( $claim->created_on, "Claim created_on is set" );
94
};
95
96
$schema->storage->txn_rollback;

Return to bug 14697