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 92-97 sub biblio { Link Here
92
    return Koha::Biblio->_new_from_dbic( $biblio_rs );
93
    return Koha::Biblio->_new_from_dbic( $biblio_rs );
93
}
94
}
94
95
96
=head3 checkout
97
98
my $checkout = $item->checkout;
99
100
Return the checkout for this item
101
102
=cut
103
104
sub checkout {
105
    my ( $self ) = @_;
106
    my $checkout_rs = $self->_result->issue;
107
    return unless $checkout_rs;
108
    return Koha::Checkout->_new_from_dbic( $checkout_rs );
109
}
110
95
=head3 get_transfer
111
=head3 get_transfer
96
112
97
my $transfer = $item->get_transfer;
113
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 => 6;
22
use Test::More tests => 7;
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 82-87 subtest 'biblio' => sub { Link Here
82
    is( $biblio->biblionumber, $retrieved_item_1->biblionumber, 'Koha::Item->biblio should return the correct biblio' );
87
    is( $biblio->biblionumber, $retrieved_item_1->biblionumber, 'Koha::Item->biblio should return the correct biblio' );
83
};
88
};
84
89
90
subtest 'checkout' => sub {
91
    plan tests => 5;
92
    my $item = Koha::Items->find( $new_item_1->itemnumber );
93
    # No checkout yet
94
    my $checkout = $item->checkout;
95
    is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no current checkout on this item' );
96
97
    # Add a checkout
98
    my $patron = $builder->build({ source => 'Borrower' });
99
    C4::Circulation::AddIssue( $patron, $item->barcode );
100
    $checkout = $retrieved_item_1->checkout;
101
    is( ref( $checkout ), 'Koha::Checkout', 'Koha::Item->checkout should return a Koha::Checkout' );
102
    is( $checkout->itemnumber, $item->itemnumber, 'Koha::Item->checkout should return the correct checkout' );
103
    is( $checkout->borrowernumber, $patron->{borrowernumber}, 'Koha::Item->checkout should return the correct checkout' );
104
105
    # Do the return
106
    C4::Circulation::AddReturn( $item->barcode );
107
108
    # There is no more checkout on this item, making sure it will not return old checkouts
109
    $checkout = $item->checkout;
110
    is( $checkout, undef, 'Koha::Item->checkout should return undef if there is no *current* checkout on this item' );
111
};
112
85
$retrieved_item_1->delete;
113
$retrieved_item_1->delete;
86
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' );
114
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' );
87
115
88
- 

Return to bug 18402