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

(-)a/C4/Items.pm (-15 / +8 lines)
Lines 27-33 BEGIN { Link Here
27
27
28
    @EXPORT = qw(
28
    @EXPORT = qw(
29
        AddItemFromMarc
29
        AddItemFromMarc
30
        AddItem
31
        AddItemBatchFromMarc
30
        AddItemBatchFromMarc
32
        ModItemFromMarc
31
        ModItemFromMarc
33
        Item2Marc
32
        Item2Marc
Lines 159-167 sub AddItemFromMarc { Link Here
159
158
160
    my $localitemmarc = MARC::Record->new;
159
    my $localitemmarc = MARC::Record->new;
161
    $localitemmarc->append_fields( $source_item_marc->field($itemtag) );
160
    $localitemmarc->append_fields( $source_item_marc->field($itemtag) );
161
162
#RMME
162
    my $item = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' );
163
    my $item = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' );
163
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
164
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
164
    return AddItem( $item, $biblionumber, $dbh, $frameworkcode, $unlinked_item_subfields );
165
    return AddItem( $item, $biblionumber, $dbh, $frameworkcode, $unlinked_item_subfields );
166
167
    my $item_values = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' );
168
    $item_values->{biblionumber} = $biblionumber;
169
    # FIXME RM my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
170
    my $item = Koha::Item->new( $item_values ); # FIXME Handle $unlinked_item_subfields
171
    return ( $item->biblionumber, $item->biblioitemnumber, $item->itemnumber );
165
}
172
}
166
173
167
=head2 AddItem
174
=head2 AddItem
Lines 190-218 sub AddItem { Link Here
190
    my $biblionumber = shift;
197
    my $biblionumber = shift;
191
198
192
    my $dbh           = @_ ? shift : C4::Context->dbh;
199
    my $dbh           = @_ ? shift : C4::Context->dbh;
193
    my $frameworkcode = @_ ? shift : C4::Biblio::GetFrameworkCode($biblionumber);
194
    my $unlinked_item_subfields;
200
    my $unlinked_item_subfields;
195
    if (@_) {
201
    if (@_) {
196
        $unlinked_item_subfields = shift;
202
        $unlinked_item_subfields = shift;
197
    }
203
    }
198
204
199
    # needs old biblionumber and biblioitemnumber
200
    $item->{'biblionumber'} = $biblionumber;
201
    my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
202
    $sth->execute( $item->{'biblionumber'} );
203
    ( $item->{'biblioitemnumber'} ) = $sth->fetchrow;
204
205
    _set_defaults_for_add($item);
205
    _set_defaults_for_add($item);
206
    _set_derived_columns_for_add($item);
206
    _set_derived_columns_for_add($item);
207
    $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields);
207
    $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields);
208
208
209
    # FIXME - checks here
210
    unless ( $item->{itype} ) {    # default to biblioitem.itemtype if no itype
211
        my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
212
        $itype_sth->execute( $item->{'biblionumber'} );
213
        ( $item->{'itype'} ) = $itype_sth->fetchrow_array;
214
    }
215
216
    my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} );
209
    my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} );
217
    return if $error;
210
    return if $error;
218
211
(-)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 49-54 Koha::Item - Koha Item object class Link Here
49
49
50
=cut
50
=cut
51
51
52
=head3 store
53
54
=cut
55
56
sub store {
57
    my ($self) = @_;
58
59
    # We do not want to oblige callers to pass this value
60
    # Dev conveniences vs performance?
61
    unless ( $self->biblioitemnumber ) {
62
        $self->biblioitemnumber( $self->biblio->biblioitem->biblioitemnumber );
63
    }
64
65
    # See related changes from C4::Items::AddItem
66
    unless ( $self->itype ) {
67
        $self->itype($self->biblio->biblioitem->itemtype);
68
    }
69
70
    unless ( $self->in_storage ) { #AddItem
71
        my $today = dt_from_string;
72
        unless ( $self->permanent_location ) {
73
            $self->permanent_location($self->location);
74
        }
75
        unless ( $self->replacementpricedate ) {
76
            $self->replacementpricedate($today);
77
        }
78
        unless ( $self->datelastseen ) {
79
            $self->datelastseen($today);
80
        }
81
82
    }
83
84
    return $self->SUPER::store;
85
}
86
52
=head3 effective_itemtype
87
=head3 effective_itemtype
53
88
54
Returns the itemtype for the item based on whether item level itemtypes are set or not.
89
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 557-563 ok(($order4->{cancellationreason} eq "foobar"), "order has cancellation reason \ Link Here
557
ok((not defined Koha::Biblios->find( $order4->{biblionumber} )), "biblio does not exist anymore");
557
ok((not defined Koha::Biblios->find( $order4->{biblionumber} )), "biblio does not exist anymore");
558
558
559
my $order5 = GetOrder($ordernumbers[4]);
559
my $order5 = GetOrder($ordernumbers[4]);
560
C4::Items::AddItem( { barcode => '0102030405' }, $order5->{biblionumber} );
560
Koha::Item->new({ barcode => '0102030405', biblionumber => $order5->{biblionumber} })->store;
561
$error = DelOrder($order5->{biblionumber}, $order5->{ordernumber}, 1);
561
$error = DelOrder($order5->{biblionumber}, $order5->{ordernumber}, 1);
562
$order5 = GetOrder($order5->{ordernumber});
562
$order5 = GetOrder($order5->{ordernumber});
563
ok((defined $order5->{datecancellationprinted}), "order is cancelled");
563
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 (-52 / +23 lines)
Lines 59-66 $insert_sth->execute('ONLY1'); Link Here
59
my $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
59
my $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
60
60
61
# Create item instance for testing.
61
# Create item instance for testing.
62
my ($item_bibnum, $item_bibitemnum, $itemnumber)
62
my $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
63
    = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
64
63
65
# Create some borrowers
64
# Create some borrowers
66
my @borrowernumbers;
65
my @borrowernumbers;
Lines 153-159 is( $hold->suspend_until, '2013-01-01 00:00:00', "Test ModReserve, suspend until Link Here
153
152
154
ModReserve({ # call without reserve_id
153
ModReserve({ # call without reserve_id
155
    rank          => '3',
154
    rank          => '3',
156
    biblionumber  => $item_bibnum,
155
    biblionumber  => $biblio->biblionumber,
157
    itemnumber    => $itemnumber,
156
    itemnumber    => $itemnumber,
158
    borrowernumber => $borrowernumber,
157
    borrowernumber => $borrowernumber,
159
});
158
});
Lines 242-257 is( $hold->priority, '6', "Test AlterPriority(), move to bottom" ); Link Here
242
# IndependentBranches is OFF.
241
# IndependentBranches is OFF.
243
242
244
my $foreign_biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
243
my $foreign_biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
245
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber)
244
my $foreign_itemnumber = $builder->build_sample_item({ library => $branch_2, biblionumber => $foreign_biblio->biblionumber })->itemnumber;
246
  = AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber);
245
$dbh->do('DELETE FROM issuingrules');
247
# Cleanup circulation rules
246
248
$dbh->do('DELETE FROM circulation_rules');
249
# $dbh->do(
250
#     q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
251
#       VALUES (?, ?, ?, ?, ?)},
252
#     {},
253
#     '*', '*', '*', 25, 99
254
# );
255
$dbh->do(
247
$dbh->do(
256
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
248
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
257
      VALUES (?, ?, ?, ?, ?)},
249
      VALUES (?, ?, ?, ?, ?)},
Lines 287-299 ok( Link Here
287
);
279
);
288
280
289
{
281
{
282
    my $item_bibnum;my $item_bibitemnum;
290
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
283
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
291
    $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
284
    $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
292
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
285
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
293
    my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1);
286
    my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1);
294
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
287
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
295
    my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2);
288
    my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2);
296
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
289
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
297
    my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3);
290
    my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3);
298
    my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber });
291
    my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber });
299
    my $hold3 = Koha::Holds->find( $reserveid3 );
292
    my $hold3 = Koha::Holds->find( $reserveid3 );
Lines 303-309 ok( Link Here
303
    is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
296
    is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
304
}
297
}
305
298
306
ModItem({ damaged => 1 }, $item_bibnum, $itemnumber);
299
ModItem({ damaged => 1 }, $biblio->biblionumber, $itemnumber);
307
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
300
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
308
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" );
301
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" );
309
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" );
302
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" );
Lines 312-318 $hold = Koha::Hold->new( Link Here
312
    {
305
    {
313
        borrowernumber => $borrowernumbers[0],
306
        borrowernumber => $borrowernumbers[0],
314
        itemnumber     => $itemnumber,
307
        itemnumber     => $itemnumber,
315
        biblionumber   => $item_bibnum,
308
        biblionumber   => $biblio->biblionumber,
316
    }
309
    }
317
)->store();
310
)->store();
318
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
311
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
Lines 326-332 ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for d Link Here
326
319
327
# Regression test for bug 9532
320
# Regression test for bug 9532
328
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
321
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
329
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
322
$itemnumber = $builder->build_sample_item({ library => $branch_1, itype => 'CANNOT', biblionumber => $biblio->biblionumber})->itemnumber;
330
AddReserve(
323
AddReserve(
331
    $branch_1,
324
    $branch_1,
332
    $borrowernumbers[0],
325
    $borrowernumbers[0],
Lines 338-351 is( Link Here
338
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves',
331
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves',
339
    "cannot request item if policy that matches on item-level item type forbids it"
332
    "cannot request item if policy that matches on item-level item type forbids it"
340
);
333
);
341
ModItem({ itype => 'CAN' }, $item_bibnum, $itemnumber);
334
ModItem({ itype => 'CAN' }, $biblio->biblionumber, $itemnumber);
342
ok(
335
ok(
343
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK',
336
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK',
344
    "can request item if policy that matches on item type allows it"
337
    "can request item if policy that matches on item type allows it"
345
);
338
);
346
339
347
t::lib::Mocks::mock_preference('item-level_itypes', 0);
340
t::lib::Mocks::mock_preference('item-level_itypes', 0);
348
ModItem({ itype => undef }, $item_bibnum, $itemnumber);
341
ModItem({ itype => undef }, $biblio->biblionumber, $itemnumber);
349
ok(
342
ok(
350
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves',
343
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves',
351
    "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)"
344
    "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)"
Lines 385-398 Koha::CirculationRules->set_rules( Link Here
385
    }
378
    }
386
);
379
);
387
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
380
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
388
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
381
$itemnumber = $builder->build_sample_item({ library => $branch_1, itype => 'CANNOT', biblionumber => $biblio->biblionumber})->itemnumber;
389
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
390
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable',
382
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable',
391
    "CanItemBeReserved should return 'notReservable'");
383
    "CanItemBeReserved should return 'notReservable'");
392
384
393
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
385
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
394
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
386
$itemnumber = $builder->build_sample_item({ library => $branch_2, itype => 'CAN', biblionumber => $biblio->biblionumber})->itemnumber;
395
    { homebranch => $branch_2, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber);
396
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
387
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
397
    'cannotReserveFromOtherBranches',
388
    'cannotReserveFromOtherBranches',
398
    "CanItemBeReserved should use PatronLibrary rule when ReservesControlBranch set to 'PatronLibrary'");
389
    "CanItemBeReserved should use PatronLibrary rule when ReservesControlBranch set to 'PatronLibrary'");
Lines 401-408 is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, Link Here
401
    'OK',
392
    'OK',
402
    "CanItemBeReserved should use item home library rule when ReservesControlBranch set to 'ItemsHomeLibrary'");
393
    "CanItemBeReserved should use item home library rule when ReservesControlBranch set to 'ItemsHomeLibrary'");
403
394
404
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
395
$itemnumber = $builder->build_sample_item({ library => $branch_1, itype => 'CAN', biblionumber => $biblio->biblionumber})->itemnumber;
405
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber);
406
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK',
396
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK',
407
    "CanItemBeReserved should return 'OK'");
397
    "CanItemBeReserved should return 'OK'");
408
398
Lines 416-423 $dbh->do('DELETE FROM items'); Link Here
416
$dbh->do('DELETE FROM biblio');
406
$dbh->do('DELETE FROM biblio');
417
407
418
$biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
408
$biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
419
( $item_bibnum, $item_bibitemnum, $itemnumber )
409
$itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber})->itemnumber;
420
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
421
410
422
$dbh->do(
411
$dbh->do(
423
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
412
    q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 448-456 subtest 'Test max_holds per library/patron category' => sub { Link Here
448
    $dbh->do('DELETE FROM circulation_rules');
437
    $dbh->do('DELETE FROM circulation_rules');
449
438
450
    $biblio = $builder->build_sample_biblio({ itemtype => 'TEST' });
439
    $biblio = $builder->build_sample_biblio({ itemtype => 'TEST' });
451
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
440
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber})->itemnumber;
452
      AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
453
        $biblio->biblionumber );
454
    $dbh->do(
441
    $dbh->do(
455
        q{
442
        q{
456
            INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
443
            INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 518-525 subtest 'Pickup location availability tests' => sub { Link Here
518
    plan tests => 4;
505
    plan tests => 4;
519
506
520
    $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
507
    $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
521
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
508
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber})->itemnumber;
522
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
523
    #Add a default rule to allow some holds
509
    #Add a default rule to allow some holds
524
    $dbh->do(
510
    $dbh->do(
525
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
511
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
Lines 577-602 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
577
563
578
    # Create 3 biblios with items
564
    # Create 3 biblios with items
579
    my $biblio_1 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
565
    my $biblio_1 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
580
    my ( undef, undef, $itemnumber_1 ) = AddItem(
566
    my $itemnumber_1 = $builder->build_sample_item({ library => $library->branchcode, biblionumber => $biblio_1->biblionumber})->itemnumber;
581
        {   homebranch    => $library->branchcode,
582
            holdingbranch => $library->branchcode
583
        },
584
        $biblio_1->biblionumber
585
    );
586
    my $biblio_2 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
567
    my $biblio_2 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
587
    my ( undef, undef, $itemnumber_2 ) = AddItem(
568
    my $itemnumber_2 = $builder->build_sample_item({ library => $library->branchcode, biblionumber => $biblio_2->biblionumber})->itemnumber;
588
        {   homebranch    => $library->branchcode,
589
            holdingbranch => $library->branchcode
590
        },
591
        $biblio_2->biblionumber
592
    );
593
    my $biblio_3 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
569
    my $biblio_3 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
594
    my ( undef, undef, $itemnumber_3 ) = AddItem(
570
    my $itemnumber_3 = $builder->build_sample_item({ library => $library->branchcode, biblionumber => $biblio_3->biblionumber})->itemnumber;
595
        {   homebranch    => $library->branchcode,
596
            holdingbranch => $library->branchcode
597
        },
598
        $biblio_3->biblionumber
599
    );
600
571
601
    Koha::IssuingRules->search->delete;
572
    Koha::IssuingRules->search->delete;
602
    my $issuingrule = Koha::IssuingRule->new(
573
    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 (-42 / +80 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 319-325 subtest 'GetItemsInfo tests' => sub { Link Here
319
    is( $results[0]->{ has_pending_hold }, "0",
332
    is( $results[0]->{ has_pending_hold }, "0",
320
        'Hold not marked as pending/unavailable if nothing in tmp_holdsqueue for item' );
333
        'Hold not marked as pending/unavailable if nothing in tmp_holdsqueue for item' );
321
334
322
    $dbh->do(q{INSERT INTO tmp_holdsqueue (biblionumber, itemnumber, surname, borrowernumber ) VALUES (?, ?, "Zorro", 42)}, undef, $item_bibnum, $itemnumber);
335
    $dbh->do(q{INSERT INTO tmp_holdsqueue (biblionumber, itemnumber, surname, borrowernumber ) VALUES (?, ?, "Zorro", 42)}, undef, $biblio->biblionumber, $itemnumber);
323
    @results = GetItemsInfo( $biblio->biblionumber );
336
    @results = GetItemsInfo( $biblio->biblionumber );
324
    is( $results[0]->{ has_pending_hold }, "1",
337
    is( $results[0]->{ has_pending_hold }, "1",
325
        'Hold marked as pending/unavailable if tmp_holdsqueue is not empty for item' );
338
        'Hold marked as pending/unavailable if tmp_holdsqueue is not empty for item' );
Lines 393-398 subtest 'SearchItems test' => sub { Link Here
393
    my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
406
    my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
394
407
395
    # Add two items
408
    # Add two items
409
<<<<<<< HEAD
396
    my (undef, undef, $item1_itemnumber) = AddItem({
410
    my (undef, undef, $item1_itemnumber) = AddItem({
397
        homebranch => $library1->{branchcode},
411
        homebranch => $library1->{branchcode},
398
        holdingbranch => $library1->{branchcode},
412
        holdingbranch => $library1->{branchcode},
Lines 404-409 subtest 'SearchItems test' => sub { Link Here
404
        itype => $itemtype->{itemtype},
418
        itype => $itemtype->{itemtype},
405
        issues => 3,
419
        issues => 3,
406
    }, $biblio->biblionumber);
420
    }, $biblio->biblionumber);
421
=======
422
    my $item1_itemnumber = $builder->build_sample_item(
423
        {
424
            biblionumber => $biblio->biblionumber,
425
            library      => $library1->{branchcode},
426
            itype        => $itemtype->{itemtype}
427
        }
428
    )->itemnumber;
429
    my $item2_itemnumber = $builder->build_sample_item(
430
        {
431
            biblionumber => $biblio->biblionumber,
432
            library      => $library2->{branchcode},
433
            itype        => $itemtype->{itemtype}
434
        }
435
    )->itemnumber;
436
>>>>>>> Bug 23463: Replace AddItem calls with Koha::Item->store
407
437
408
    my ($items, $total_results);
438
    my ($items, $total_results);
409
439
Lines 585-599 subtest 'Koha::Item(s) tests' => sub { Link Here
585
615
586
    # Create a biblio and item for testing
616
    # Create a biblio and item for testing
587
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
617
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
588
    my $biblio = $builder->build_sample_biblio({title => 'Silence in the library'});
618
    my $biblio = $builder->build_sample_biblio();
589
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
619
    my $itemnumber = $builder->build_sample_item(
590
        {
620
        {
621
            biblionumber  => $biblio->biblionumber,
591
            homebranch    => $library1->{branchcode},
622
            homebranch    => $library1->{branchcode},
592
            holdingbranch => $library2->{branchcode},
623
            holdingbranch => $library2->{branchcode},
593
            itype         => $itemtype->{itemtype},
624
            itype         => $itemtype->{itemtype}
594
        },
625
        }
595
        $biblio->biblionumber
626
    )->itemnumber;
596
    );
597
627
598
    # Get item.
628
    # Get item.
599
    my $item = Koha::Items->find( $itemnumber );
629
    my $item = Koha::Items->find( $itemnumber );
Lines 608-615 subtest 'Koha::Item(s) tests' => sub { Link Here
608
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
638
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
609
639
610
    $biblio = $item->biblio();
640
    $biblio = $item->biblio();
611
    is( ref($biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" );
641
    is( ref($item->biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" );
612
    is( $biblio->title(), 'Silence in the library', 'Title matches biblio title' );
642
    is( $item->biblio->title(), $biblio->title, 'Title matches biblio title' );
613
643
614
    $schema->storage->txn_rollback;
644
    $schema->storage->txn_rollback;
615
};
645
};
Lines 647-660 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
647
677
648
    my @itemnumbers;
678
    my @itemnumbers;
649
    for my $item_info (@$item_infos) {
679
    for my $item_info (@$item_infos) {
650
        my ( undef, undef, $itemnumber ) = AddItem(
680
        my $itemnumber = $builder->build_sample_item(
651
            {
681
            {
682
                biblionumber  => $biblio->biblionumber,
652
                homebranch    => $item_info->{homebranch},
683
                homebranch    => $item_info->{homebranch},
653
                holdingbranch => $item_info->{holdingbanch},
684
                holdingbranch => $item_info->{holdingbranch},
654
                itype         => $itemtype->{itemtype},
685
                itype         => $itemtype->{itemtype}
655
            },
686
            }
656
            $biblio->biblionumber
687
        )->itemnumber;
657
        );
688
658
        push @itemnumbers, $itemnumber;
689
        push @itemnumbers, $itemnumber;
659
    }
690
    }
660
691
Lines 926-932 subtest 'Test logging for ModItem' => sub { Link Here
926
    my $biblio = $builder->build_sample_biblio();
957
    my $biblio = $builder->build_sample_biblio();
927
958
928
    # Add an item.
959
    # Add an item.
929
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber);
960
    my $itemnumber = $builder->build_sample_item(
961
        {
962
            biblionumber => $biblio->biblionumber,
963
            library      => $library->{homebranch},
964
            location     => $location,
965
            itype        => $itemtype->{itemtype}
966
        }
967
    )->itemnumber;
930
968
931
    # False means no logging
969
    # False means no logging
932
    $schema->resultset('ActionLog')->search()->delete();
970
    $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 147-155 subtest 'can_be_transferred' => sub { Link Here
147
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
147
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
148
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
148
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
149
    my $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
149
    my $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
150
    my ($item_bibnum, $item_bibitemnum, $itemnumber)
150
    my $item = $builder->build_sample_item(
151
        = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library1->branchcode }, $biblio->biblionumber);
151
        {
152
    my $item  = Koha::Items->find($itemnumber);
152
            biblionumber => $biblio->biblionumber,
153
            library      => $library1->branchcode
154
        }
155
    );
153
156
154
    is(Koha::Item::Transfer::Limits->search({
157
    is(Koha::Item::Transfer::Limits->search({
155
        fromBranch => $library1->branchcode,
158
        fromBranch => $library1->branchcode,
Lines 177-185 subtest 'can_be_transferred' => sub { Link Here
177
    is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the '
180
    is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the '
178
         .'items is already located at to-library, then the transfer is possible.');
181
         .'items is already located at to-library, then the transfer is possible.');
179
    $item->holdingbranch($library1->branchcode)->store;
182
    $item->holdingbranch($library1->branchcode)->store;
180
    my ($item_bibnum2, $item_bibitemnum2, $itemnumber2)
183
181
        = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library3->branchcode }, $biblio->biblionumber);
184
    my $item2 = $builder->build_sample_item(
182
    my $item2  = Koha::Items->find($itemnumber2);
185
        {
186
            biblionumber  => $biblio->biblionumber,
187
            homebranch    => $library1->branchcode,
188
            holdingbranch => $library3->branchcode,
189
        }
190
    );
183
    is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added '
191
    is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added '
184
        .'another item that should have no transfer limits applying on, then '
192
        .'another item that should have no transfer limits applying on, then '
185
        .'the transfer is possible.');
193
        .'the transfer is possible.');
(-)a/t/db_dependent/Koha/Items.t (+23 lines)
Lines 28-36 use Koha::Item; Link Here
28
use Koha::Item::Transfer::Limits;
28
use Koha::Item::Transfer::Limits;
29
use Koha::Items;
29
use Koha::Items;
30
use Koha::Database;
30
use Koha::Database;
31
use Koha::DateUtils qw( dt_from_string );
31
32
32
use t::lib::TestBuilder;
33
use t::lib::TestBuilder;
33
use t::lib::Mocks;
34
use t::lib::Mocks;
35
use t::lib::Dates;
34
36
35
my $schema = Koha::Database->new->schema;
37
my $schema = Koha::Database->new->schema;
36
$schema->storage->txn_begin;
38
$schema->storage->txn_begin;
Lines 61-66 is( Koha::Items->search->count, $nb_of_items + 2, 'The 2 items should have been Link Here
61
my $retrieved_item_1 = Koha::Items->find( $new_item_1->itemnumber );
63
my $retrieved_item_1 = Koha::Items->find( $new_item_1->itemnumber );
62
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' );
64
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' );
63
65
66
subtest 'store' => sub {
67
    plan tests => 4;
68
    my $biblio = $builder->build_sample_biblio;
69
    my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 );
70
    my $item = Koha::Item->new(
71
        {
72
            homebranch    => $library->{branchcode},
73
            holdingbranch => $library->{branchcode},
74
            biblionumber  => $biblio->biblionumber,
75
            location      => 'my_loc',
76
        }
77
    )->store
78
    ->get_from_storage;
79
80
    is( t::lib::Dates::compare($item->replacementpricedate, $today), 0, 'replacementpricedate must have been set to today if not given');
81
    is( t::lib::Dates::compare($item->datelastseen,         $today), 0, 'datelastseen must have been set to today if not given');
82
    is( $item->itype, $biblio->biblioitem->itemtype, 'items.itype must have been set to biblioitem.itemtype is not given');
83
    is( $item->permanent_location, $item->location, 'permanent_location must have been set to location if not given' );
84
    $item->delete;
85
};
86
64
subtest 'get_transfer' => sub {
87
subtest 'get_transfer' => sub {
65
    plan tests => 3;
88
    plan tests => 3;
66
89
(-)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 182-189 sub build_sample_item { Link Here
182
    my $library = delete $args->{library}
182
    my $library = delete $args->{library}
183
      || $self->build_object( { class => 'Koha::Libraries' } )->branchcode;
183
      || $self->build_object( { class => 'Koha::Libraries' } )->branchcode;
184
184
185
    my $itype = delete $args->{itype}
185
    # If itype is not passed it will be picked from the biblio (see Koha::Item->store)
186
      || $self->build_object( { class => 'Koha::ItemTypes' } )->itemtype;
187
186
188
    my $barcode = delete $args->{barcode}
187
    my $barcode = delete $args->{barcode}
189
      || $self->_gen_text( { info => { size => SIZE_BARCODE } } );
188
      || $self->_gen_text( { info => { size => SIZE_BARCODE } } );
Lines 193-199 sub build_sample_item { Link Here
193
            homebranch    => $library,
192
            homebranch    => $library,
194
            holdingbranch => $library,
193
            holdingbranch => $library,
195
            barcode       => $barcode,
194
            barcode       => $barcode,
196
            itype         => $itype,
197
            %$args,
195
            %$args,
198
        },
196
        },
199
        $biblionumber
197
        $biblionumber
200
- 

Return to bug 23463