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

(-)a/Koha/Checkout.pm (+26 lines)
Lines 29-34 use Koha::Database; Link Here
29
use Koha::DateUtils;
29
use Koha::DateUtils;
30
use Koha::Items;
30
use Koha::Items;
31
31
32
use Koha::Exceptions::Object;
33
32
use base qw(Koha::Object);
34
use base qw(Koha::Object);
33
35
34
=head1 NAME
36
=head1 NAME
Lines 103-108 sub patron { Link Here
103
    return Koha::Patron->_new_from_dbic( $patron_rs );
105
    return Koha::Patron->_new_from_dbic( $patron_rs );
104
}
106
}
105
107
108
=head3 store
109
110
my $checkout = $checkout->store
111
112
Overrides the default store subroutine.
113
114
=cut
115
116
sub store {
117
    my ( $self ) = @_;
118
119
    my $checkout_type = $self->checkout_type;
120
    if ( $checkout_type ) {
121
        unless ( Koha::Checkouts::is_valid_checkout_type( $checkout_type ) ) {
122
            Koha::Exceptions::Object::FKConstraint->throw(
123
                broken_fk => 'checkout_type',
124
                value     => $self->checkout_type,
125
            );
126
        }
127
    }
128
129
    return $self->SUPER::store();
130
}
131
106
=head3 to_api_mapping
132
=head3 to_api_mapping
107
133
108
This method returns the mapping for representing a Koha::Checkout object
134
This method returns the mapping for representing a Koha::Checkout object
(-)a/Koha/Checkouts.pm (+20 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Carp;
22
use Carp;
23
23
24
use C4::Context;
24
use C4::Context;
25
use Koha::AuthorisedValues;
25
use Koha::Checkout;
26
use Koha::Checkout;
26
use Koha::Database;
27
use Koha::Database;
27
28
Lines 54-61 sub calculate_dropbox_date { Link Here
54
    return $dropbox_date;
55
    return $dropbox_date;
55
}
56
}
56
57
58
=head3 is_valid_checkout_type
59
60
my $valid_checkout_type = Koha::Checkouts::is_valid_checkout_type( $type );
61
62
Checks authorised values for valid checkout types.
63
57
=cut
64
=cut
58
65
66
sub is_valid_checkout_type {
67
    my ( $type ) = @_;
68
69
    return 1 if not defined $type; # undefined refers to normal checkout
70
71
    my $av = Koha::AuthorisedValues->search({
72
        category         => 'CHECKOUT_TYPE',
73
        authorised_value => $type,
74
    });
75
76
    return $av->count ? 1 : 0;
77
}
78
59
=head2 Name to code mappings
79
=head2 Name to code mappings
60
80
61
=head3 $type
81
=head3 $type
(-)a/t/db_dependent/Koha/Checkouts.t (-2 / +52 lines)
Lines 19-28 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 9;
22
use Test::More tests => 10;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use C4::Circulation;
25
use C4::Circulation;
26
use Koha::AuthorisedValues;
27
use Koha::AuthorisedValueCategories;
26
use Koha::Checkouts;
28
use Koha::Checkouts;
27
use Koha::Database;
29
use Koha::Database;
28
use Koha::DateUtils qw( dt_from_string );
30
use Koha::DateUtils qw( dt_from_string );
Lines 141-146 subtest 'patron' => sub { Link Here
141
    );
143
    );
142
};
144
};
143
145
146
subtest 'store' => sub {
147
    plan tests => 1;
148
149
    subtest 'validate checkout_type' => sub {
150
        plan tests => 3;
151
152
        # This should exist on clean installations, but just make sure...
153
        unless ( Koha::AuthorisedValueCategories->search( {
154
            category_name => 'CHECKOUT_TYPE'
155
        } )->count ) {
156
            $builder->build_object( {
157
                class=> 'Koha::AuthorisedValueCategories',
158
                value => { category_name => 'CHECKOUT_TYPE' }
159
            } );
160
        }
161
162
        my $av = $builder->build_object( {
163
            class=> 'Koha::AuthorisedValues',
164
            value => { category => 'CHECKOUT_TYPE' }
165
        } );
166
167
        my $patron = $builder->build_object( {
168
            class=> 'Koha::Patrons',
169
            value => { branchcode => $library->{branchcode} }
170
        } );
171
        my $item   = $builder->build_object( { class=> 'Koha::Items' } );
172
        my $checkout = Koha::Checkout->new(
173
            {   borrowernumber => $patron->borrowernumber,
174
                itemnumber     => $item->itemnumber,
175
                branchcode     => $library->{branchcode},
176
            }
177
        )->store;
178
179
        ok( $checkout->issue_id > 0,
180
            'store() was successful with undef checkout_type' );
181
182
        $checkout->set({ checkout_type => $av->authorised_value })->store;
183
        is( $checkout->checkout_type, $av->authorised_value,
184
            'store() was successful with a valid checkout_type' );
185
186
        throws_ok {
187
            $checkout->set({ checkout_type => 'NON_EXISTENT' })->store
188
        } 'Koha::Exceptions::Object::FKConstraint',
189
          'store() throws an exception with an invalid checkout_type';
190
191
        $checkout->delete;
192
    };
193
};
194
144
$retrieved_checkout_1->delete;
195
$retrieved_checkout_1->delete;
145
is( Koha::Checkouts->search->count, $nb_of_checkouts + 1, 'Delete should have deleted the checkout' );
196
is( Koha::Checkouts->search->count, $nb_of_checkouts + 1, 'Delete should have deleted the checkout' );
146
197
147
- 

Return to bug 25037