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

(-)a/C4/Items.pm (-15 / +8 lines)
Lines 28-34 BEGIN { Link Here
28
28
29
    @EXPORT = qw(
29
    @EXPORT = qw(
30
        AddItemFromMarc
30
        AddItemFromMarc
31
        AddItem
32
        AddItemBatchFromMarc
31
        AddItemBatchFromMarc
33
        ModItemFromMarc
32
        ModItemFromMarc
34
        Item2Marc
33
        Item2Marc
Lines 160-168 sub AddItemFromMarc { Link Here
160
159
161
    my $localitemmarc = MARC::Record->new;
160
    my $localitemmarc = MARC::Record->new;
162
    $localitemmarc->append_fields( $source_item_marc->field($itemtag) );
161
    $localitemmarc->append_fields( $source_item_marc->field($itemtag) );
162
163
#RMME
163
    my $item = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' );
164
    my $item = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' );
164
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
165
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
165
    return AddItem( $item, $biblionumber, $dbh, $frameworkcode, $unlinked_item_subfields );
166
    return AddItem( $item, $biblionumber, $dbh, $frameworkcode, $unlinked_item_subfields );
167
168
    my $item_values = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' );
169
    $item_values->{biblionumber} = $biblionumber;
170
    # FIXME RM my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
171
    my $item = Koha::Item->new( $item_values ); # FIXME Handle $unlinked_item_subfields
172
    return ( $item->biblionumber, $item->biblioitemnumber, $item->itemnumber );
166
}
173
}
167
174
168
=head2 AddItem
175
=head2 AddItem
Lines 191-219 sub AddItem { Link Here
191
    my $biblionumber = shift;
198
    my $biblionumber = shift;
192
199
193
    my $dbh           = @_ ? shift : C4::Context->dbh;
200
    my $dbh           = @_ ? shift : C4::Context->dbh;
194
    my $frameworkcode = @_ ? shift : C4::Biblio::GetFrameworkCode($biblionumber);
195
    my $unlinked_item_subfields;
201
    my $unlinked_item_subfields;
196
    if (@_) {
202
    if (@_) {
197
        $unlinked_item_subfields = shift;
203
        $unlinked_item_subfields = shift;
198
    }
204
    }
199
205
200
    # needs old biblionumber and biblioitemnumber
201
    $item->{'biblionumber'} = $biblionumber;
202
    my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
203
    $sth->execute( $item->{'biblionumber'} );
204
    ( $item->{'biblioitemnumber'} ) = $sth->fetchrow;
205
206
    _set_defaults_for_add($item);
206
    _set_defaults_for_add($item);
207
    _set_derived_columns_for_add($item);
207
    _set_derived_columns_for_add($item);
208
    $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields);
208
    $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields);
209
209
210
    # FIXME - checks here
211
    unless ( $item->{itype} ) {    # default to biblioitem.itemtype if no itype
212
        my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
213
        $itype_sth->execute( $item->{'biblionumber'} );
214
        ( $item->{'itype'} ) = $itype_sth->fetchrow_array;
215
    }
216
217
    my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} );
210
    my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} );
218
    return if $error;
211
    return if $error;
219
212
(-)a/Koha/EDI.pm (-10 / +9 lines)
Lines 29-35 use C4::Context; Link Here
29
use Koha::Database;
29
use Koha::Database;
30
use C4::Acquisition qw( NewBasket CloseBasket ModOrder);
30
use C4::Acquisition qw( NewBasket CloseBasket ModOrder);
31
use C4::Suggestions qw( ModSuggestion );
31
use C4::Suggestions qw( ModSuggestion );
32
use C4::Items qw(AddItem);
33
use C4::Biblio qw( AddBiblio TransformKohaToMarc GetMarcBiblio GetFrameworkCode GetMarcFromKohaField );
32
use C4::Biblio qw( AddBiblio TransformKohaToMarc GetMarcBiblio GetFrameworkCode GetMarcFromKohaField );
34
use Koha::Edifact::Order;
33
use Koha::Edifact::Order;
35
use Koha::Edifact;
34
use Koha::Edifact;
Lines 718-726 sub quote_item { Link Here
718
717
719
            my $created = 0;
718
            my $created = 0;
720
            while ( $created < $order_quantity ) {
719
            while ( $created < $order_quantity ) {
721
                my $itemnumber;
720
                $item_hash->{biblionumber} = $bib->{biblionumber};
722
                ( $bib->{biblionumber}, $bib->{biblioitemnumber}, $itemnumber )
721
                my $item = Koha::Item->new( $item_hash )
723
                  = AddItem( $item_hash, $bib->{biblionumber} );
722
                my $itemnumber = $item->itemnumber;
724
                $logger->trace("Added item:$itemnumber");
723
                $logger->trace("Added item:$itemnumber");
725
                $schema->resultset('AqordersItem')->create(
724
                $schema->resultset('AqordersItem')->create(
726
                    {
725
                    {
Lines 809-817 sub quote_item { Link Here
809
                        $item_hash->{homebranch} = $new_item->{homebranch};
808
                        $item_hash->{homebranch} = $new_item->{homebranch};
810
                    }
809
                    }
811
810
812
                    my $itemnumber;
811
                    $item_hash->{biblionumber} = $bib->{biblionumber};
813
                    ( undef, undef, $itemnumber ) =
812
                    my $item = Koha::Item->new( $item_hash )
814
                      AddItem( $item_hash, $bib->{biblionumber} );
813
                    my $itemnumber = $item->itemnumber;
815
                    $logger->trace("New item $itemnumber added");
814
                    $logger->trace("New item $itemnumber added");
816
                    $schema->resultset('AqordersItem')->create(
815
                    $schema->resultset('AqordersItem')->create(
817
                        {
816
                        {
Lines 878-886 sub quote_item { Link Here
878
                          $item->girfield( 'branch', $occurrence ),
877
                          $item->girfield( 'branch', $occurrence ),
879
                        homebranch => $item->girfield( 'branch', $occurrence ),
878
                        homebranch => $item->girfield( 'branch', $occurrence ),
880
                    };
879
                    };
881
                    my $itemnumber;
880
                    $new_item->{biblionumber} = $bib->{biblionumber};
882
                    ( undef, undef, $itemnumber ) =
881
                    my $item = Koha::Item->new( $new_item )
883
                      AddItem( $new_item, $bib->{biblionumber} );
882
                    my $itemnumber = $item->itemnumber;
884
                    $logger->trace("New item $itemnumber added");
883
                    $logger->trace("New item $itemnumber added");
885
                    $schema->resultset('AqordersItem')->create(
884
                    $schema->resultset('AqordersItem')->create(
886
                        {
885
                        {
(-)a/Koha/Item.pm (+35 lines)
Lines 48-53 Koha::Item - Koha Item object class Link Here
48
48
49
=cut
49
=cut
50
50
51
=head3 store
52
53
=cut
54
55
sub store {
56
    my ($self) = @_;
57
58
    # We do not want to oblige callers to pass this value
59
    # Dev conveniences vs performance?
60
    unless ( $self->biblioitemnumber ) {
61
        $self->biblioitemnumber( $self->biblio->biblioitem->biblioitemnumber );
62
    }
63
64
    # See related changes from C4::Items::AddItem
65
    unless ( $self->itype ) {
66
        $self->itype($self->biblio->biblioitem->itemtype);
67
    }
68
69
    unless ( $self->in_storage ) { #AddItem
70
        my $today = dt_from_string;
71
        unless ( $self->permanent_location ) {
72
            $self->permanent_location($self->location);
73
        }
74
        unless ( $self->replacementpricedate ) {
75
            $self->replacementpricedate($today);
76
        }
77
        unless ( $self->datelastseen ) {
78
            $self->datelastseen($today);
79
        }
80
81
    }
82
83
    return $self->SUPER::store;
84
}
85
51
=head3 effective_itemtype
86
=head3 effective_itemtype
52
87
53
Returns the itemtype for the item based on whether item level itemtypes are set or not.
88
Returns the itemtype for the item based on whether item level itemtypes are set or not.
(-)a/acqui/addorderiso2709.pl (-16 / +19 lines)
Lines 220-241 if ($op eq ""){ Link Here
220
        my @itemnumbers;
220
        my @itemnumbers;
221
        for (my $i = 0; $i < $count; $i++) {
221
        for (my $i = 0; $i < $count; $i++) {
222
            $itemcreation = 1;
222
            $itemcreation = 1;
223
            my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({
223
            my $item = Koha::Item->new(
224
                homebranch => $homebranches[$i],
224
                {
225
                holdingbranch => $holdingbranches[$i],
225
                    biblionumber        => $biblionumber,
226
                itemnotes_nonpublic => $nonpublic_notes[$i],
226
                    homebranch          => $homebranches[$i],
227
                itemnotes => $public_notes[$i],
227
                    holdingbranch       => $holdingbranches[$i],
228
                location => $locs[$i],
228
                    itemnotes_nonpublic => $nonpublic_notes[$i],
229
                ccode => $ccodes[$i],
229
                    itemnotes           => $public_notes[$i],
230
                itype => $itypes[$i],
230
                    location            => $locs[$i],
231
                notforloan => $notforloans[$i],
231
                    ccode               => $ccodes[$i],
232
                uri => $uris[$i],
232
                    itype               => $itypes[$i],
233
                copynumber => $copynos[$i],
233
                    notforloan          => $notforloans[$i],
234
                price => $itemprices[$i],
234
                    uri                 => $uris[$i],
235
                replacementprice => $replacementprices[$i],
235
                    copynumber          => $copynos[$i],
236
                itemcallnumber => $itemcallnumbers[$i],
236
                    price               => $itemprices[$i],
237
            }, $biblionumber);
237
                    replacementprice    => $replacementprices[$i],
238
            push( @itemnumbers, $itemnumber );
238
                    itemcallnumber      => $itemcallnumbers[$i],
239
                }
240
            );
241
            push( @itemnumbers, $item->itemnumber );
239
        }
242
        }
240
        if ($itemcreation == 1) {
243
        if ($itemcreation == 1) {
241
            # Group orderlines from MarcItemFieldsToOrder
244
            # Group orderlines from MarcItemFieldsToOrder
(-)a/t/db_dependent/Acquisition.t (-1 / +1 lines)
Lines 536-542 ok(($order4->{cancellationreason} eq "foobar"), "order has cancellation reason \ Link Here
536
ok((not defined Koha::Biblios->find( $order4->{biblionumber} )), "biblio does not exist anymore");
536
ok((not defined Koha::Biblios->find( $order4->{biblionumber} )), "biblio does not exist anymore");
537
537
538
my $order5 = GetOrder($ordernumbers[4]);
538
my $order5 = GetOrder($ordernumbers[4]);
539
C4::Items::AddItem( { barcode => '0102030405' }, $order5->{biblionumber} );
539
Koha::Item->new({ barcode => '0102030405', biblionumber => $order5->{biblionumber} })->store;
540
$error = DelOrder($order5->{biblionumber}, $order5->{ordernumber}, 1);
540
$error = DelOrder($order5->{biblionumber}, $order5->{ordernumber}, 1);
541
$order5 = GetOrder($order5->{ordernumber});
541
$order5 = GetOrder($order5->{ordernumber});
542
ok((defined $order5->{datecancellationprinted}), "order is cancelled");
542
ok((defined $order5->{datecancellationprinted}), "order is cancelled");
(-)a/t/db_dependent/Acquisition/CancelReceipt.t (-3 / +3 lines)
Lines 66-72 my $budgetid = C4::Budgets::AddBudget( Link Here
66
my $budget = C4::Budgets::GetBudget( $budgetid );
66
my $budget = C4::Budgets::GetBudget( $budgetid );
67
67
68
my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
68
my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
69
my $itemnumber = AddItem( { itype => $itemtype }, $biblionumber );
69
my $itemnumber = Koha::Item->new({ itype => $itemtype, biblionumber => $biblionumber })->store->itemnumber;
70
70
71
my $order = Koha::Acquisition::Order->new(
71
my $order = Koha::Acquisition::Order->new(
72
    {
72
    {
Lines 92-99 CancelReceipt($ordernumber); Link Here
92
92
93
is($order->items->count, 0, "Create items on receiving: 0 item exist after cancelling a receipt");
93
is($order->items->count, 0, "Create items on receiving: 0 item exist after cancelling a receipt");
94
94
95
my $itemnumber1 = AddItem( { itype => $itemtype }, $biblionumber );
95
my $itemnumber1 = Koha::Item->new({ itype => $itemtype, biblionumber => $biblionumber })->store->itemnumber;
96
my $itemnumber2 = AddItem( { itype => $itemtype }, $biblionumber );
96
my $itemnumber2 = Koha::Item->new({ itype => $itemtype, biblionumber => $biblionumber })->store->itemnumber;
97
97
98
t::lib::Mocks::mock_preference('AcqCreateItem', 'ordering');
98
t::lib::Mocks::mock_preference('AcqCreateItem', 'ordering');
99
t::lib::Mocks::mock_preference('AcqItemSetSubfieldsWhenReceiptIsCancelled', '7=9'); # notforloan is mapped with 952$7
99
t::lib::Mocks::mock_preference('AcqItemSetSubfieldsWhenReceiptIsCancelled', '7=9'); # notforloan is mapped with 952$7
(-)a/t/db_dependent/Acquisition/TransferOrder.t (-3 / +7 lines)
Lines 12-17 use Koha::Database; Link Here
12
use Koha::DateUtils;
12
use Koha::DateUtils;
13
use Koha::Acquisition::Booksellers;
13
use Koha::Acquisition::Booksellers;
14
use Koha::Acquisition::Orders;
14
use Koha::Acquisition::Orders;
15
use t::lib::TestBuilder;
15
use MARC::Record;
16
use MARC::Record;
16
17
17
my $schema = Koha::Database->new()->schema();
18
my $schema = Koha::Database->new()->schema();
Lines 20-25 $schema->storage->txn_begin(); Link Here
20
my $dbh = C4::Context->dbh;
21
my $dbh = C4::Context->dbh;
21
$dbh->{RaiseError} = 1;
22
$dbh->{RaiseError} = 1;
22
23
24
my $builder = t::lib::TestBuilder->new;
25
23
my $bookseller1 = Koha::Acquisition::Bookseller->new(
26
my $bookseller1 = Koha::Acquisition::Bookseller->new(
24
    {
27
    {
25
        name => "my vendor 1",
28
        name => "my vendor 1",
Lines 55-62 my $budgetid = C4::Budgets::AddBudget( Link Here
55
58
56
my $budget = C4::Budgets::GetBudget( $budgetid );
59
my $budget = C4::Budgets::GetBudget( $budgetid );
57
60
58
my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
61
my $biblio = $builder->build_sample_biblio();
59
my $itemnumber = AddItem({}, $biblionumber);
62
my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
63
my $biblionumber = $biblio->biblionumber;
60
64
61
my $order = Koha::Acquisition::Order->new(
65
my $order = Koha::Acquisition::Order->new(
62
    {
66
    {
Lines 67-73 my $order = Koha::Acquisition::Order->new( Link Here
67
    }
71
    }
68
)->store;
72
)->store;
69
my $ordernumber = $order->ordernumber;
73
my $ordernumber = $order->ordernumber;
70
$order->add_item( $itemnumber );
74
$order->add_item( $item_1->itemnumber );
71
75
72
# Begin tests
76
# Begin tests
73
is(scalar GetOrders($basketno1), 1, "1 order in basket1");
77
is(scalar GetOrders($basketno1), 1, "1 order in basket1");
(-)a/t/db_dependent/Circulation.t (-7 / +8 lines)
Lines 2426-2440 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2426
                }
2426
                }
2427
            }
2427
            }
2428
        );
2428
        );
2429
        my ( undef, undef, $item_id ) = AddItem(
2429
        my $item_id = Koha::Item->new(
2430
            {   homebranch       => $library->branchcode,
2430
            {
2431
                biblionumber     => $biblio->biblionumber,
2432
                homebranch       => $library->branchcode,
2431
                holdingbranch    => $library->branchcode,
2433
                holdingbranch    => $library->branchcode,
2432
                barcode          => $barcode,
2434
                barcode          => $barcode,
2433
                replacementprice => $replacement_amount,
2435
                replacementprice => $replacement_amount,
2434
                itype            => $item_type->itemtype
2436
                itype            => $item_type->itemtype
2435
            },
2437
            },
2436
            $biblio->biblionumber
2438
        )->store->itemnumber;
2437
        );
2438
2439
2439
        AddIssue( $patron->unblessed, $barcode );
2440
        AddIssue( $patron->unblessed, $barcode );
2440
2441
Lines 3011-3026 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
3011
    });
3012
    });
3012
3013
3013
    my $biblio = $builder->build_sample_biblio({ title=> $title, author => $author });
3014
    my $biblio = $builder->build_sample_biblio({ title=> $title, author => $author });
3014
    my ( undef, undef, $item_id ) = AddItem(
3015
    my $item_id = Koha::Item->new(
3015
        {
3016
        {
3017
            biblionumber     => $biblio->biblionumber,
3016
            homebranch       => $library->id,
3018
            homebranch       => $library->id,
3017
            holdingbranch    => $library->id,
3019
            holdingbranch    => $library->id,
3018
            barcode          => $barcode,
3020
            barcode          => $barcode,
3019
            replacementprice => 23.00,
3021
            replacementprice => 23.00,
3020
            itype            => $itemtype->id
3022
            itype            => $itemtype->id
3021
        },
3023
        },
3022
        $biblio->biblionumber
3024
    )->store->itemnumber;
3023
    );
3024
    my $item = Koha::Items->find( $item_id );
3025
    my $item = Koha::Items->find( $item_id );
3025
3026
3026
    my $context = Test::MockModule->new('C4::Context');
3027
    my $context = Test::MockModule->new('C4::Context');
(-)a/t/db_dependent/Circulation/Branch.t (-14 / +11 lines)
Lines 98-140 $record->append_fields( Link Here
98
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' );
98
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' );
99
99
100
# item 1 has home branch and holding branch samplebranch1
100
# item 1 has home branch and holding branch samplebranch1
101
my @sampleitem1 = C4::Items::AddItem(
101
my $item_id1 = Koha::Item->new(
102
    {
102
    {
103
        biblionumber   => $biblionumber,
103
        barcode        => 'barcode_1',
104
        barcode        => 'barcode_1',
104
        itemcallnumber => 'callnumber1',
105
        itemcallnumber => 'callnumber1',
105
        homebranch     => $samplebranch1->{branchcode},
106
        homebranch     => $samplebranch1->{branchcode},
106
        holdingbranch  => $samplebranch1->{branchcode},
107
        holdingbranch  => $samplebranch1->{branchcode},
107
        itype          => $no_circ_itemtype->{ itemtype }
108
        itype          => $no_circ_itemtype->{ itemtype }
108
    },
109
    }
109
    $biblionumber
110
)->store->itemnumber;
110
);
111
my $item_id1    = $sampleitem1[2];
112
111
113
# item 2 has holding branch samplebranch2
112
# item 2 has holding branch samplebranch2
114
my @sampleitem2 = C4::Items::AddItem(
113
my $item_id2 = Koha::Item->new(
115
    {
114
    {
115
        biblionumber   => $biblionumber,
116
        barcode        => 'barcode_2',
116
        barcode        => 'barcode_2',
117
        itemcallnumber => 'callnumber2',
117
        itemcallnumber => 'callnumber2',
118
        homebranch     => $samplebranch2->{branchcode},
118
        homebranch     => $samplebranch2->{branchcode},
119
        holdingbranch  => $samplebranch1->{branchcode},
119
        holdingbranch  => $samplebranch1->{branchcode},
120
        itype          => $no_circ_itemtype->{ itemtype }
120
        itype          => $no_circ_itemtype->{ itemtype }
121
    },
121
    },
122
    $biblionumber
122
)->store->itemnumber;
123
);
124
my $item_id2 = $sampleitem2[2];
125
123
126
# item 3 has item type sampleitemtype2 with noreturn policy
124
# item 3 has item type sampleitemtype2 with noreturn policy
127
my @sampleitem3 = C4::Items::AddItem(
125
my $item_id3 = Koha::Item->new(
128
    {
126
    {
127
        biblionumber   => $biblionumber,
129
        barcode        => 'barcode_3',
128
        barcode        => 'barcode_3',
130
        itemcallnumber => 'callnumber3',
129
        itemcallnumber => 'callnumber3',
131
        homebranch     => $samplebranch2->{branchcode},
130
        homebranch     => $samplebranch2->{branchcode},
132
        holdingbranch  => $samplebranch2->{branchcode},
131
        holdingbranch  => $samplebranch2->{branchcode},
133
        itype          => $sampleitemtype2->{itemtype}
132
        itype          => $sampleitemtype2->{itemtype}
134
    },
133
    }
135
    $biblionumber
134
)->store->itemnumber;
136
);
137
my $item_id3 = $sampleitem3[2];
138
135
139
#Add borrower
136
#Add borrower
140
my $borrower_id1 = Koha::Patron->new({
137
my $borrower_id1 = Koha::Patron->new({
(-)a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t (-2 / +2 lines)
Lines 61-70 my %item_info = ( Link Here
61
61
62
my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
62
my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
63
my $barcode1 = '0101';
63
my $barcode1 = '0101';
64
AddItem({ barcode => $barcode1, %item_info }, $biblionumber1);
64
Koha::Item->new({ barcode => $barcode1, %item_info, biblionumber => $biblionumber1 })->store;
65
my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
65
my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
66
my $barcode2 = '0202';
66
my $barcode2 = '0202';
67
AddItem({ barcode => $barcode2, %item_info }, $biblionumber2);
67
Koha::Item->new({ barcode => $barcode2, %item_info, biblionumber => $biblionumber2 })->store;
68
68
69
my $borrowernumber1 = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode})->store->borrowernumber;
69
my $borrowernumber1 = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode})->store->borrowernumber;
70
my $borrowernumber2 = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode})->store->borrowernumber;
70
my $borrowernumber2 = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode})->store->borrowernumber;
(-)a/t/db_dependent/Circulation/CheckValidBarcode.t (-3 / +3 lines)
Lines 67-76 $check_valid_barcode = C4::Circulation::CheckValidBarcode($barcode3); Link Here
67
is( $check_valid_barcode, 0, 'CheckValidBarcode with an invalid barcode returns true' );
67
is( $check_valid_barcode, 0, 'CheckValidBarcode with an invalid barcode returns true' );
68
68
69
my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
69
my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
70
AddItem({ barcode => $barcode1, %item_branch_infos }, $biblionumber1);
70
Koha::Item->new({ barcode => $barcode1, %item_branch_infos, biblionumber => $biblionumber1})->store;
71
AddItem({ barcode => $barcode2, %item_branch_infos }, $biblionumber1);
71
Koha::Item->new({ barcode => $barcode2, %item_branch_infos, biblionumber => $biblionumber1})->store;
72
my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
72
my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
73
AddItem({ barcode => $barcode3, %item_branch_infos }, $biblionumber2);
73
Koha::Item->new({ barcode => $barcode3, %item_branch_infos, biblionumber =>$biblionumber2})->store;
74
74
75
$check_valid_barcode = C4::Circulation::CheckValidBarcode();
75
$check_valid_barcode = C4::Circulation::CheckValidBarcode();
76
is( $check_valid_barcode, 0, 'CheckValidBarcode without barcode returns false' );
76
is( $check_valid_barcode, 0, 'CheckValidBarcode without barcode returns false' );
(-)a/t/db_dependent/Circulation/GetPendingOnSiteCheckouts.t (-4 / +4 lines)
Lines 50-60 my %item_infos = ( Link Here
50
);
50
);
51
51
52
my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
52
my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
53
my $itemnumber1 = AddItem({ barcode => '0101', %item_infos }, $biblionumber1);
53
my $itemnumber1 = Koha::Item->new({ barcode => '0101', %item_infos, biblionumber => $biblionumber1})->store->itemnumber;
54
my $itemnumber2 = AddItem({ barcode => '0102', %item_infos }, $biblionumber1);
54
my $itemnumber2 = Koha::Item->new({ barcode => '0102', %item_infos, biblionumber => $biblionumber1})->store->itemnumber;
55
55
56
my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
56
my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
57
my $itemnumber3 = AddItem({ barcode => '0203', %item_infos }, $biblionumber2);
57
my $itemnumber3 = Koha::Item->new({ barcode => '0203', %item_infos, biblionumber => $biblionumber2})->store->itemnumber;
58
58
59
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
59
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
60
my $borrowernumber = $builder->build(
60
my $borrowernumber = $builder->build(
Lines 75-81 AddIssue($borrower, '0203'); Link Here
75
my $onsite_checkouts = GetPendingOnSiteCheckouts;
75
my $onsite_checkouts = GetPendingOnSiteCheckouts;
76
is( scalar @$onsite_checkouts, 0, "No pending on-site checkouts" );
76
is( scalar @$onsite_checkouts, 0, "No pending on-site checkouts" );
77
77
78
my $itemnumber4 = AddItem({ barcode => '0104', %item_infos }, $biblionumber1);
78
my $itemnumber4 = Koha::Item->new({ barcode => '0104', %item_infos, biblionumber => $biblionumber1})->store->itemnumber;
79
AddIssue( $borrower, '0104', undef, undef, undef, undef, { onsite_checkout => 1 } );
79
AddIssue( $borrower, '0104', undef, undef, undef, undef, { onsite_checkout => 1 } );
80
$onsite_checkouts = GetPendingOnSiteCheckouts;
80
$onsite_checkouts = GetPendingOnSiteCheckouts;
81
is( scalar @$onsite_checkouts, 1, "There is 1 pending on-site checkout" );
81
is( scalar @$onsite_checkouts, 1, "There is 1 pending on-site checkout" );
(-)a/t/db_dependent/Circulation/GetTopIssues.t (-4 / +6 lines)
Lines 50-66 $c4_context->mock('userenv', sub { Link Here
50
t::lib::Mocks::mock_preference('item-level_itypes', '0');
50
t::lib::Mocks::mock_preference('item-level_itypes', '0');
51
51
52
my $biblionumber = create_biblio('Test 1', $itemtype);
52
my $biblionumber = create_biblio('Test 1', $itemtype);
53
AddItem({
53
Koha::Item->new({
54
    biblionumber => $biblionumber,
54
    barcode => 'GTI_BARCODE_001',
55
    barcode => 'GTI_BARCODE_001',
55
    homebranch => $branch_1->{ branchcode },
56
    homebranch => $branch_1->{ branchcode },
56
    ccode => 'GTI_CCODE',
57
    ccode => 'GTI_CCODE',
57
}, $biblionumber);
58
})->store;
58
59
59
$biblionumber = create_biblio('Test 2', $itemtype);
60
$biblionumber = create_biblio('Test 2', $itemtype);
60
AddItem({
61
Koha::Item->new({
62
    biblionumber => $biblionumber,
61
    barcode => 'GTI_BARCODE_002',
63
    barcode => 'GTI_BARCODE_002',
62
    homebranch => $branch_2->{ branchcode },
64
    homebranch => $branch_2->{ branchcode },
63
}, $biblionumber);
65
})->store;
64
66
65
my $borrowernumber = Koha::Patron->new({
67
my $borrowernumber = Koha::Patron->new({
66
    userid => 'gti.test',
68
    userid => 'gti.test',
(-)a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t (-3 / +3 lines)
Lines 6-12 use MARC::Field; Link Here
6
use C4::Context;
6
use C4::Context;
7
7
8
use C4::Circulation qw( AddIssue AddReturn );
8
use C4::Circulation qw( AddIssue AddReturn );
9
use C4::Items qw( AddItem );
10
use C4::Biblio qw( AddBiblio );
9
use C4::Biblio qw( AddBiblio );
11
use Koha::Database;
10
use Koha::Database;
12
use Koha::DateUtils;
11
use Koha::DateUtils;
Lines 61-72 $record->append_fields( Link Here
61
60
62
my $barcode = 'bc_maxsuspensiondays';
61
my $barcode = 'bc_maxsuspensiondays';
63
my ($biblionumber, $biblioitemnumber) = AddBiblio($record, '');
62
my ($biblionumber, $biblioitemnumber) = AddBiblio($record, '');
64
my (undef, undef, $itemnumber) = AddItem({
63
my $itemnumber = Koha::Item->new({
64
        biblionumber => $biblionumber,
65
        homebranch => $branchcode,
65
        homebranch => $branchcode,
66
        holdingbranch => $branchcode,
66
        holdingbranch => $branchcode,
67
        barcode => $barcode,
67
        barcode => $barcode,
68
        itype => $itemtype
68
        itype => $itemtype
69
    } , $biblionumber);
69
    })->store->itemnumber;
70
70
71
# clear any holidays to avoid throwing off the suspension day
71
# clear any holidays to avoid throwing off the suspension day
72
# calculations
72
# calculations
(-)a/t/db_dependent/Circulation/issue.t (-21 / +14 lines)
Lines 131-162 my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ); Link Here
131
131
132
my $barcode_1 = 'barcode_1';
132
my $barcode_1 = 'barcode_1';
133
my $barcode_2 = 'barcode_2';
133
my $barcode_2 = 'barcode_2';
134
my @sampleitem1 = C4::Items::AddItem(
134
my $item_id1 = Koha::Item->new(
135
    {
135
    {
136
        biblionumber   => $biblionumber,
136
        barcode        => $barcode_1,
137
        barcode        => $barcode_1,
137
        itemcallnumber => 'callnumber1',
138
        itemcallnumber => 'callnumber1',
138
        homebranch     => $branchcode_1,
139
        homebranch     => $branchcode_1,
139
        holdingbranch  => $branchcode_1,
140
        holdingbranch  => $branchcode_1,
140
        issue          => 1,
141
        reserve        => 1,
142
        itype          => $itemtype
141
        itype          => $itemtype
143
    },
142
    },
144
    $biblionumber
143
)->store->itemnumber;
145
);
144
my $item_id2 = Koha::Item->new(
146
my $item_id1    = $sampleitem1[2];
147
my @sampleitem2 = C4::Items::AddItem(
148
    {
145
    {
146
        biblionumber   => $biblionumber,
149
        barcode        => $barcode_2,
147
        barcode        => $barcode_2,
150
        itemcallnumber => 'callnumber2',
148
        itemcallnumber => 'callnumber2',
151
        homebranch     => $branchcode_2,
149
        homebranch     => $branchcode_2,
152
        holdingbranch  => $branchcode_2,
150
        holdingbranch  => $branchcode_2,
153
        notforloan     => 1,
151
        notforloan     => 1,
154
        issue          => 1,
155
        itype          => $itemtype
152
        itype          => $itemtype
156
    },
153
    },
157
    $biblionumber
154
)->store->itemnumber;
158
);
159
my $item_id2 = $sampleitem2[2];
160
155
161
#Add borrower
156
#Add borrower
162
my $borrower_id1 = Koha::Patron->new({
157
my $borrower_id1 = Koha::Patron->new({
Lines 346-354 AddReturn($barcode_1, undef, undef, dt_from_string('2014-04-01 23:42')); Link Here
346
$return = $dbh->selectrow_hashref("SELECT * FROM old_issues LIMIT 1" );
341
$return = $dbh->selectrow_hashref("SELECT * FROM old_issues LIMIT 1" );
347
ok( $return->{returndate} eq '2014-04-01 23:42:00', "Item returned with a return date of '2014-04-01 23:42' has that return date" );
342
ok( $return->{returndate} eq '2014-04-01 23:42:00', "Item returned with a return date of '2014-04-01 23:42' has that return date" );
348
343
349
my $itemnumber;
344
my $itemnumber = Koha::Item->new(
350
($biblionumber, $biblioitemnumber, $itemnumber) = C4::Items::AddItem(
351
    {
345
    {
346
        biblionumber   => $biblionumber,
352
        barcode        => 'barcode_3',
347
        barcode        => 'barcode_3',
353
        itemcallnumber => 'callnumber3',
348
        itemcallnumber => 'callnumber3',
354
        homebranch     => $branchcode_1,
349
        homebranch     => $branchcode_1,
Lines 356-363 my $itemnumber; Link Here
356
        notforloan     => 1,
351
        notforloan     => 1,
357
        itype          => $itemtype
352
        itype          => $itemtype
358
    },
353
    },
359
    $biblionumber
354
)->store->itemnumber;
360
);
361
355
362
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} );
356
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} );
363
AddReturn( 'barcode_3', $branchcode_1 );
357
AddReturn( 'barcode_3', $branchcode_1 );
Lines 373-390 AddReturn( 'barcode_3', $branchcode_1 ); Link Here
373
$item = Koha::Items->find( $itemnumber );
367
$item = Koha::Items->find( $itemnumber );
374
ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} );
368
ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} );
375
369
376
my $itemnumber2;
370
my $itemnumber2 = Koha::Item->new(
377
($biblionumber, $biblioitemnumber, $itemnumber2) = C4::Items::AddItem(
378
    {
371
    {
372
        biblionumber   => $biblionumber,
379
        barcode        => 'barcode_4',
373
        barcode        => 'barcode_4',
380
        itemcallnumber => 'callnumber4',
374
        itemcallnumber => 'callnumber4',
381
        homebranch     => $branchcode_1,
375
        homebranch     => $branchcode_1,
382
        holdingbranch  => $branchcode_1,
376
        holdingbranch  => $branchcode_1,
383
        location => 'FIC',
377
        location       => 'FIC',
384
        itype          => $itemtype
378
        itype          => $itemtype
385
    },
379
    }
386
    $biblionumber
380
)->store->itemnumber;
387
);
388
381
389
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', q{} );
382
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', q{} );
390
AddReturn( 'barcode_4', $branchcode_1 );
383
AddReturn( 'barcode_4', $branchcode_1 );
(-)a/t/db_dependent/Circulation/transfers.t (-10 / +10 lines)
Lines 69-94 $record->append_fields( Link Here
69
    MARC::Field->new( '952', '0', '0', a => $branchcode_1 ) );
69
    MARC::Field->new( '952', '0', '0', a => $branchcode_1 ) );
70
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', );
70
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', );
71
71
72
my @sampleitem1 = C4::Items::AddItem(
72
my $item_id1 = Koha::Item->new(
73
    {   barcode        => 1,
73
    {
74
        biblionumber   => $biblionumber,
75
        barcode        => 1,
74
        itemcallnumber => 'callnumber1',
76
        itemcallnumber => 'callnumber1',
75
        homebranch     => $branchcode_1,
77
        homebranch     => $branchcode_1,
76
        holdingbranch  => $branchcode_1,
78
        holdingbranch  => $branchcode_1,
77
        itype          => $itemtype
79
        itype          => $itemtype
78
    },
80
    },
79
    $biblionumber
81
)->store->itemnumber;
80
);
82
my $item_id2 = Koha::Item->new(
81
my $item_id1    = $sampleitem1[2];
83
    {
82
my @sampleitem2 = C4::Items::AddItem(
84
        biblionumber   => $biblionumber,
83
    {   barcode        => 2,
85
        barcode        => 2,
84
        itemcallnumber => 'callnumber2',
86
        itemcallnumber => 'callnumber2',
85
        homebranch     => $branchcode_1,
87
        homebranch     => $branchcode_1,
86
        holdingbranch  => $branchcode_1,
88
        holdingbranch  => $branchcode_1,
87
        itype          => $itemtype
89
        itype          => $itemtype
88
    },
90
    },
89
    $biblionumber
91
)->store->itemnumber;
90
);
91
my $item_id2 = $sampleitem2[2];
92
92
93
#Add transfers
93
#Add transfers
94
ModItemTransfer(
94
ModItemTransfer(
(-)a/t/db_dependent/CourseReserves.t (-6 / +6 lines)
Lines 17-29 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 27;
20
use Test::More tests => 26;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
24
25
BEGIN {
25
BEGIN {
26
    use_ok('C4::Items', qw(AddItem));
27
    use_ok('C4::Biblio');
26
    use_ok('C4::Biblio');
28
    use_ok('C4::CourseReserves', qw/:all/);
27
    use_ok('C4::CourseReserves', qw/:all/);
29
    use_ok('C4::Context');
28
    use_ok('C4::Context');
Lines 50-62 foreach (1..10) { Link Here
50
# Create the a record with an item
49
# Create the a record with an item
51
my $record = MARC::Record->new;
50
my $record = MARC::Record->new;
52
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
51
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
53
my ( undef, undef, $itemnumber ) = C4::Items::AddItem(
52
my $itemnumber = Koha::Item->new(
54
    {   homebranch    => $branchcode,
53
    {
54
        biblionumber  => $biblionumber,
55
        homebranch    => $branchcode,
55
        holdingbranch => $branchcode,
56
        holdingbranch => $branchcode,
56
        itype         => $itemtype
57
        itype         => $itemtype
57
    },
58
    },
58
    $biblionumber
59
)->store->itemnumber;
59
);
60
60
61
my $course_id = ModCourse(
61
my $course_id = ModCourse(
62
    course_name => "Test Course",
62
    course_name => "Test Course",
(-)a/t/db_dependent/Holds.t (-44 / +21 lines)
Lines 58-65 $insert_sth->execute('ONLY1'); Link Here
58
my $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
58
my $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
59
59
60
# Create item instance for testing.
60
# Create item instance for testing.
61
my ($item_bibnum, $item_bibitemnum, $itemnumber)
61
my $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
62
    = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
63
62
64
# Create some borrowers
63
# Create some borrowers
65
my @borrowernumbers;
64
my @borrowernumbers;
Lines 152-158 is( $hold->suspend_until, '2013-01-01 00:00:00', "Test ModReserve, suspend until Link Here
152
151
153
ModReserve({ # call without reserve_id
152
ModReserve({ # call without reserve_id
154
    rank          => '3',
153
    rank          => '3',
155
    biblionumber  => $item_bibnum,
154
    biblionumber  => $biblio->biblionumber,
156
    itemnumber    => $itemnumber,
155
    itemnumber    => $itemnumber,
157
    borrowernumber => $borrowernumber,
156
    borrowernumber => $borrowernumber,
158
});
157
});
Lines 241-248 is( $hold->priority, '6', "Test AlterPriority(), move to bottom" ); Link Here
241
# IndependentBranches is OFF.
240
# IndependentBranches is OFF.
242
241
243
my $foreign_biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
242
my $foreign_biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
244
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber)
243
my $foreign_itemnumber = $builder->build_sample_item({ library => $branch_2, biblionumber => $foreign_biblio->biblionumber })->itemnumber;
245
  = AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber);
246
$dbh->do('DELETE FROM issuingrules');
244
$dbh->do('DELETE FROM issuingrules');
247
$dbh->do(
245
$dbh->do(
248
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
246
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 284-296 ok( Link Here
284
);
282
);
285
283
286
{
284
{
285
    my $item_bibnum;my $item_bibitemnum;
287
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
286
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
288
    $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
287
    $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
289
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
288
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
290
    my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1);
289
    my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1);
291
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
290
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
292
    my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2);
291
    my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2);
293
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
292
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
294
    my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3);
293
    my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3);
295
    my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber });
294
    my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber });
296
    my $hold3 = Koha::Holds->find( $reserveid3 );
295
    my $hold3 = Koha::Holds->find( $reserveid3 );
Lines 300-306 ok( Link Here
300
    is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
299
    is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
301
}
300
}
302
301
303
ModItem({ damaged => 1 }, $item_bibnum, $itemnumber);
302
ModItem({ damaged => 1 }, $biblio->biblionumber, $itemnumber);
304
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
303
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
305
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" );
304
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" );
306
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" );
305
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" );
Lines 309-315 $hold = Koha::Hold->new( Link Here
309
    {
308
    {
310
        borrowernumber => $borrowernumbers[0],
309
        borrowernumber => $borrowernumbers[0],
311
        itemnumber     => $itemnumber,
310
        itemnumber     => $itemnumber,
312
        biblionumber   => $item_bibnum,
311
        biblionumber   => $biblio->biblionumber,
313
    }
312
    }
314
)->store();
313
)->store();
315
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
314
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
Lines 323-329 ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for d Link Here
323
322
324
# Regression test for bug 9532
323
# Regression test for bug 9532
325
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
324
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
326
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
325
$itemnumber = $builder->build_sample_item({ library => $branch_1, itype => 'CANNOT', biblionumber => $biblio->biblionumber})->itemnumber;
327
AddReserve(
326
AddReserve(
328
    $branch_1,
327
    $branch_1,
329
    $borrowernumbers[0],
328
    $borrowernumbers[0],
Lines 335-348 is( Link Here
335
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves',
334
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves',
336
    "cannot request item if policy that matches on item-level item type forbids it"
335
    "cannot request item if policy that matches on item-level item type forbids it"
337
);
336
);
338
ModItem({ itype => 'CAN' }, $item_bibnum, $itemnumber);
337
ModItem({ itype => 'CAN' }, $biblio->biblionumber, $itemnumber);
339
ok(
338
ok(
340
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK',
339
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK',
341
    "can request item if policy that matches on item type allows it"
340
    "can request item if policy that matches on item type allows it"
342
);
341
);
343
342
344
t::lib::Mocks::mock_preference('item-level_itypes', 0);
343
t::lib::Mocks::mock_preference('item-level_itypes', 0);
345
ModItem({ itype => undef }, $item_bibnum, $itemnumber);
344
ModItem({ itype => undef }, $biblio->biblionumber, $itemnumber);
346
ok(
345
ok(
347
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves',
346
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves',
348
    "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)"
347
    "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)"
Lines 382-395 Koha::CirculationRules->set_rules( Link Here
382
    }
381
    }
383
);
382
);
384
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
383
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
385
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
384
$itemnumber = $builder->build_sample_item({ library => $branch_1, itype => 'CANNOT', biblionumber => $biblio->biblionumber})->itemnumber;
386
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
387
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable',
385
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable',
388
    "CanItemBeReserved should return 'notReservable'");
386
    "CanItemBeReserved should return 'notReservable'");
389
387
390
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
388
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
391
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
389
$itemnumber = $builder->build_sample_item({ library => $branch_2, itype => 'CAN', biblionumber => $biblio->biblionumber})->itemnumber;
392
    { homebranch => $branch_2, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber);
393
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
390
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
394
    'cannotReserveFromOtherBranches',
391
    'cannotReserveFromOtherBranches',
395
    "CanItemBeReserved should use PatronLibrary rule when ReservesControlBranch set to 'PatronLibrary'");
392
    "CanItemBeReserved should use PatronLibrary rule when ReservesControlBranch set to 'PatronLibrary'");
Lines 398-405 is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, Link Here
398
    'OK',
395
    'OK',
399
    "CanItemBeReserved should use item home library rule when ReservesControlBranch set to 'ItemsHomeLibrary'");
396
    "CanItemBeReserved should use item home library rule when ReservesControlBranch set to 'ItemsHomeLibrary'");
400
397
401
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
398
$itemnumber = $builder->build_sample_item({ library => $branch_1, itype => 'CAN', biblionumber => $biblio->biblionumber})->itemnumber;
402
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber);
403
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK',
399
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK',
404
    "CanItemBeReserved should return 'OK'");
400
    "CanItemBeReserved should return 'OK'");
405
401
Lines 413-420 $dbh->do('DELETE FROM items'); Link Here
413
$dbh->do('DELETE FROM biblio');
409
$dbh->do('DELETE FROM biblio');
414
410
415
$biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
411
$biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
416
( $item_bibnum, $item_bibitemnum, $itemnumber )
412
$itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber})->itemnumber;
417
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
418
413
419
$dbh->do(
414
$dbh->do(
420
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
415
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 445-453 subtest 'Test max_holds per library/patron category' => sub { Link Here
445
    $dbh->do('DELETE FROM circulation_rules');
440
    $dbh->do('DELETE FROM circulation_rules');
446
441
447
    $biblio = $builder->build_sample_biblio({ itemtype => 'TEST' });
442
    $biblio = $builder->build_sample_biblio({ itemtype => 'TEST' });
448
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
443
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber})->itemnumber;
449
      AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
450
        $biblio->biblionumber );
451
    $dbh->do(
444
    $dbh->do(
452
        q{
445
        q{
453
            INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
446
            INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 515-522 subtest 'Pickup location availability tests' => sub { Link Here
515
    plan tests => 4;
508
    plan tests => 4;
516
509
517
    $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
510
    $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
518
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
511
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber})->itemnumber;
519
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
520
    #Add a default rule to allow some holds
512
    #Add a default rule to allow some holds
521
    $dbh->do(
513
    $dbh->do(
522
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
514
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 572-597 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
572
564
573
    # Create 3 biblios with items
565
    # Create 3 biblios with items
574
    my $biblio_1 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
566
    my $biblio_1 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
575
    my ( undef, undef, $itemnumber_1 ) = AddItem(
567
    my $itemnumber_1 = $builder->build_sample_item({ library => $library->branchcode, biblionumber => $biblio_1->biblionumber})->itemnumber;
576
        {   homebranch    => $library->branchcode,
577
            holdingbranch => $library->branchcode
578
        },
579
        $biblio_1->biblionumber
580
    );
581
    my $biblio_2 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
568
    my $biblio_2 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
582
    my ( undef, undef, $itemnumber_2 ) = AddItem(
569
    my $itemnumber_2 = $builder->build_sample_item({ library => $library->branchcode, biblionumber => $biblio_2->biblionumber})->itemnumber;
583
        {   homebranch    => $library->branchcode,
584
            holdingbranch => $library->branchcode
585
        },
586
        $biblio_2->biblionumber
587
    );
588
    my $biblio_3 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
570
    my $biblio_3 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
589
    my ( undef, undef, $itemnumber_3 ) = AddItem(
571
    my $itemnumber_3 = $builder->build_sample_item({ library => $library->branchcode, biblionumber => $biblio_3->biblionumber})->itemnumber;
590
        {   homebranch    => $library->branchcode,
591
            holdingbranch => $library->branchcode
592
        },
593
        $biblio_3->biblionumber
594
    );
595
572
596
    Koha::IssuingRules->search->delete;
573
    Koha::IssuingRules->search->delete;
597
    my $issuingrule = Koha::IssuingRule->new(
574
    my $issuingrule = Koha::IssuingRule->new(
(-)a/t/db_dependent/Holds/LocalHoldsPriority.t (-4 / +5 lines)
Lines 41-53 my $itemtype = $builder->build( Link Here
41
my $borrowers_count = 5;
41
my $borrowers_count = 5;
42
42
43
my $biblio = $builder->build_sample_biblio();
43
my $biblio = $builder->build_sample_biblio();
44
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
44
my $itemnumber = Koha::Item->new(
45
    {   homebranch    => $library4->{branchcode},
45
    {
46
        biblionumber  => $biblio->biblionumber,
47
        homebranch    => $library4->{branchcode},
46
        holdingbranch => $library3->{branchcode},
48
        holdingbranch => $library3->{branchcode},
47
        itype         => $itemtype
49
        itype         => $itemtype
48
    },
50
    },
49
    $biblio->biblionumber,
51
)->store->itemnumber;
50
);
51
52
52
53
53
my @branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode}, $library4->{branchcode}, $library3->{branchcode}, $library4->{branchcode} );
54
my @branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode}, $library4->{branchcode}, $library3->{branchcode}, $library4->{branchcode} );
(-)a/t/db_dependent/Holds/RevertWaitingStatus.t (-4 / +5 lines)
Lines 48-61 my $borrowers_count = 3; Link Here
48
48
49
my $biblio = $builder->build_sample_biblio();
49
my $biblio = $builder->build_sample_biblio();
50
my $item_barcode = 'my_barcode';
50
my $item_barcode = 'my_barcode';
51
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
51
my $itemnumber = Koha::Item->new(
52
    {   homebranch    => $branchcode,
52
    {
53
        biblionumber  => $biblio->biblionumber,
54
        homebranch    => $branchcode,
53
        holdingbranch => $branchcode,
55
        holdingbranch => $branchcode,
54
        barcode       => $item_barcode,
56
        barcode       => $item_barcode,
55
        itype         => $itemtype
57
        itype         => $itemtype
56
    },
58
    },
57
    $biblio->biblionumber,
59
)->store->itemnumber;
58
);
59
60
60
# Create some borrowers
61
# Create some borrowers
61
my $patron_category = $builder->build({ source => 'Category' });
62
my $patron_category = $builder->build({ source => 'Category' });
(-)a/t/db_dependent/Items.t (-52 / +77 lines)
Lines 60-73 subtest 'General Add, Get and Del tests' => sub { Link Here
60
    my $biblio = $builder->build_sample_biblio();
60
    my $biblio = $builder->build_sample_biblio();
61
61
62
    # Add an item.
62
    # Add an item.
63
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber);
63
    my $item = $builder->build_sample_item(
64
    cmp_ok($item_bibnum, '==', $biblio->biblionumber, "New item is linked to correct biblionumber.");
64
        {
65
    cmp_ok($item_bibitemnum, '==', $biblio->biblioitem->biblioitemnumber, "New item is linked to correct biblioitemnumber.");
65
            biblionumber => $biblio->biblionumber,
66
            library      => $library->{branchcode},
67
            location     => $location,
68
            itype        => $itemtype->{itemtype}
69
        }
70
    );
71
    my $itemnumber = $item->itemnumber;
72
    cmp_ok($item->biblionumber, '==', $biblio->biblionumber, "New item is linked to correct biblionumber.");
73
    cmp_ok($item->biblioitemnumber, '==', $biblio->biblioitem->biblioitemnumber, "New item is linked to correct biblioitemnumber.");
66
74
67
    # Get item.
75
    # Get item.
68
    my $getitem = Koha::Items->find($itemnumber);
76
    my $getitem = Koha::Items->find($itemnumber);
69
    cmp_ok($getitem->itemnumber, '==', $itemnumber, "Retrieved item has correct itemnumber.");
77
    cmp_ok($getitem->itemnumber, '==', $itemnumber, "Retrieved item has correct itemnumber.");
70
    cmp_ok($getitem->biblioitemnumber, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber.");
78
    cmp_ok($getitem->biblioitemnumber, '==', $item->biblioitemnumber, "Retrieved item has correct biblioitemnumber."); # We are not testing anything useful here
71
    is( $getitem->location, $location, "The location should not have been modified" );
79
    is( $getitem->location, $location, "The location should not have been modified" );
72
    is( $getitem->permanent_location, $location, "The permanent_location should have been set to the location value" );
80
    is( $getitem->permanent_location, $location, "The permanent_location should have been set to the location value" );
73
81
Lines 87-93 subtest 'General Add, Get and Del tests' => sub { Link Here
87
    my $getdeleted = Koha::Items->find($itemnumber);
95
    my $getdeleted = Koha::Items->find($itemnumber);
88
    is($getdeleted, undef, "Item deleted as expected.");
96
    is($getdeleted, undef, "Item deleted as expected.");
89
97
90
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $biblio->biblionumber);
98
    $itemnumber = $builder->build_sample_item(
99
        {
100
            biblionumber => $biblio->biblionumber,
101
            library      => $library->{branchcode},
102
            location     => $location,
103
            permanent_location => 'my permanent location',
104
            itype        => $itemtype->{itemtype}
105
        }
106
    )->itemnumber;
91
    $getitem = Koha::Items->find($itemnumber);
107
    $getitem = Koha::Items->find($itemnumber);
92
    is( $getitem->location, $location, "The location should not have been modified" );
108
    is( $getitem->location, $location, "The location should not have been modified" );
93
    is( $getitem->permanent_location, 'my permanent location', "The permanent_location should not have modified" );
109
    is( $getitem->permanent_location, 'my permanent location', "The permanent_location should not have modified" );
Lines 172-196 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
172
    my $biblio = $builder->build_sample_biblio();
188
    my $biblio = $builder->build_sample_biblio();
173
189
174
    # Add two items
190
    # Add two items
175
    my ( $item1_bibnum, $item1_bibitemnum, $item1_itemnumber ) = AddItem(
191
    my $item1_itemnumber = $builder->build_sample_item(
176
        {
192
        {
177
            homebranch    => $library1->{branchcode},
193
            biblionumber => $biblio->biblionumber,
178
            holdingbranch => $library1->{branchcode},
194
            library      => $library1->{branchcode},
179
            withdrawn     => 1,
195
            withdrawn    => 1,
180
            itype         => $itemtype->{itemtype},
196
            itype        => $itemtype->{itemtype}
181
        },
197
        }
182
        $biblio->biblionumber
198
    )->itemnumber;
183
    );
199
    my $item2_itemnumber = $builder->build_sample_item(
184
    my ( $item2_bibnum, $item2_bibitemnum, $item2_itemnumber ) = AddItem(
185
        {
200
        {
186
            homebranch    => $library2->{branchcode},
201
            biblionumber => $biblio->biblionumber,
187
            holdingbranch => $library2->{branchcode},
202
            library      => $library2->{branchcode},
188
            withdrawn     => 0,
203
            withdrawn    => 0,
189
            itype         => $itemtype->{itemtype},
204
            itype        => $itemtype->{itemtype}
190
        },
205
        }
191
        $biblio->biblionumber
206
    )->itemnumber;
192
    );
193
194
    my $opachiddenitems;
207
    my $opachiddenitems;
195
    my @itemnumbers = ($item1_itemnumber,$item2_itemnumber);
208
    my @itemnumbers = ($item1_itemnumber,$item2_itemnumber);
196
    my @hidden;
209
    my @hidden;
Lines 279-293 subtest 'GetItemsInfo tests' => sub { Link Here
279
    # Add a biblio
292
    # Add a biblio
280
    my $biblio = $builder->build_sample_biblio();
293
    my $biblio = $builder->build_sample_biblio();
281
    # Add an item
294
    # Add an item
282
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
295
    my $itemnumber = $builder->build_sample_item(
283
        {
296
        {
297
            biblionumber  => $biblio->biblionumber,
284
            homebranch    => $library1->{branchcode},
298
            homebranch    => $library1->{branchcode},
285
            holdingbranch => $library2->{branchcode},
299
            holdingbranch => $library2->{branchcode},
286
            itype         => $itemtype->{itemtype},
300
            itype         => $itemtype->{itemtype},
287
            restricted    => 1,
301
            restricted    => 1,
288
        },
302
        }
289
        $biblio->biblionumber
303
    )->itemnumber;
290
    );
291
304
292
    my $library = Koha::Libraries->find( $library1->{branchcode} );
305
    my $library = Koha::Libraries->find( $library1->{branchcode} );
293
    $library->opac_info("homebranch OPAC info");
306
    $library->opac_info("homebranch OPAC info");
Lines 316-322 subtest 'GetItemsInfo tests' => sub { Link Here
316
    t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckout', 0 );
329
    t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckout', 0 );
317
    #place item into holds queue
330
    #place item into holds queue
318
    my $dbh = C4::Context->dbh;
331
    my $dbh = C4::Context->dbh;
319
    $dbh->do(q{INSERT INTO tmp_holdsqueue (biblionumber, itemnumber, surname, borrowernumber ) VALUES (?, ?, "Zorro", 42)}, undef, $item_bibnum, $itemnumber);
332
    $dbh->do(q{INSERT INTO tmp_holdsqueue (biblionumber, itemnumber, surname, borrowernumber ) VALUES (?, ?, "Zorro", 42)}, undef, $biblio->biblionumber, $itemnumber);
320
    @results = GetItemsInfo( $biblio->biblionumber );
333
    @results = GetItemsInfo( $biblio->biblionumber );
321
    is( $results[0]->{ has_pending_hold }, "1",
334
    is( $results[0]->{ has_pending_hold }, "1",
322
        'Hold marked as pending/unavailable if not AllowItemsOnHoldCheckout' );
335
        'Hold marked as pending/unavailable if not AllowItemsOnHoldCheckout' );
Lines 395-410 subtest 'SearchItems test' => sub { Link Here
395
    my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
408
    my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
396
409
397
    # Add two items
410
    # Add two items
398
    my (undef, undef, $item1_itemnumber) = AddItem({
411
    my $item1_itemnumber = $builder->build_sample_item(
399
        homebranch => $library1->{branchcode},
412
        {
400
        holdingbranch => $library1->{branchcode},
413
            biblionumber => $biblio->biblionumber,
401
        itype => $itemtype->{itemtype},
414
            library      => $library1->{branchcode},
402
    }, $biblio->biblionumber);
415
            itype        => $itemtype->{itemtype}
403
    my (undef, undef, $item2_itemnumber) = AddItem({
416
        }
404
        homebranch => $library2->{branchcode},
417
    )->itemnumber;
405
        holdingbranch => $library2->{branchcode},
418
    my $item2_itemnumber = $builder->build_sample_item(
406
        itype => $itemtype->{itemtype},
419
        {
407
    }, $biblio->biblionumber);
420
            biblionumber => $biblio->biblionumber,
421
            library      => $library2->{branchcode},
422
            itype        => $itemtype->{itemtype}
423
        }
424
    )->itemnumber;
408
425
409
    my ($items, $total_results);
426
    my ($items, $total_results);
410
427
Lines 567-581 subtest 'Koha::Item(s) tests' => sub { Link Here
567
584
568
    # Create a biblio and item for testing
585
    # Create a biblio and item for testing
569
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
586
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
570
    my $biblio = $builder->build_sample_biblio({title => 'Silence in the library'});
587
    my $biblio = $builder->build_sample_biblio();
571
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
588
    my $itemnumber = $builder->build_sample_item(
572
        {
589
        {
590
            biblionumber  => $biblio->biblionumber,
573
            homebranch    => $library1->{branchcode},
591
            homebranch    => $library1->{branchcode},
574
            holdingbranch => $library2->{branchcode},
592
            holdingbranch => $library2->{branchcode},
575
            itype         => $itemtype->{itemtype},
593
            itype         => $itemtype->{itemtype}
576
        },
594
        }
577
        $biblio->biblionumber
595
    )->itemnumber;
578
    );
579
596
580
    # Get item.
597
    # Get item.
581
    my $item = Koha::Items->find( $itemnumber );
598
    my $item = Koha::Items->find( $itemnumber );
Lines 590-597 subtest 'Koha::Item(s) tests' => sub { Link Here
590
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
607
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
591
608
592
    $biblio = $item->biblio();
609
    $biblio = $item->biblio();
593
    is( ref($biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" );
610
    is( ref($item->biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" );
594
    is( $biblio->title(), 'Silence in the library', 'Title matches biblio title' );
611
    is( $item->biblio->title(), $biblio->title, 'Title matches biblio title' );
595
612
596
    $schema->storage->txn_rollback;
613
    $schema->storage->txn_rollback;
597
};
614
};
Lines 629-642 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
629
646
630
    my @itemnumbers;
647
    my @itemnumbers;
631
    for my $item_info (@$item_infos) {
648
    for my $item_info (@$item_infos) {
632
        my ( undef, undef, $itemnumber ) = AddItem(
649
        my $itemnumber = $builder->build_sample_item(
633
            {
650
            {
651
                biblionumber  => $biblio->biblionumber,
634
                homebranch    => $item_info->{homebranch},
652
                homebranch    => $item_info->{homebranch},
635
                holdingbranch => $item_info->{holdingbanch},
653
                holdingbranch => $item_info->{holdingbranch},
636
                itype         => $itemtype->{itemtype},
654
                itype         => $itemtype->{itemtype}
637
            },
655
            }
638
            $biblio->biblionumber
656
        )->itemnumber;
639
        );
657
640
        push @itemnumbers, $itemnumber;
658
        push @itemnumbers, $itemnumber;
641
    }
659
    }
642
660
Lines 908-914 subtest 'Test logging for ModItem' => sub { Link Here
908
    my $biblio = $builder->build_sample_biblio();
926
    my $biblio = $builder->build_sample_biblio();
909
927
910
    # Add an item.
928
    # Add an item.
911
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber);
929
    my $itemnumber = $builder->build_sample_item(
930
        {
931
            biblionumber => $biblio->biblionumber,
932
            library      => $library->{homebranch},
933
            location     => $location,
934
            itype        => $itemtype->{itemtype}
935
        }
936
    )->itemnumber;
912
937
913
    # False means no logging
938
    # False means no logging
914
    $schema->resultset('ActionLog')->search()->delete();
939
    $schema->resultset('ActionLog')->search()->delete();
(-)a/t/db_dependent/Items/AutomaticItemModificationByAge.t (-9 / +7 lines)
Lines 53-69 $record->append_fields( Link Here
53
);
53
);
54
my ($biblionumber, undef) = C4::Biblio::AddBiblio($record, $frameworkcode);
54
my ($biblionumber, undef) = C4::Biblio::AddBiblio($record, $frameworkcode);
55
55
56
my ($item_bibnum, $item_bibitemnum, $itemnumber) = C4::Items::AddItem(
56
my $item = $builder->build_sample_item(
57
    {
57
    {
58
        homebranch => $library,
58
        biblionumber => $biblionumber,
59
        holdingbranch => $library,
59
        library      => $library,
60
        new_status => 'new_value',
60
        new_status   => 'new_value',
61
        ccode => 'FIC',
61
        ccode        => 'FIC',
62
    },
62
    }
63
    $biblionumber
64
);
63
);
65
64
my $itemnumber = $item->itemnumber;
66
my $item = Koha::Items->find( $itemnumber );
67
is ( $item->new_status, 'new_value', q|AddItem insert the 'new_status' field| );
65
is ( $item->new_status, 'new_value', q|AddItem insert the 'new_status' field| );
68
66
69
my ( $tagfield, undef ) = GetMarcFromKohaField( 'items.itemnumber' );
67
my ( $tagfield, undef ) = GetMarcFromKohaField( 'items.itemnumber' );
(-)a/t/db_dependent/Items/DelItem.t (-5 / +12 lines)
Lines 20-36 my $library = $builder->build({ Link Here
20
20
21
my $biblio = $builder->build_sample_biblio();
21
my $biblio = $builder->build_sample_biblio();
22
22
23
my ( $item_bibnum, $item_bibitemnum, $itemnumber );
23
my $itemnumber = $builder->build_sample_item(
24
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
24
    {
25
  AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblio->biblionumber );
25
        biblionumber => $biblio->biblionumber,
26
        library      => $library->{branchcode}
27
    }
28
)->itemnumber;
26
29
27
my $deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } );
30
my $deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } );
28
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
31
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
29
my $deleted_item = Koha::Items->find($itemnumber);
32
my $deleted_item = Koha::Items->find($itemnumber);
30
is( $deleted_item, undef, "DelItem with biblionumber parameter - the item should be deleted." );
33
is( $deleted_item, undef, "DelItem with biblionumber parameter - the item should be deleted." );
31
34
32
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
35
$itemnumber = $builder->build_sample_item(
33
  AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblio->biblionumber );
36
    {
37
        biblionumber => $biblio->biblionumber,
38
        library      => $library->{branchcode}
39
    }
40
)->itemnumber;
34
$deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } );
41
$deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } );
35
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
42
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
36
$deleted_item = Koha::Items->find($itemnumber);
43
$deleted_item = Koha::Items->find($itemnumber);
(-)a/t/db_dependent/Koha/BiblioUtils/Iterator.t (-1 / +1 lines)
Lines 50-56 t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); Link Here
50
my $biblio = $builder->build_sample_biblio();
50
my $biblio = $builder->build_sample_biblio();
51
51
52
# Add an item.
52
# Add an item.
53
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber);
53
$builder->build_sample_item({ biblionumber => $biblio->biblionumber });
54
54
55
my $rs = $schema->resultset('Biblioitem')->search({});
55
my $rs = $schema->resultset('Biblioitem')->search({});
56
my $iterator = Koha::BiblioUtils::Iterator->new($rs, items => 1 );
56
my $iterator = Koha::BiblioUtils::Iterator->new($rs, items => 1 );
(-)a/t/db_dependent/Koha/Biblios.t (-6 / +14 lines)
Lines 145-153 subtest 'can_be_transferred' => sub { Link Here
145
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
145
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
146
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
146
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
147
    my $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
147
    my $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
148
    my ($item_bibnum, $item_bibitemnum, $itemnumber)
148
    my $item = $builder->build_sample_item(
149
        = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library1->branchcode }, $biblio->biblionumber);
149
        {
150
    my $item  = Koha::Items->find($itemnumber);
150
            biblionumber => $biblio->biblionumber,
151
            library      => $library1->branchcode
152
        }
153
    );
151
154
152
    is(Koha::Item::Transfer::Limits->search({
155
    is(Koha::Item::Transfer::Limits->search({
153
        fromBranch => $library1->branchcode,
156
        fromBranch => $library1->branchcode,
Lines 175-183 subtest 'can_be_transferred' => sub { Link Here
175
    is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the '
178
    is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the '
176
         .'items is already located at to-library, then the transfer is possible.');
179
         .'items is already located at to-library, then the transfer is possible.');
177
    $item->holdingbranch($library1->branchcode)->store;
180
    $item->holdingbranch($library1->branchcode)->store;
178
    my ($item_bibnum2, $item_bibitemnum2, $itemnumber2)
181
179
        = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library3->branchcode }, $biblio->biblionumber);
182
    my $item2 = $builder->build_sample_item(
180
    my $item2  = Koha::Items->find($itemnumber2);
183
        {
184
            biblionumber  => $biblio->biblionumber,
185
            homebranch    => $library1->branchcode,
186
            holdingbranch => $library3->branchcode,
187
        }
188
    );
181
    is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added '
189
    is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added '
182
        .'another item that should have no transfer limits applying on, then '
190
        .'another item that should have no transfer limits applying on, then '
183
        .'the transfer is possible.');
191
        .'the transfer is possible.');
(-)a/t/db_dependent/Koha/Items.t (+23 lines)
Lines 27-35 use Koha::Item; Link Here
27
use Koha::Item::Transfer::Limits;
27
use Koha::Item::Transfer::Limits;
28
use Koha::Items;
28
use Koha::Items;
29
use Koha::Database;
29
use Koha::Database;
30
use Koha::DateUtils qw( dt_from_string );
30
31
31
use t::lib::TestBuilder;
32
use t::lib::TestBuilder;
32
use t::lib::Mocks;
33
use t::lib::Mocks;
34
use t::lib::Dates;
33
35
34
my $schema = Koha::Database->new->schema;
36
my $schema = Koha::Database->new->schema;
35
$schema->storage->txn_begin;
37
$schema->storage->txn_begin;
Lines 58-63 is( Koha::Items->search->count, $nb_of_items + 2, 'The 2 items should have been Link Here
58
my $retrieved_item_1 = Koha::Items->find( $new_item_1->itemnumber );
60
my $retrieved_item_1 = Koha::Items->find( $new_item_1->itemnumber );
59
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' );
61
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' );
60
62
63
subtest 'store' => sub {
64
    plan tests => 4;
65
    my $biblio = $builder->build_sample_biblio;
66
    my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 );
67
    my $item = Koha::Item->new(
68
        {
69
            homebranch    => $library->{branchcode},
70
            holdingbranch => $library->{branchcode},
71
            biblionumber  => $biblio->biblionumber,
72
            location      => 'my_loc',
73
        }
74
    )->store
75
    ->get_from_storage;
76
77
    is( t::lib::Dates::compare($item->replacementpricedate, $today), 0, 'replacementpricedate must have been set to today if not given');
78
    is( t::lib::Dates::compare($item->datelastseen,         $today), 0, 'datelastseen must have been set to today if not given');
79
    is( $item->itype, $biblio->biblioitem->itemtype, 'items.itype must have been set to biblioitem.itemtype is not given');
80
    is( $item->permanent_location, $item->location, 'permanent_location must have been set to location if not given' );
81
    $item->delete;
82
};
83
61
subtest 'get_transfer' => sub {
84
subtest 'get_transfer' => sub {
62
    plan tests => 3;
85
    plan tests => 3;
63
86
(-)a/t/db_dependent/Labels/t_Label.t (-7 / +6 lines)
Lines 62-75 t::lib::Mocks::mock_userenv({ branchcode => $branch_1 }); Link Here
62
my $bibnum = $builder->build_sample_biblio({ frameworkcode => $frameworkcode })->biblionumber;
62
my $bibnum = $builder->build_sample_biblio({ frameworkcode => $frameworkcode })->biblionumber;
63
63
64
# Create a helper item instance for testing
64
# Create a helper item instance for testing
65
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
65
my $itemnumber = $builder->build_sample_item(
66
    {
66
    {
67
        homebranch    => $branch_1,
67
        biblionumber => $bibnum,
68
        holdingbranch => $branch_1,
68
        library      => $branch_1,
69
        itype         => $itemtype
69
        itype        => $itemtype,
70
    },
70
    }
71
    $bibnum
71
)->itemnumber;
72
);
73
72
74
# Modify item; setting barcode.
73
# Modify item; setting barcode.
75
my $testbarcode = '97531';
74
my $testbarcode = '97531';
(-)a/t/db_dependent/Members/GetAllIssues.t (-6 / +5 lines)
Lines 54-67 my %item_infos = ( Link Here
54
);
54
);
55
55
56
my ($biblionumber1) = AddBiblio( MARC::Record->new, '' );
56
my ($biblionumber1) = AddBiblio( MARC::Record->new, '' );
57
my $itemnumber1 =
57
58
  AddItem( { barcode => '0101', %item_infos }, $biblionumber1 );
58
# FIXME These tests will fail if the barcode exists in DB
59
my $itemnumber2 =
59
my $itemnumber1 = $builder->build_sample_item({ biblionumber => $biblionumber1, barcode => '0101', %item_infos })->itemnumber;
60
  AddItem( { barcode => '0102', %item_infos }, $biblionumber1 );
60
my $itemnumber2 = $builder->build_sample_item({ biblionumber => $biblionumber1, barcode => '0102', %item_infos })->itemnumber;
61
61
62
my ($biblionumber2) = AddBiblio( MARC::Record->new, '' );
62
my ($biblionumber2) = AddBiblio( MARC::Record->new, '' );
63
my $itemnumber3 =
63
my $itemnumber2 = $builder->build_sample_item({ biblionumber => $biblionumber2, barcode => '0202', %item_infos })->itemnumber;
64
  AddItem( { barcode => '0203', %item_infos }, $biblionumber2 );
65
64
66
my $borrowernumber1 =
65
my $borrowernumber1 =
67
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
66
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
(-)a/t/db_dependent/Members/IssueSlip.t (-5 / +3 lines)
Lines 95-101 $dbh->do(q| Link Here
95
|, {}, $quick_slip_content);
95
|, {}, $quick_slip_content);
96
96
97
my ( $title1, $title2 ) = ( 'My title 1', 'My title 2' );
97
my ( $title1, $title2 ) = ( 'My title 1', 'My title 2' );
98
my ( $barcode1, $barcode2 ) = ('BC0101', 'BC0202' );
98
my ( $barcode1, $barcode2 ) = ('BC0101', 'BC0202' ); # FIXME Must not be hardcoded, tests could fail
99
my $record = MARC::Record->new;
99
my $record = MARC::Record->new;
100
$record->append_fields(
100
$record->append_fields(
101
    MARC::Field->new(
101
    MARC::Field->new(
Lines 104-111 $record->append_fields( Link Here
104
    ),
104
    ),
105
);
105
);
106
my ($biblionumber1) = AddBiblio( $record, '' );
106
my ($biblionumber1) = AddBiblio( $record, '' );
107
my $itemnumber1 =
107
my $itemnumber1 = $builder->build_sample_item({ biblionumber => $biblionumber1, barcode => $barcode1, %item_infos })->itemnumber;
108
  AddItem( { barcode => $barcode1, %item_infos }, $biblionumber1 );
109
108
110
$record = MARC::Record->new;
109
$record = MARC::Record->new;
111
$record->append_fields(
110
$record->append_fields(
Lines 115-122 $record->append_fields( Link Here
115
    ),
114
    ),
116
);
115
);
117
my ($biblionumber2) = AddBiblio( $record, '' );
116
my ($biblionumber2) = AddBiblio( $record, '' );
118
my $itemnumber2 =
117
my $itemnumber2 = $builder->build_sample_item({ biblionumber => $biblionumber2, barcode => $barcode2, %item_infos })->itemnumber;
119
  AddItem( { barcode => $barcode2, %item_infos }, $biblionumber2 );
120
118
121
my $borrowernumber =
119
my $borrowernumber =
122
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
120
  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
(-)a/t/db_dependent/Patron/Borrower_Discharge.t (-8 / +7 lines)
Lines 20-26 use Test::Warn; Link Here
20
use MARC::Record;
20
use MARC::Record;
21
21
22
use C4::Circulation qw( AddIssue AddReturn );
22
use C4::Circulation qw( AddIssue AddReturn );
23
use C4::Items qw( AddItem );
24
use C4::Biblio qw( AddBiblio );
23
use C4::Biblio qw( AddBiblio );
25
use C4::Context;
24
use C4::Context;
26
25
Lines 72-84 my $p3 = Koha::Patrons->find( $patron3->{borrowernumber} ); Link Here
72
# Discharge not possible with issues
71
# Discharge not possible with issues
73
my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
72
my ( $biblionumber ) = AddBiblio( MARC::Record->new, '');
74
my $barcode = 'BARCODE42';
73
my $barcode = 'BARCODE42';
75
my ( undef, undef, $itemnumber ) = AddItem(
74
$builder->build_sample_item(
76
    {   homebranch    => $library->{branchcode},
75
    {
77
        holdingbranch => $library->{branchcode},
76
        biblionumber => $biblionumber,
78
        barcode       => $barcode,
77
        library      => $library->{branchcode},
79
        itype         => $itemtype
78
        barcode      => $barcode,
80
    },
79
        itype        => $itemtype
81
    $biblionumber
80
    }
82
);
81
);
83
82
84
AddIssue( $patron, $barcode );
83
AddIssue( $patron, $barcode );
(-)a/t/db_dependent/Reserves.t (-64 / +54 lines)
Lines 85-97 t::lib::Mocks::mock_userenv({ branchcode => $branch_1 }); Link Here
85
my $bibnum = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber;
85
my $bibnum = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber;
86
86
87
# Create a helper item instance for testing
87
# Create a helper item instance for testing
88
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
88
my $itemnumber = $builder->build_sample_item({ biblionumber => $bibnum, library => $branch_1, itype => $itemtype })->itemnumber;
89
    {   homebranch    => $branch_1,
90
        holdingbranch => $branch_1,
91
        itype         => $itemtype
92
    },
93
    $bibnum
94
);
95
89
96
my $biblio_with_no_item = $builder->build({
90
my $biblio_with_no_item = $builder->build({
97
    source => 'Biblio'
91
    source => 'Biblio'
Lines 130-142 AddReserve($branchcode, $borrowernumber, $biblionumber, Link Here
130
        $bibitems,  $priority, $resdate, $expdate, $notes,
124
        $bibitems,  $priority, $resdate, $expdate, $notes,
131
        'a title',      $checkitem, $found);
125
        'a title',      $checkitem, $found);
132
126
133
my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
127
my ($status, $reserve, $all_reserves) = CheckReserves($item->itemnumber, $barcode);
134
128
135
is($status, "Reserved", "CheckReserves Test 1");
129
is($status, "Reserved", "CheckReserves Test 1");
136
130
137
ok(exists($reserve->{reserve_id}), 'CheckReserves() include reserve_id in its response');
131
ok(exists($reserve->{reserve_id}), 'CheckReserves() include reserve_id in its response');
138
132
139
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
133
($status, $reserve, $all_reserves) = CheckReserves($item->itemnumber);
140
is($status, "Reserved", "CheckReserves Test 2");
134
is($status, "Reserved", "CheckReserves Test 2");
141
135
142
($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
136
($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
Lines 227-249 Koha::CirculationRules->set_rules( Link Here
227
my $bibnum2 = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber;
221
my $bibnum2 = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber;
228
222
229
my ($itemnum_cpl, $itemnum_fpl);
223
my ($itemnum_cpl, $itemnum_fpl);
230
( undef, undef, $itemnum_cpl ) = AddItem(
224
$itemnum_cpl = $builder->build_sample_item(
231
    {   homebranch    => $branch_1,
225
    {
232
        holdingbranch => $branch_1,
226
        biblionumber => $bibnum2,
233
        barcode       => 'bug10272_CPL',
227
        library      => $branch_1,
234
        itype         => $itemtype
228
        barcode      => 'bug10272_CPL',
235
    },
229
        itype        => $itemtype
236
    $bibnum2
230
    }
237
);
231
)->itemnumber;
238
( undef, undef, $itemnum_fpl ) = AddItem(
232
$itemnum_fpl = $builder->build_sample_item(
239
    {   homebranch    => $branch_2,
233
    {
240
        holdingbranch => $branch_2,
234
        biblionumber => $bibnum2,
241
        barcode       => 'bug10272_FPL',
235
        library      => $branch_2,
242
        itype         => $itemtype
236
        barcode      => 'bug10272_FPL',
243
    },
237
        itype        => $itemtype
244
    $bibnum2
238
    }
245
);
239
)->itemnumber;
246
247
240
248
# Ensure that priorities are numbered correcly when a hold is moved to waiting
241
# Ensure that priorities are numbered correcly when a hold is moved to waiting
249
# (bug 11947)
242
# (bug 11947)
Lines 320-328 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); Link Here
320
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
313
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
321
           $bibitems,  1, $resdate, $expdate, $notes,
314
           $bibitems,  1, $resdate, $expdate, $notes,
322
           'a title',      $checkitem, $found);
315
           'a title',      $checkitem, $found);
323
($status)=CheckReserves($itemnumber,undef,undef);
316
($status)=CheckReserves($item->itemnumber,undef,undef);
324
is( $status, 'Reserved', 'CheckReserves returns reserve without lookahead');
317
is( $status, 'Reserved', 'CheckReserves returns reserve without lookahead');
325
($status)=CheckReserves($itemnumber,undef,7);
318
($status)=CheckReserves($item->itemnumber,undef,7);
326
is( $status, 'Reserved', 'CheckReserves also returns reserve with lookahead');
319
is( $status, 'Reserved', 'CheckReserves also returns reserve with lookahead');
327
320
328
# Test 9761b: Add a reserve with future date, CheckReserve should not return it
321
# Test 9761b: Add a reserve with future date, CheckReserve should not return it
Lines 335-347 $expdate= undef; #no expdate Link Here
335
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
328
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
336
           $bibitems,  1, $resdate, $expdate, $notes,
329
           $bibitems,  1, $resdate, $expdate, $notes,
337
           'a title',      $checkitem, $found);
330
           'a title',      $checkitem, $found);
338
($status)=CheckReserves($itemnumber,undef,undef);
331
($status)=CheckReserves($item->itemnumber,undef,undef);
339
is( $status, '', 'CheckReserves returns no future reserve without lookahead');
332
is( $status, '', 'CheckReserves returns no future reserve without lookahead');
340
333
341
# Test 9761c: Add a reserve with future date, CheckReserve should return it if lookahead is high enough
334
# Test 9761c: Add a reserve with future date, CheckReserve should return it if lookahead is high enough
342
($status)=CheckReserves($itemnumber,undef,3);
335
($status)=CheckReserves($item->itemnumber,undef,3);
343
is( $status, '', 'CheckReserves returns no future reserve with insufficient lookahead');
336
is( $status, '', 'CheckReserves returns no future reserve with insufficient lookahead');
344
($status)=CheckReserves($itemnumber,undef,4);
337
($status)=CheckReserves($item->itemnumber,undef,4);
345
is( $status, 'Reserved', 'CheckReserves returns future reserve with sufficient lookahead');
338
is( $status, 'Reserved', 'CheckReserves returns future reserve with sufficient lookahead');
346
339
347
# Test 9761d: Check ResFound message of AddReturn for future hold
340
# Test 9761d: Check ResFound message of AddReturn for future hold
Lines 361-372 is(exists $messages->{ResFound}?1:0, 1, 'AddReturn considers future reserve with Link Here
361
354
362
# test marking a hold as captured
355
# test marking a hold as captured
363
my $hold_notice_count = count_hold_print_messages();
356
my $hold_notice_count = count_hold_print_messages();
364
ModReserveAffect($itemnumber, $requesters{$branch_1}, 0);
357
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0);
365
my $new_count = count_hold_print_messages();
358
my $new_count = count_hold_print_messages();
366
is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting');
359
is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting');
367
360
368
# test that duplicate notices aren't generated
361
# test that duplicate notices aren't generated
369
ModReserveAffect($itemnumber, $requesters{$branch_1}, 0);
362
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0);
370
$new_count = count_hold_print_messages();
363
$new_count = count_hold_print_messages();
371
is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)');
364
is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)');
372
365
Lines 392-398 $resdate=output_pref($resdate); Link Here
392
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
385
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
393
           $bibitems,  1, $resdate, $expdate, $notes,
386
           $bibitems,  1, $resdate, $expdate, $notes,
394
           'a title',      $checkitem, $found);
387
           'a title',      $checkitem, $found);
395
my $item = Koha::Items->find( $itemnumber );
396
$holds = $item->current_holds;
388
$holds = $item->current_holds;
397
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
389
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
398
my $future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
390
my $future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
Lines 401-411 is( $future_holds->count, 0, 'current_holds does not return a future next availa Link Here
401
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
393
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
402
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
394
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
403
           $bibitems,  1, $resdate, $expdate, $notes,
395
           $bibitems,  1, $resdate, $expdate, $notes,
404
           'a title',      $itemnumber, $found); #item level hold
396
           'a title',      $item->itemnumber, $found); #item level hold
405
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
397
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
406
is( $future_holds->count, 0, 'current_holds does not return a future item level hold' );
398
is( $future_holds->count, 0, 'current_holds does not return a future item level hold' );
407
# 9788c: current_holds returns future wait (confirmed future hold)
399
# 9788c: current_holds returns future wait (confirmed future hold)
408
ModReserveAffect( $itemnumber,  $requesters{$branch_1} , 0); #confirm hold
400
ModReserveAffect( $item->itemnumber,  $requesters{$branch_1} , 0); #confirm hold
409
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
401
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
410
is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' );
402
is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' );
411
# End of tests for bug 9788
403
# End of tests for bug 9788
Lines 427-436 is($p, 1, 'CalculatePriority should now return priority 1'); Link Here
427
#add a new reserve and confirm it to waiting
419
#add a new reserve and confirm it to waiting
428
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
420
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
429
           $bibitems,  $p, $resdate, $expdate, $notes,
421
           $bibitems,  $p, $resdate, $expdate, $notes,
430
           'a title',      $itemnumber, $found);
422
           'a title',      $item->itemnumber, $found);
431
$p = C4::Reserves::CalculatePriority($bibnum);
423
$p = C4::Reserves::CalculatePriority($bibnum);
432
is($p, 2, 'CalculatePriority should now return priority 2');
424
is($p, 2, 'CalculatePriority should now return priority 2');
433
ModReserveAffect( $itemnumber,  $requesters{$branch_1} , 0);
425
ModReserveAffect( $item->itemnumber,  $requesters{$branch_1} , 0);
434
$p = C4::Reserves::CalculatePriority($bibnum);
426
$p = C4::Reserves::CalculatePriority($bibnum);
435
is($p, 1, 'CalculatePriority should now return priority 1');
427
is($p, 1, 'CalculatePriority should now return priority 1');
436
#add another biblio hold, no resdate
428
#add another biblio hold, no resdate
Lines 455-464 is($p, 3, 'CalculatePriority should now return priority 3'); Link Here
455
447
456
# Tests for cancel reserves by users from OPAC.
448
# Tests for cancel reserves by users from OPAC.
457
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
449
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
458
AddReserve($branch_1,  $requesters{$branch_1}, $item_bibnum,
450
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
459
           $bibitems,  1, undef, $expdate, $notes,
451
           $bibitems,  1, undef, $expdate, $notes,
460
           'a title',      $checkitem, '');
452
           'a title',      $checkitem, '');
461
my (undef, $canres, undef) = CheckReserves($itemnumber);
453
my (undef, $canres, undef) = CheckReserves($item->itemnumber);
462
454
463
is( CanReserveBeCanceledFromOpac(), undef,
455
is( CanReserveBeCanceledFromOpac(), undef,
464
    'CanReserveBeCanceledFromOpac should return undef if called without any parameter'
456
    'CanReserveBeCanceledFromOpac should return undef if called without any parameter'
Lines 480-496 is($cancancel, 1, 'Can user cancel its own reserve'); Link Here
480
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_2});
472
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_2});
481
is($cancancel, 0, 'Other user cant cancel reserve');
473
is($cancancel, 0, 'Other user cant cancel reserve');
482
474
483
ModReserveAffect($itemnumber, $requesters{$branch_1}, 1);
475
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 1);
484
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
476
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
485
is($cancancel, 0, 'Reserve in transfer status cant be canceled');
477
is($cancancel, 0, 'Reserve in transfer status cant be canceled');
486
478
487
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
479
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
488
AddReserve($branch_1,  $requesters{$branch_1}, $item_bibnum,
480
AddReserve($branch_1,  $requesters{$branch_1}, $bibnum,
489
           $bibitems,  1, undef, $expdate, $notes,
481
           $bibitems,  1, undef, $expdate, $notes,
490
           'a title',      $checkitem, '');
482
           'a title',      $checkitem, '');
491
(undef, $canres, undef) = CheckReserves($itemnumber);
483
(undef, $canres, undef) = CheckReserves($item->itemnumber);
492
484
493
ModReserveAffect($itemnumber, $requesters{$branch_1}, 0);
485
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0);
494
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
486
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
495
is($cancancel, 0, 'Reserve in waiting status cant be canceled');
487
is($cancancel, 0, 'Reserve in waiting status cant be canceled');
496
488
Lines 529-536 is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_with_no_item->{bibl Link Here
529
####### EO Bug 13113 <<<
521
####### EO Bug 13113 <<<
530
       ####
522
       ####
531
523
532
$item = Koha::Items->find($itemnumber);
533
534
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $patron), "Reserving a book on item level" );
524
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $patron), "Reserving a book on item level" );
535
525
536
my $pickup_branch = $builder->build({ source => 'Branch' })->{ branchcode };
526
my $pickup_branch = $builder->build({ source => 'Branch' })->{ branchcode };
Lines 551-598 t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' ); Link Here
551
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
541
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
552
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 0);
542
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 0);
553
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1);
543
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1);
554
AddReserve($branch_1,  $borrowernumber, $item_bibnum,
544
AddReserve($branch_1,  $borrowernumber, $bibnum,
555
    $bibitems,  1, undef, $expdate, $notes, 'a title', $checkitem, '');
545
    $bibitems,  1, undef, $expdate, $notes, 'a title', $checkitem, '');
556
MoveReserve( $itemnumber, $borrowernumber );
546
MoveReserve( $item->itemnumber, $borrowernumber );
557
($status)=CheckReserves( $itemnumber );
547
($status)=CheckReserves( $item->itemnumber );
558
is( $status, '', 'MoveReserve filled hold');
548
is( $status, '', 'MoveReserve filled hold');
559
#   hold from A waiting, today, no fut holds: MoveReserve should fill it
549
#   hold from A waiting, today, no fut holds: MoveReserve should fill it
560
AddReserve($branch_1,  $borrowernumber, $item_bibnum,
550
AddReserve($branch_1,  $borrowernumber, $bibnum,
561
   $bibitems,  1, undef, $expdate, $notes, 'a title', $checkitem, 'W');
551
   $bibitems,  1, undef, $expdate, $notes, 'a title', $checkitem, 'W');
562
MoveReserve( $itemnumber, $borrowernumber );
552
MoveReserve( $item->itemnumber, $borrowernumber );
563
($status)=CheckReserves( $itemnumber );
553
($status)=CheckReserves( $item->itemnumber );
564
is( $status, '', 'MoveReserve filled waiting hold');
554
is( $status, '', 'MoveReserve filled waiting hold');
565
#   hold from A pos 1, tomorrow, no fut holds: not filled
555
#   hold from A pos 1, tomorrow, no fut holds: not filled
566
$resdate= dt_from_string();
556
$resdate= dt_from_string();
567
$resdate->add_duration(DateTime::Duration->new(days => 1));
557
$resdate->add_duration(DateTime::Duration->new(days => 1));
568
$resdate=output_pref($resdate);
558
$resdate=output_pref($resdate);
569
AddReserve($branch_1,  $borrowernumber, $item_bibnum,
559
AddReserve($branch_1,  $borrowernumber, $bibnum,
570
    $bibitems,  1, $resdate, $expdate, $notes, 'a title', $checkitem, '');
560
    $bibitems,  1, $resdate, $expdate, $notes, 'a title', $checkitem, '');
571
MoveReserve( $itemnumber, $borrowernumber );
561
MoveReserve( $item->itemnumber, $borrowernumber );
572
($status)=CheckReserves( $itemnumber, undef, 1 );
562
($status)=CheckReserves( $item->itemnumber, undef, 1 );
573
is( $status, 'Reserved', 'MoveReserve did not fill future hold');
563
is( $status, 'Reserved', 'MoveReserve did not fill future hold');
574
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
564
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
575
#   hold from A pos 1, tomorrow, fut holds=2: MoveReserve should fill it
565
#   hold from A pos 1, tomorrow, fut holds=2: MoveReserve should fill it
576
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 2);
566
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 2);
577
AddReserve($branch_1,  $borrowernumber, $item_bibnum,
567
AddReserve($branch_1,  $borrowernumber, $bibnum,
578
    $bibitems,  1, $resdate, $expdate, $notes, 'a title', $checkitem, '');
568
    $bibitems,  1, $resdate, $expdate, $notes, 'a title', $checkitem, '');
579
MoveReserve( $itemnumber, $borrowernumber );
569
MoveReserve( $item->itemnumber, $borrowernumber );
580
($status)=CheckReserves( $itemnumber, undef, 2 );
570
($status)=CheckReserves( $item->itemnumber, undef, 2 );
581
is( $status, '', 'MoveReserve filled future hold now');
571
is( $status, '', 'MoveReserve filled future hold now');
582
#   hold from A waiting, tomorrow, fut holds=2: MoveReserve should fill it
572
#   hold from A waiting, tomorrow, fut holds=2: MoveReserve should fill it
583
AddReserve($branch_1,  $borrowernumber, $item_bibnum,
573
AddReserve($branch_1,  $borrowernumber, $bibnum,
584
    $bibitems,  1, $resdate, $expdate, $notes, 'a title', $checkitem, 'W');
574
    $bibitems,  1, $resdate, $expdate, $notes, 'a title', $checkitem, 'W');
585
MoveReserve( $itemnumber, $borrowernumber );
575
MoveReserve( $item->itemnumber, $borrowernumber );
586
($status)=CheckReserves( $itemnumber, undef, 2 );
576
($status)=CheckReserves( $item->itemnumber, undef, 2 );
587
is( $status, '', 'MoveReserve filled future waiting hold now');
577
is( $status, '', 'MoveReserve filled future waiting hold now');
588
#   hold from A pos 1, today+3, fut holds=2: MoveReserve should not fill it
578
#   hold from A pos 1, today+3, fut holds=2: MoveReserve should not fill it
589
$resdate= dt_from_string();
579
$resdate= dt_from_string();
590
$resdate->add_duration(DateTime::Duration->new(days => 3));
580
$resdate->add_duration(DateTime::Duration->new(days => 3));
591
$resdate=output_pref($resdate);
581
$resdate=output_pref($resdate);
592
AddReserve($branch_1,  $borrowernumber, $item_bibnum,
582
AddReserve($branch_1,  $borrowernumber, $bibnum,
593
    $bibitems,  1, $resdate, $expdate, $notes, 'a title', $checkitem, '');
583
    $bibitems,  1, $resdate, $expdate, $notes, 'a title', $checkitem, '');
594
MoveReserve( $itemnumber, $borrowernumber );
584
MoveReserve( $item->itemnumber, $borrowernumber );
595
($status)=CheckReserves( $itemnumber, undef, 3 );
585
($status)=CheckReserves( $item->itemnumber, undef, 3 );
596
is( $status, 'Reserved', 'MoveReserve did not fill future hold of 3 days');
586
is( $status, 'Reserved', 'MoveReserve did not fill future hold of 3 days');
597
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
587
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
598
588
(-)a/t/db_dependent/RotatingCollections.t (-16 / +17 lines)
Lines 24-29 use C4::Biblio; Link Here
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Library;
25
use Koha::Library;
26
26
27
use t::lib::TestBuilder;
28
27
BEGIN {
29
BEGIN {
28
}
30
}
29
31
Lines 58-63 $dbh->do(q|DELETE FROM collections |); Link Here
58
$dbh->do(q|DELETE FROM branches |);
60
$dbh->do(q|DELETE FROM branches |);
59
$dbh->do(q|DELETE FROM categories|);
61
$dbh->do(q|DELETE FROM categories|);
60
62
63
my $builder = t::lib::TestBuilder->new;
64
61
#Test CreateCollection
65
#Test CreateCollection
62
my $collections     = GetCollections();
66
my $collections     = GetCollections();
63
my $countcollection = scalar(@$collections);
67
my $countcollection = scalar(@$collections);
Lines 219-244 $record->append_fields( Link Here
219
    )
223
    )
220
);
224
);
221
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', );
225
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', );
222
my @sampleitem1 = C4::Items::AddItem(
226
my $item_id1 = $builder->build_sample_item(
223
    {
227
    {
224
        barcode        => 1,
228
        biblionumber => $biblionumber,
229
        library      => $samplebranch->{branchcode},
230
        barcode        => 1,              # FIXME This must not be hardcoded!
225
        itemcallnumber => 'callnumber1',
231
        itemcallnumber => 'callnumber1',
226
        homebranch     => $samplebranch->{branchcode},
232
    }
227
        holdingbranch  => $samplebranch->{branchcode}
233
)->itemnumber;
228
    },
234
my $item_id2 = $builder->build_sample_item(
229
    $biblionumber
230
);
231
my $item_id1    = $sampleitem1[2];
232
my @sampleitem2 = C4::Items::AddItem(
233
    {
235
    {
234
        barcode        => 2,
236
        biblionumber => $biblionumber,
237
        library      => $samplebranch->{branchcode},
238
        barcode        => 2,              # FIXME This must not be hardcoded!
235
        itemcallnumber => 'callnumber2',
239
        itemcallnumber => 'callnumber2',
236
        homebranch     => $samplebranch->{branchcode},
240
    }
237
        holdingbranch  => $samplebranch->{branchcode}
241
)->itemnumber;
238
    },
242
239
    $biblionumber
240
);
241
my $item_id2 = $sampleitem2[2];
242
is( AddItemToCollection( $collection_id1, $item_id1 ),
243
is( AddItemToCollection( $collection_id1, $item_id1 ),
243
    1, "Sampleitem1 has been added to Collection1" );
244
    1, "Sampleitem1 has been added to Collection1" );
244
is( AddItemToCollection( $collection_id1, $item_id2 ),
245
is( AddItemToCollection( $collection_id1, $item_id2 ),
(-)a/t/db_dependent/ShelfBrowser.t (-5 / +7 lines)
Lines 62-72 $record->append_fields( Link Here
62
my ( $biblionumber ) = C4::Biblio::AddBiblio($record, '');
62
my ( $biblionumber ) = C4::Biblio::AddBiblio($record, '');
63
63
64
for my $callnumber ( shuffle @callnumbers ) {
64
for my $callnumber ( shuffle @callnumbers ) {
65
    my ( $biblionumber, undef, $itemnumber ) = C4::Items::AddItem({
65
    my $itemnumber = $builder->build_sample_item(
66
        homebranch => $library->{branchcode},
66
        {
67
        holdingbranch => $library->{branchcode},
67
            biblionumber   => $biblionumber,
68
        itemcallnumber => $callnumber,
68
            library        => $library->{branchcode},
69
    }, $biblionumber);
69
            itemcallnumber => $callnumber,
70
        }
71
    )->itemnumber;
70
    $cn->{$callnumber} = {
72
    $cn->{$callnumber} = {
71
        biblionumber => $biblionumber,
73
        biblionumber => $biblionumber,
72
        itemnumber => $itemnumber,
74
        itemnumber => $itemnumber,
(-)a/t/db_dependent/Template/Plugin/Branches.t (-1 lines)
Lines 21-27 use Test::MockModule; Link Here
21
21
22
use C4::Context;
22
use C4::Context;
23
use C4::Biblio qw(AddBiblio);
23
use C4::Biblio qw(AddBiblio);
24
use C4::Items qw(AddItem);
25
use Koha::Database;
24
use Koha::Database;
26
25
27
use Clone qw(clone);
26
use Clone qw(clone);
(-)a/t/lib/TestBuilder.pm (-4 / +1 lines)
Lines 176-183 sub build_sample_item { Link Here
176
    my $library = delete $args->{library}
176
    my $library = delete $args->{library}
177
      || $self->build_object( { class => 'Koha::Libraries' } )->branchcode;
177
      || $self->build_object( { class => 'Koha::Libraries' } )->branchcode;
178
178
179
    my $itype = delete $args->{itype}
179
    # If itype is not passed it will be picked from the biblio (see Koha::Item->store)
180
      || $self->build_object( { class => 'Koha::ItemTypes' } )->itemtype;
181
180
182
    my $barcode = delete $args->{barcode}
181
    my $barcode = delete $args->{barcode}
183
      || $self->_gen_text( { info => { size => SIZE_BARCODE } } );
182
      || $self->_gen_text( { info => { size => SIZE_BARCODE } } );
Lines 187-193 sub build_sample_item { Link Here
187
            homebranch    => $library,
186
            homebranch    => $library,
188
            holdingbranch => $library,
187
            holdingbranch => $library,
189
            barcode       => $barcode,
188
            barcode       => $barcode,
190
            itype         => $itype,
191
            %$args,
189
            %$args,
192
        },
190
        },
193
        $biblionumber
191
        $biblionumber
194
- 

Return to bug 23463