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

(-)a/Koha/Item.pm (+16 lines)
Lines 25-30 use Koha::Database; Link Here
25
use Koha::DateUtils qw( dt_from_string );
25
use Koha::DateUtils qw( dt_from_string );
26
26
27
use C4::Context;
27
use C4::Context;
28
use Koha::Checkouts;
28
use Koha::IssuingRules;
29
use Koha::IssuingRules;
29
use Koha::Item::Transfer;
30
use Koha::Item::Transfer;
30
use Koha::Patrons;
31
use Koha::Patrons;
Lines 106-111 sub biblioitem { Link Here
106
    return Koha::Biblioitem->_new_from_dbic( $biblioitem_rs );
107
    return Koha::Biblioitem->_new_from_dbic( $biblioitem_rs );
107
}
108
}
108
109
110
=head3 checkout
111
112
my $checkout = $item->checkout;
113
114
Return the checkout for this item
115
116
=cut
117
118
sub checkout {
119
    my ( $self ) = @_;
120
    my $checkout_rs = $self->_result->issue;
121
    return unless $checkout_rs;
122
    return Koha::Checkout->_new_from_dbic( $checkout_rs );
123
}
124
109
=head3 get_transfer
125
=head3 get_transfer
110
126
111
my $transfer = $item->get_transfer;
127
my $transfer = $item->get_transfer;
(-)a/t/db_dependent/Koha/Items.t (-2 / +29 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 7;
22
use Test::More tests => 8;
23
23
24
use C4::Circulation;
24
use C4::Circulation;
25
use Koha::Item;
25
use Koha::Item;
Lines 41-46 my $new_item_1 = Koha::Item->new( Link Here
41
        homebranch       => $library->{branchcode},
41
        homebranch       => $library->{branchcode},
42
        holdingbranch    => $library->{branchcode},
42
        holdingbranch    => $library->{branchcode},
43
        barcode          => "a_barcode_for_t",
43
        barcode          => "a_barcode_for_t",
44
        itype            => 'BK',
44
    }
45
    }
45
)->store;
46
)->store;
46
my $new_item_2 = Koha::Item->new(
47
my $new_item_2 = Koha::Item->new(
Lines 49-57 my $new_item_2 = Koha::Item->new( Link Here
49
        homebranch       => $library->{branchcode},
50
        homebranch       => $library->{branchcode},
50
        holdingbranch    => $library->{branchcode},
51
        holdingbranch    => $library->{branchcode},
51
        barcode          => "another_barcode_for_t",
52
        barcode          => "another_barcode_for_t",
53
        itype            => 'BK',
52
    }
54
    }
53
)->store;
55
)->store;
54
56
57
C4::Context->_new_userenv('xxx');
58
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Midway Public Library', '', '', '');
59
55
like( $new_item_1->itemnumber, qr|^\d+$|, 'Adding a new item should have set the itemnumber' );
60
like( $new_item_1->itemnumber, qr|^\d+$|, 'Adding a new item should have set the itemnumber' );
56
is( Koha::Items->search->count, $nb_of_items + 2, 'The 2 items should have been added' );
61
is( Koha::Items->search->count, $nb_of_items + 2, 'The 2 items should have been added' );
57
62
Lines 90-95 subtest 'biblioitem' => sub { Link Here
90
    is( $biblioitem->biblionumber, $retrieved_item_1->biblionumber, 'Koha::Item->biblioitem should return the correct biblioitem' );
95
    is( $biblioitem->biblionumber, $retrieved_item_1->biblionumber, 'Koha::Item->biblioitem should return the correct biblioitem' );
91
};
96
};
92
97
98
subtest 'checkout' => sub {
99
    plan tests => 5;
100
    my $item = Koha::Items->find( $new_item_1->itemnumber );
101
    # No checkout yet
102
    my $checkout = $item->checkout;
103
    is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no current checkout on this item' );
104
105
    # Add a checkout
106
    my $patron = $builder->build({ source => 'Borrower' });
107
    C4::Circulation::AddIssue( $patron, $item->barcode );
108
    $checkout = $retrieved_item_1->checkout;
109
    is( ref( $checkout ), 'Koha::Checkout', 'Koha::Item->checkout should return a Koha::Checkout' );
110
    is( $checkout->itemnumber, $item->itemnumber, 'Koha::Item->checkout should return the correct checkout' );
111
    is( $checkout->borrowernumber, $patron->{borrowernumber}, 'Koha::Item->checkout should return the correct checkout' );
112
113
    # Do the return
114
    C4::Circulation::AddReturn( $item->barcode );
115
116
    # There is no more checkout on this item, making sure it will not return old checkouts
117
    $checkout = $item->checkout;
118
    is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no *current* checkout on this item' );
119
};
120
93
$retrieved_item_1->delete;
121
$retrieved_item_1->delete;
94
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' );
122
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' );
95
123
96
- 

Return to bug 18402