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 2742-2756 subtest '_FixAccountForLostAndFound' => sub { Link Here
2742
                }
2742
                }
2743
            }
2743
            }
2744
        );
2744
        );
2745
        my ( undef, undef, $item_id ) = AddItem(
2745
        my $item_id = Koha::Item->new(
2746
            {   homebranch       => $library->branchcode,
2746
            {
2747
                biblionumber     => $biblio->biblionumber,
2748
                homebranch       => $library->branchcode,
2747
                holdingbranch    => $library->branchcode,
2749
                holdingbranch    => $library->branchcode,
2748
                barcode          => $barcode,
2750
                barcode          => $barcode,
2749
                replacementprice => $replacement_amount,
2751
                replacementprice => $replacement_amount,
2750
                itype            => $item_type->itemtype
2752
                itype            => $item_type->itemtype
2751
            },
2753
            },
2752
            $biblio->biblionumber
2754
        )->store->itemnumber;
2753
        );
2754
2755
2755
        AddIssue( $patron->unblessed, $barcode );
2756
        AddIssue( $patron->unblessed, $barcode );
2756
2757
Lines 3355-3370 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
3355
    });
3356
    });
3356
3357
3357
    my $biblio = $builder->build_sample_biblio({ title=> $title, author => $author });
3358
    my $biblio = $builder->build_sample_biblio({ title=> $title, author => $author });
3358
    my ( undef, undef, $item_id ) = AddItem(
3359
    my $item_id = Koha::Item->new(
3359
        {
3360
        {
3361
            biblionumber     => $biblio->biblionumber,
3360
            homebranch       => $library->id,
3362
            homebranch       => $library->id,
3361
            holdingbranch    => $library->id,
3363
            holdingbranch    => $library->id,
3362
            barcode          => $barcode,
3364
            barcode          => $barcode,
3363
            replacementprice => 23.00,
3365
            replacementprice => 23.00,
3364
            itype            => $itemtype->id
3366
            itype            => $itemtype->id
3365
        },
3367
        },
3366
        $biblio->biblionumber
3368
    )->store->itemnumber;
3367
    );
3368
    my $item = Koha::Items->find( $item_id );
3369
    my $item = Koha::Items->find( $item_id );
3369
3370
3370
    my $context = Test::MockModule->new('C4::Context');
3371
    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 60-71 $record->append_fields( Link Here
60
59
61
my $barcode = 'bc_maxsuspensiondays';
60
my $barcode = 'bc_maxsuspensiondays';
62
my ($biblionumber, $biblioitemnumber) = AddBiblio($record, '');
61
my ($biblionumber, $biblioitemnumber) = AddBiblio($record, '');
63
my (undef, undef, $itemnumber) = AddItem({
62
my $itemnumber = Koha::Item->new({
63
        biblionumber => $biblionumber,
64
        homebranch => $branchcode,
64
        homebranch => $branchcode,
65
        holdingbranch => $branchcode,
65
        holdingbranch => $branchcode,
66
        barcode => $barcode,
66
        barcode => $barcode,
67
        itype => $itemtype
67
        itype => $itemtype
68
    } , $biblionumber);
68
    })->store->itemnumber;
69
69
70
# clear any holidays to avoid throwing off the suspension day
70
# clear any holidays to avoid throwing off the suspension day
71
# calculations
71
# 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 353-361 AddReturn($barcode_1, undef, undef, dt_from_string('2014-04-01 23:42')); Link Here
353
$return = $dbh->selectrow_hashref("SELECT * FROM old_issues LIMIT 1" );
348
$return = $dbh->selectrow_hashref("SELECT * FROM old_issues LIMIT 1" );
354
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" );
349
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" );
355
350
356
my $itemnumber;
351
my $itemnumber = Koha::Item->new(
357
($biblionumber, $biblioitemnumber, $itemnumber) = C4::Items::AddItem(
358
    {
352
    {
353
        biblionumber   => $biblionumber,
359
        barcode        => 'barcode_3',
354
        barcode        => 'barcode_3',
360
        itemcallnumber => 'callnumber3',
355
        itemcallnumber => 'callnumber3',
361
        homebranch     => $branchcode_1,
356
        homebranch     => $branchcode_1,
Lines 363-370 my $itemnumber; Link Here
363
        notforloan     => 1,
358
        notforloan     => 1,
364
        itype          => $itemtype
359
        itype          => $itemtype
365
    },
360
    },
366
    $biblionumber
361
)->store->itemnumber;
367
);
368
362
369
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} );
363
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} );
370
AddReturn( 'barcode_3', $branchcode_1 );
364
AddReturn( 'barcode_3', $branchcode_1 );
Lines 380-397 AddReturn( 'barcode_3', $branchcode_1 ); Link Here
380
$item = Koha::Items->find( $itemnumber );
374
$item = Koha::Items->find( $itemnumber );
381
ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} );
375
ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} );
382
376
383
my $itemnumber2;
377
my $itemnumber2 = Koha::Item->new(
384
($biblionumber, $biblioitemnumber, $itemnumber2) = C4::Items::AddItem(
385
    {
378
    {
379
        biblionumber   => $biblionumber,
386
        barcode        => 'barcode_4',
380
        barcode        => 'barcode_4',
387
        itemcallnumber => 'callnumber4',
381
        itemcallnumber => 'callnumber4',
388
        homebranch     => $branchcode_1,
382
        homebranch     => $branchcode_1,
389
        holdingbranch  => $branchcode_1,
383
        holdingbranch  => $branchcode_1,
390
        location => 'FIC',
384
        location       => 'FIC',
391
        itype          => $itemtype
385
        itype          => $itemtype
392
    },
386
    }
393
    $biblionumber
387
)->store->itemnumber;
394
);
395
388
396
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', q{} );
389
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', q{} );
397
AddReturn( 'barcode_4', $branchcode_1 );
390
AddReturn( 'barcode_4', $branchcode_1 );
(-)a/t/db_dependent/Circulation/transfers.t (-10 / +10 lines)
Lines 69-94 $record->append_fields( Link Here
69
    MARC::Field->new( '952', '0', '0', a => $branchcode_1 ) );
69
    MARC::Field->new( '952', '0', '0', a => $branchcode_1 ) );
70
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', );
70
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', );
71
71
72
my @sampleitem1 = C4::Items::AddItem(
72
my $item_id1 = Koha::Item->new(
73
    {   barcode        => 1,
73
    {
74
        biblionumber   => $biblionumber,
75
        barcode        => 1,
74
        itemcallnumber => 'callnumber1',
76
        itemcallnumber => 'callnumber1',
75
        homebranch     => $branchcode_1,
77
        homebranch     => $branchcode_1,
76
        holdingbranch  => $branchcode_1,
78
        holdingbranch  => $branchcode_1,
77
        itype          => $itemtype
79
        itype          => $itemtype
78
    },
80
    },
79
    $biblionumber
81
)->store->itemnumber;
80
);
82
my $item_id2 = Koha::Item->new(
81
my $item_id1    = $sampleitem1[2];
83
    {
82
my @sampleitem2 = C4::Items::AddItem(
84
        biblionumber   => $biblionumber,
83
    {   barcode        => 2,
85
        barcode        => 2,
84
        itemcallnumber => 'callnumber2',
86
        itemcallnumber => 'callnumber2',
85
        homebranch     => $branchcode_1,
87
        homebranch     => $branchcode_1,
86
        holdingbranch  => $branchcode_1,
88
        holdingbranch  => $branchcode_1,
87
        itype          => $itemtype
89
        itype          => $itemtype
88
    },
90
    },
89
    $biblionumber
91
)->store->itemnumber;
90
);
91
my $item_id2 = $sampleitem2[2];
92
92
93
#Add transfers
93
#Add transfers
94
ModItemTransfer(
94
ModItemTransfer(
(-)a/t/db_dependent/CourseReserves.t (-6 / +6 lines)
Lines 17-29 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 27;
20
use Test::More tests => 26;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
24
25
BEGIN {
25
BEGIN {
26
    use_ok('C4::Items', qw(AddItem));
27
    use_ok('C4::Biblio');
26
    use_ok('C4::Biblio');
28
    use_ok('C4::CourseReserves', qw/:all/);
27
    use_ok('C4::CourseReserves', qw/:all/);
29
    use_ok('C4::Context');
28
    use_ok('C4::Context');
Lines 50-62 foreach (1..10) { Link Here
50
# Create the a record with an item
49
# Create the a record with an item
51
my $record = MARC::Record->new;
50
my $record = MARC::Record->new;
52
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
51
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
53
my ( undef, undef, $itemnumber ) = C4::Items::AddItem(
52
my $itemnumber = Koha::Item->new(
54
    {   homebranch    => $branchcode,
53
    {
54
        biblionumber  => $biblionumber,
55
        homebranch    => $branchcode,
55
        holdingbranch => $branchcode,
56
        holdingbranch => $branchcode,
56
        itype         => $itemtype
57
        itype         => $itemtype
57
    },
58
    },
58
    $biblionumber
59
)->store->itemnumber;
59
);
60
60
61
my $course_id = ModCourse(
61
my $course_id = ModCourse(
62
    course_name => "Test Course",
62
    course_name => "Test Course",
(-)a/t/db_dependent/Holds.t (-44 / +20 lines)
Lines 58-65 $insert_sth->execute('ONLY1'); Link Here
58
my $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
58
my $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
59
59
60
# Create item instance for testing.
60
# Create item instance for testing.
61
my ($item_bibnum, $item_bibitemnum, $itemnumber)
61
my $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
62
    = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
63
62
64
# Create some borrowers
63
# Create some borrowers
65
my @borrowernumbers;
64
my @borrowernumbers;
Lines 148-154 is( $hold->suspend_until, '2013-01-01 00:00:00', "Test ModReserve, suspend until Link Here
148
147
149
ModReserve({ # call without reserve_id
148
ModReserve({ # call without reserve_id
150
    rank          => '3',
149
    rank          => '3',
151
    biblionumber  => $item_bibnum,
150
    biblionumber  => $biblio->biblionumber,
152
    itemnumber    => $itemnumber,
151
    itemnumber    => $itemnumber,
153
    borrowernumber => $borrowernumber,
152
    borrowernumber => $borrowernumber,
154
});
153
});
Lines 232-239 is( $hold->priority, '6', "Test AlterPriority(), move to bottom" ); Link Here
232
# IndependentBranches is OFF.
231
# IndependentBranches is OFF.
233
232
234
my $foreign_biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
233
my $foreign_biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
235
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber)
234
my $foreign_itemnumber = $builder->build_sample_item({ library => $branch_2, biblionumber => $foreign_biblio->biblionumber })->itemnumber;
236
  = AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber);
237
Koha::CirculationRules->set_rules(
235
Koha::CirculationRules->set_rules(
238
    {
236
    {
239
        categorycode => undef,
237
        categorycode => undef,
Lines 287-293 ok( Link Here
287
{
285
{
288
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
286
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
289
    $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
287
    $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
290
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
288
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
291
    my $reserveid1 = AddReserve(
289
    my $reserveid1 = AddReserve(
292
        {
290
        {
293
            branchcode     => $branch_1,
291
            branchcode     => $branch_1,
Lines 297-303 ok( Link Here
297
        }
295
        }
298
    );
296
    );
299
297
300
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
298
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
301
    my $reserveid2 = AddReserve(
299
    my $reserveid2 = AddReserve(
302
        {
300
        {
303
            branchcode     => $branch_1,
301
            branchcode     => $branch_1,
Lines 307-313 ok( Link Here
307
        }
305
        }
308
    );
306
    );
309
307
310
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber);
308
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
311
    my $reserveid3 = AddReserve(
309
    my $reserveid3 = AddReserve(
312
        {
310
        {
313
            branchcode     => $branch_1,
311
            branchcode     => $branch_1,
Lines 325-331 ok( Link Here
325
    is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
323
    is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
326
}
324
}
327
325
328
ModItem({ damaged => 1 }, $item_bibnum, $itemnumber);
326
ModItem({ damaged => 1 }, $biblio->biblionumber, $itemnumber);
329
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
327
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
330
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" );
328
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" );
331
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" );
329
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" );
Lines 334-340 $hold = Koha::Hold->new( Link Here
334
    {
332
    {
335
        borrowernumber => $borrowernumbers[0],
333
        borrowernumber => $borrowernumbers[0],
336
        itemnumber     => $itemnumber,
334
        itemnumber     => $itemnumber,
337
        biblionumber   => $item_bibnum,
335
        biblionumber   => $biblio->biblionumber,
338
    }
336
    }
339
)->store();
337
)->store();
340
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
338
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
Lines 348-354 ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for d Link Here
348
346
349
# Regression test for bug 9532
347
# Regression test for bug 9532
350
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
348
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
351
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
349
$itemnumber = $builder->build_sample_item({ library => $branch_1, itype => 'CANNOT', biblionumber => $biblio->biblionumber})->itemnumber;
352
AddReserve(
350
AddReserve(
353
    {
351
    {
354
        branchcode     => $branch_1,
352
        branchcode     => $branch_1,
Lines 361-374 is( Link Here
361
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves',
359
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves',
362
    "cannot request item if policy that matches on item-level item type forbids it"
360
    "cannot request item if policy that matches on item-level item type forbids it"
363
);
361
);
364
ModItem({ itype => 'CAN' }, $item_bibnum, $itemnumber);
362
ModItem({ itype => 'CAN' }, $biblio->biblionumber, $itemnumber);
365
ok(
363
ok(
366
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK',
364
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK',
367
    "can request item if policy that matches on item type allows it"
365
    "can request item if policy that matches on item type allows it"
368
);
366
);
369
367
370
t::lib::Mocks::mock_preference('item-level_itypes', 0);
368
t::lib::Mocks::mock_preference('item-level_itypes', 0);
371
ModItem({ itype => undef }, $item_bibnum, $itemnumber);
369
ModItem({ itype => undef }, $biblio->biblionumber, $itemnumber);
372
ok(
370
ok(
373
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves',
371
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves',
374
    "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)"
372
    "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)"
Lines 410-423 Koha::CirculationRules->set_rules( Link Here
410
    }
408
    }
411
);
409
);
412
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
410
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
413
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
411
$itemnumber = $builder->build_sample_item({ library => $branch_1, itype => 'CANNOT', biblionumber => $biblio->biblionumber})->itemnumber;
414
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber);
415
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable',
412
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable',
416
    "CanItemBeReserved should return 'notReservable'");
413
    "CanItemBeReserved should return 'notReservable'");
417
414
418
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
415
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
419
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
416
$itemnumber = $builder->build_sample_item({ library => $branch_2, itype => 'CAN', biblionumber => $biblio->biblionumber})->itemnumber;
420
    { homebranch => $branch_2, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber);
421
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
417
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
422
    'cannotReserveFromOtherBranches',
418
    'cannotReserveFromOtherBranches',
423
    "CanItemBeReserved should use PatronLibrary rule when ReservesControlBranch set to 'PatronLibrary'");
419
    "CanItemBeReserved should use PatronLibrary rule when ReservesControlBranch set to 'PatronLibrary'");
Lines 426-433 is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, Link Here
426
    'OK',
422
    'OK',
427
    "CanItemBeReserved should use item home library rule when ReservesControlBranch set to 'ItemsHomeLibrary'");
423
    "CanItemBeReserved should use item home library rule when ReservesControlBranch set to 'ItemsHomeLibrary'");
428
424
429
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
425
$itemnumber = $builder->build_sample_item({ library => $branch_1, itype => 'CAN', biblionumber => $biblio->biblionumber})->itemnumber;
430
    { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblio->biblionumber);
431
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK',
426
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK',
432
    "CanItemBeReserved should return 'OK'");
427
    "CanItemBeReserved should return 'OK'");
433
428
Lines 441-448 $dbh->do('DELETE FROM items'); Link Here
441
$dbh->do('DELETE FROM biblio');
436
$dbh->do('DELETE FROM biblio');
442
437
443
$biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
438
$biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
444
( $item_bibnum, $item_bibitemnum, $itemnumber )
439
$itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber})->itemnumber;
445
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
446
440
447
Koha::CirculationRules->set_rules(
441
Koha::CirculationRules->set_rules(
448
    {
442
    {
Lines 483-491 subtest 'Test max_holds per library/patron category' => sub { Link Here
483
    $dbh->do('DELETE FROM reserves');
477
    $dbh->do('DELETE FROM reserves');
484
478
485
    $biblio = $builder->build_sample_biblio;
479
    $biblio = $builder->build_sample_biblio;
486
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
480
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber})->itemnumber;
487
      AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
488
        $biblio->biblionumber );
489
    Koha::CirculationRules->set_rules(
481
    Koha::CirculationRules->set_rules(
490
        {
482
        {
491
            categorycode => undef,
483
            categorycode => undef,
Lines 562-569 subtest 'Pickup location availability tests' => sub { Link Here
562
    plan tests => 4;
554
    plan tests => 4;
563
555
564
    $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
556
    $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
565
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
557
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber})->itemnumber;
566
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
567
    #Add a default rule to allow some holds
558
    #Add a default rule to allow some holds
568
559
569
    Koha::CirculationRules->set_rules(
560
    Koha::CirculationRules->set_rules(
Lines 625-650 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
625
616
626
    # Create 3 biblios with items
617
    # Create 3 biblios with items
627
    my $biblio_1 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
618
    my $biblio_1 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
628
    my ( undef, undef, $itemnumber_1 ) = AddItem(
619
    my $itemnumber_1 = $builder->build_sample_item({ library => $library->branchcode, biblionumber => $biblio_1->biblionumber})->itemnumber;
629
        {   homebranch    => $library->branchcode,
630
            holdingbranch => $library->branchcode
631
        },
632
        $biblio_1->biblionumber
633
    );
634
    my $biblio_2 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
620
    my $biblio_2 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
635
    my ( undef, undef, $itemnumber_2 ) = AddItem(
621
    my $itemnumber_2 = $builder->build_sample_item({ library => $library->branchcode, biblionumber => $biblio_2->biblionumber})->itemnumber;
636
        {   homebranch    => $library->branchcode,
637
            holdingbranch => $library->branchcode
638
        },
639
        $biblio_2->biblionumber
640
    );
641
    my $biblio_3 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
622
    my $biblio_3 = $builder->build_sample_biblio({ itemtype => $itemtype->itemtype });
642
    my ( undef, undef, $itemnumber_3 ) = AddItem(
623
    my $itemnumber_3 = $builder->build_sample_item({ library => $library->branchcode, biblionumber => $biblio_3->biblionumber})->itemnumber;
643
        {   homebranch    => $library->branchcode,
644
            holdingbranch => $library->branchcode
645
        },
646
        $biblio_3->biblionumber
647
    );
648
624
649
    Koha::CirculationRules->search->delete;
625
    Koha::CirculationRules->search->delete;
650
    Koha::CirculationRules->set_rules(
626
    Koha::CirculationRules->set_rules(
(-)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 (-53 / +77 lines)
Lines 59-72 subtest 'General Add, Get and Del tests' => sub { Link Here
59
    my $biblio = $builder->build_sample_biblio();
59
    my $biblio = $builder->build_sample_biblio();
60
60
61
    # Add an item.
61
    # Add an item.
62
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber);
62
    my $item = $builder->build_sample_item(
63
    cmp_ok($item_bibnum, '==', $biblio->biblionumber, "New item is linked to correct biblionumber.");
63
        {
64
    cmp_ok($item_bibitemnum, '==', $biblio->biblioitem->biblioitemnumber, "New item is linked to correct biblioitemnumber.");
64
            biblionumber => $biblio->biblionumber,
65
            library      => $library->{branchcode},
66
            location     => $location,
67
            itype        => $itemtype->{itemtype}
68
        }
69
    );
70
    my $itemnumber = $item->itemnumber;
71
    cmp_ok($item->biblionumber, '==', $biblio->biblionumber, "New item is linked to correct biblionumber.");
72
    cmp_ok($item->biblioitemnumber, '==', $biblio->biblioitem->biblioitemnumber, "New item is linked to correct biblioitemnumber.");
65
73
66
    # Get item.
74
    # Get item.
67
    my $getitem = Koha::Items->find($itemnumber);
75
    my $getitem = Koha::Items->find($itemnumber);
68
    cmp_ok($getitem->itemnumber, '==', $itemnumber, "Retrieved item has correct itemnumber.");
76
    cmp_ok($getitem->itemnumber, '==', $itemnumber, "Retrieved item has correct itemnumber.");
69
    cmp_ok($getitem->biblioitemnumber, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber.");
77
    cmp_ok($getitem->biblioitemnumber, '==', $item->biblioitemnumber, "Retrieved item has correct biblioitemnumber."); # We are not testing anything useful here
70
    is( $getitem->location, $location, "The location should not have been modified" );
78
    is( $getitem->location, $location, "The location should not have been modified" );
71
    is( $getitem->permanent_location, $location, "The permanent_location should have been set to the location value" );
79
    is( $getitem->permanent_location, $location, "The permanent_location should have been set to the location value" );
72
80
Lines 86-92 subtest 'General Add, Get and Del tests' => sub { Link Here
86
    my $getdeleted = Koha::Items->find($itemnumber);
94
    my $getdeleted = Koha::Items->find($itemnumber);
87
    is($getdeleted, undef, "Item deleted as expected.");
95
    is($getdeleted, undef, "Item deleted as expected.");
88
96
89
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $biblio->biblionumber);
97
    $itemnumber = $builder->build_sample_item(
98
        {
99
            biblionumber => $biblio->biblionumber,
100
            library      => $library->{branchcode},
101
            location     => $location,
102
            permanent_location => 'my permanent location',
103
            itype        => $itemtype->{itemtype}
104
        }
105
    )->itemnumber;
90
    $getitem = Koha::Items->find($itemnumber);
106
    $getitem = Koha::Items->find($itemnumber);
91
    is( $getitem->location, $location, "The location should not have been modified" );
107
    is( $getitem->location, $location, "The location should not have been modified" );
92
    is( $getitem->permanent_location, 'my permanent location', "The permanent_location should not have modified" );
108
    is( $getitem->permanent_location, 'my permanent location', "The permanent_location should not have modified" );
Lines 226-250 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
226
    my $biblio = $builder->build_sample_biblio();
242
    my $biblio = $builder->build_sample_biblio();
227
243
228
    # Add two items
244
    # Add two items
229
    my ( $item1_bibnum, $item1_bibitemnum, $item1_itemnumber ) = AddItem(
245
    my $item1_itemnumber = $builder->build_sample_item(
230
        {
246
        {
231
            homebranch    => $library1->{branchcode},
247
            biblionumber => $biblio->biblionumber,
232
            holdingbranch => $library1->{branchcode},
248
            library      => $library1->{branchcode},
233
            withdrawn     => 1,
249
            withdrawn    => 1,
234
            itype         => $itemtype->{itemtype},
250
            itype        => $itemtype->{itemtype}
235
        },
251
        }
236
        $biblio->biblionumber
252
    )->itemnumber;
237
    );
253
    my $item2_itemnumber = $builder->build_sample_item(
238
    my ( $item2_bibnum, $item2_bibitemnum, $item2_itemnumber ) = AddItem(
239
        {
254
        {
240
            homebranch    => $library2->{branchcode},
255
            biblionumber => $biblio->biblionumber,
241
            holdingbranch => $library2->{branchcode},
256
            library      => $library2->{branchcode},
242
            withdrawn     => 0,
257
            withdrawn    => 0,
243
            itype         => $itemtype->{itemtype},
258
            itype        => $itemtype->{itemtype}
244
        },
259
        }
245
        $biblio->biblionumber
260
    )->itemnumber;
246
    );
247
248
    my $opachiddenitems;
261
    my $opachiddenitems;
249
    my @itemnumbers = ($item1_itemnumber,$item2_itemnumber);
262
    my @itemnumbers = ($item1_itemnumber,$item2_itemnumber);
250
    my @hidden;
263
    my @hidden;
Lines 333-347 subtest 'GetItemsInfo tests' => sub { Link Here
333
    # Add a biblio
346
    # Add a biblio
334
    my $biblio = $builder->build_sample_biblio();
347
    my $biblio = $builder->build_sample_biblio();
335
    # Add an item
348
    # Add an item
336
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
349
    my $itemnumber = $builder->build_sample_item(
337
        {
350
        {
351
            biblionumber  => $biblio->biblionumber,
338
            homebranch    => $library1->{branchcode},
352
            homebranch    => $library1->{branchcode},
339
            holdingbranch => $library2->{branchcode},
353
            holdingbranch => $library2->{branchcode},
340
            itype         => $itemtype->{itemtype},
354
            itype         => $itemtype->{itemtype},
341
            restricted    => 1,
355
            restricted    => 1,
342
        },
356
        }
343
        $biblio->biblionumber
357
    )->itemnumber;
344
    );
345
358
346
    my $library = Koha::Libraries->find( $library1->{branchcode} );
359
    my $library = Koha::Libraries->find( $library1->{branchcode} );
347
    $library->opac_info("homebranch OPAC info");
360
    $library->opac_info("homebranch OPAC info");
Lines 373-379 subtest 'GetItemsInfo tests' => sub { Link Here
373
    is( $results[0]->{ has_pending_hold }, "0",
386
    is( $results[0]->{ has_pending_hold }, "0",
374
        'Hold not marked as pending/unavailable if nothing in tmp_holdsqueue for item' );
387
        'Hold not marked as pending/unavailable if nothing in tmp_holdsqueue for item' );
375
388
376
    $dbh->do(q{INSERT INTO tmp_holdsqueue (biblionumber, itemnumber, surname, borrowernumber ) VALUES (?, ?, "Zorro", 42)}, undef, $item_bibnum, $itemnumber);
389
    $dbh->do(q{INSERT INTO tmp_holdsqueue (biblionumber, itemnumber, surname, borrowernumber ) VALUES (?, ?, "Zorro", 42)}, undef, $biblio->biblionumber, $itemnumber);
377
    @results = GetItemsInfo( $biblio->biblionumber );
390
    @results = GetItemsInfo( $biblio->biblionumber );
378
    is( $results[0]->{ has_pending_hold }, "1",
391
    is( $results[0]->{ has_pending_hold }, "1",
379
        'Hold marked as pending/unavailable if tmp_holdsqueue is not empty for item' );
392
        'Hold marked as pending/unavailable if tmp_holdsqueue is not empty for item' );
Lines 447-463 subtest 'SearchItems test' => sub { Link Here
447
    my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
460
    my (undef, $initial_items_count) = SearchItems(undef, {rows => 1});
448
461
449
    # Add two items
462
    # Add two items
450
    my (undef, undef, $item1_itemnumber) = AddItem({
463
    my $item1_itemnumber = $builder->build_sample_item(
451
        homebranch => $library1->{branchcode},
464
        {
452
        holdingbranch => $library1->{branchcode},
465
            biblionumber => $biblio->biblionumber,
453
        itype => $itemtype->{itemtype},
466
            library      => $library1->{branchcode},
454
    }, $biblio->biblionumber);
467
            itype        => $itemtype->{itemtype}
455
    my (undef, undef, $item2_itemnumber) = AddItem({
468
        }
456
        homebranch => $library2->{branchcode},
469
    )->itemnumber;
457
        holdingbranch => $library2->{branchcode},
470
    my $item2_itemnumber = $builder->build_sample_item(
458
        itype => $itemtype->{itemtype},
471
        {
459
        issues => 3,
472
            biblionumber => $biblio->biblionumber,
460
    }, $biblio->biblionumber);
473
            library      => $library2->{branchcode},
474
            itype        => $itemtype->{itemtype}
475
        }
476
    )->itemnumber;
461
477
462
    my ($items, $total_results);
478
    my ($items, $total_results);
463
479
Lines 639-653 subtest 'Koha::Item(s) tests' => sub { Link Here
639
655
640
    # Create a biblio and item for testing
656
    # Create a biblio and item for testing
641
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
657
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
642
    my $biblio = $builder->build_sample_biblio({title => 'Silence in the library'});
658
    my $biblio = $builder->build_sample_biblio();
643
    my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
659
    my $itemnumber = $builder->build_sample_item(
644
        {
660
        {
661
            biblionumber  => $biblio->biblionumber,
645
            homebranch    => $library1->{branchcode},
662
            homebranch    => $library1->{branchcode},
646
            holdingbranch => $library2->{branchcode},
663
            holdingbranch => $library2->{branchcode},
647
            itype         => $itemtype->{itemtype},
664
            itype         => $itemtype->{itemtype}
648
        },
665
        }
649
        $biblio->biblionumber
666
    )->itemnumber;
650
    );
651
667
652
    # Get item.
668
    # Get item.
653
    my $item = Koha::Items->find( $itemnumber );
669
    my $item = Koha::Items->find( $itemnumber );
Lines 662-669 subtest 'Koha::Item(s) tests' => sub { Link Here
662
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
678
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
663
679
664
    $biblio = $item->biblio();
680
    $biblio = $item->biblio();
665
    is( ref($biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" );
681
    is( ref($item->biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" );
666
    is( $biblio->title(), 'Silence in the library', 'Title matches biblio title' );
682
    is( $item->biblio->title(), $biblio->title, 'Title matches biblio title' );
667
683
668
    $schema->storage->txn_rollback;
684
    $schema->storage->txn_rollback;
669
};
685
};
Lines 701-714 subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { Link Here
701
717
702
    my @itemnumbers;
718
    my @itemnumbers;
703
    for my $item_info (@$item_infos) {
719
    for my $item_info (@$item_infos) {
704
        my ( undef, undef, $itemnumber ) = AddItem(
720
        my $itemnumber = $builder->build_sample_item(
705
            {
721
            {
722
                biblionumber  => $biblio->biblionumber,
706
                homebranch    => $item_info->{homebranch},
723
                homebranch    => $item_info->{homebranch},
707
                holdingbranch => $item_info->{holdingbanch},
724
                holdingbranch => $item_info->{holdingbranch},
708
                itype         => $itemtype->{itemtype},
725
                itype         => $itemtype->{itemtype}
709
            },
726
            }
710
            $biblio->biblionumber
727
        )->itemnumber;
711
        );
728
712
        push @itemnumbers, $itemnumber;
729
        push @itemnumbers, $itemnumber;
713
    }
730
    }
714
731
Lines 980-986 subtest 'Test logging for ModItem' => sub { Link Here
980
    my $biblio = $builder->build_sample_biblio();
997
    my $biblio = $builder->build_sample_biblio();
981
998
982
    # Add an item.
999
    # Add an item.
983
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $biblio->biblionumber);
1000
    my $itemnumber = $builder->build_sample_item(
1001
        {
1002
            biblionumber => $biblio->biblionumber,
1003
            library      => $library->{homebranch},
1004
            location     => $location,
1005
            itype        => $itemtype->{itemtype}
1006
        }
1007
    )->itemnumber;
984
1008
985
    # False means no logging
1009
    # False means no logging
986
    $schema->resultset('ActionLog')->search()->delete();
1010
    $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 144-152 subtest 'can_be_transferred' => sub { Link Here
144
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
144
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
145
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
145
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
146
    my $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
146
    my $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' });
147
    my ($item_bibnum, $item_bibitemnum, $itemnumber)
147
    my $item = $builder->build_sample_item(
148
        = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library1->branchcode }, $biblio->biblionumber);
148
        {
149
    my $item  = Koha::Items->find($itemnumber);
149
            biblionumber => $biblio->biblionumber,
150
            library      => $library1->branchcode
151
        }
152
    );
150
153
151
    is(Koha::Item::Transfer::Limits->search({
154
    is(Koha::Item::Transfer::Limits->search({
152
        fromBranch => $library1->branchcode,
155
        fromBranch => $library1->branchcode,
Lines 174-182 subtest 'can_be_transferred' => sub { Link Here
174
    is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the '
177
    is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given one of the '
175
         .'items is already located at to-library, then the transfer is possible.');
178
         .'items is already located at to-library, then the transfer is possible.');
176
    $item->holdingbranch($library1->branchcode)->store;
179
    $item->holdingbranch($library1->branchcode)->store;
177
    my ($item_bibnum2, $item_bibitemnum2, $itemnumber2)
180
178
        = AddItem({ homebranch => $library1->branchcode, holdingbranch => $library3->branchcode }, $biblio->biblionumber);
181
    my $item2 = $builder->build_sample_item(
179
    my $item2  = Koha::Items->find($itemnumber2);
182
        {
183
            biblionumber  => $biblio->biblionumber,
184
            homebranch    => $library1->branchcode,
185
            holdingbranch => $library3->branchcode,
186
        }
187
    );
180
    is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added '
188
    is($biblio->can_be_transferred({ to => $library2 }), 1, 'Given we added '
181
        .'another item that should have no transfer limits applying on, then '
189
        .'another item that should have no transfer limits applying on, then '
182
        .'the transfer is possible.');
190
        .'the transfer is possible.');
(-)a/t/db_dependent/Koha/Items.t (-1 / +24 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 10;
22
use Test::More tests => 11;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use C4::Circulation;
25
use C4::Circulation;
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 (-63 / +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 127-139 AddReserve( Link Here
127
    }
121
    }
128
);
122
);
129
123
130
my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
124
my ($status, $reserve, $all_reserves) = CheckReserves($item->itemnumber, $barcode);
131
125
132
is($status, "Reserved", "CheckReserves Test 1");
126
is($status, "Reserved", "CheckReserves Test 1");
133
127
134
ok(exists($reserve->{reserve_id}), 'CheckReserves() include reserve_id in its response');
128
ok(exists($reserve->{reserve_id}), 'CheckReserves() include reserve_id in its response');
135
129
136
($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
130
($status, $reserve, $all_reserves) = CheckReserves($item->itemnumber);
137
is($status, "Reserved", "CheckReserves Test 2");
131
is($status, "Reserved", "CheckReserves Test 2");
138
132
139
($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
133
($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 354-362 AddReserve( Link Here
354
        priority       => 1,
347
        priority       => 1,
355
    }
348
    }
356
);
349
);
357
($status)=CheckReserves($itemnumber,undef,undef);
350
($status)=CheckReserves($item->itemnumber,undef,undef);
358
is( $status, 'Reserved', 'CheckReserves returns reserve without lookahead');
351
is( $status, 'Reserved', 'CheckReserves returns reserve without lookahead');
359
($status)=CheckReserves($itemnumber,undef,7);
352
($status)=CheckReserves($item->itemnumber,undef,7);
360
is( $status, 'Reserved', 'CheckReserves also returns reserve with lookahead');
353
is( $status, 'Reserved', 'CheckReserves also returns reserve with lookahead');
361
354
362
# Test 9761b: Add a reserve with future date, CheckReserve should not return it
355
# Test 9761b: Add a reserve with future date, CheckReserve should not return it
Lines 374-386 AddReserve( Link Here
374
        reservation_date => $resdate,
367
        reservation_date => $resdate,
375
    }
368
    }
376
);
369
);
377
($status)=CheckReserves($itemnumber,undef,undef);
370
($status)=CheckReserves($item->itemnumber,undef,undef);
378
is( $status, '', 'CheckReserves returns no future reserve without lookahead');
371
is( $status, '', 'CheckReserves returns no future reserve without lookahead');
379
372
380
# Test 9761c: Add a reserve with future date, CheckReserve should return it if lookahead is high enough
373
# Test 9761c: Add a reserve with future date, CheckReserve should return it if lookahead is high enough
381
($status)=CheckReserves($itemnumber,undef,3);
374
($status)=CheckReserves($item->itemnumber,undef,3);
382
is( $status, '', 'CheckReserves returns no future reserve with insufficient lookahead');
375
is( $status, '', 'CheckReserves returns no future reserve with insufficient lookahead');
383
($status)=CheckReserves($itemnumber,undef,4);
376
($status)=CheckReserves($item->itemnumber,undef,4);
384
is( $status, 'Reserved', 'CheckReserves returns future reserve with sufficient lookahead');
377
is( $status, 'Reserved', 'CheckReserves returns future reserve with sufficient lookahead');
385
378
386
# Test 9761d: Check ResFound message of AddReturn for future hold
379
# Test 9761d: Check ResFound message of AddReturn for future hold
Lines 400-411 is(exists $messages->{ResFound}?1:0, 1, 'AddReturn considers future reserve with Link Here
400
393
401
# test marking a hold as captured
394
# test marking a hold as captured
402
my $hold_notice_count = count_hold_print_messages();
395
my $hold_notice_count = count_hold_print_messages();
403
ModReserveAffect($itemnumber, $requesters{$branch_1}, 0);
396
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0);
404
my $new_count = count_hold_print_messages();
397
my $new_count = count_hold_print_messages();
405
is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting');
398
is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting');
406
399
407
# test that duplicate notices aren't generated
400
# test that duplicate notices aren't generated
408
ModReserveAffect($itemnumber, $requesters{$branch_1}, 0);
401
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0);
409
$new_count = count_hold_print_messages();
402
$new_count = count_hold_print_messages();
410
is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)');
403
is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)');
411
404
Lines 452-464 AddReserve( Link Here
452
        biblionumber     => $bibnum,
445
        biblionumber     => $bibnum,
453
        priority         => 1,
446
        priority         => 1,
454
        reservation_date => $resdate,
447
        reservation_date => $resdate,
455
        itemnumber       => $itemnumber,
448
        itemnumber       => $item->itemnumber,
456
    }
449
    }
457
); #item level hold
450
); #item level hold
458
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
451
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
459
is( $future_holds->count, 0, 'current_holds does not return a future item level hold' );
452
is( $future_holds->count, 0, 'current_holds does not return a future item level hold' );
460
# 9788c: current_holds returns future wait (confirmed future hold)
453
# 9788c: current_holds returns future wait (confirmed future hold)
461
ModReserveAffect( $itemnumber,  $requesters{$branch_1} , 0); #confirm hold
454
ModReserveAffect( $item->itemnumber,  $requesters{$branch_1} , 0); #confirm hold
462
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
455
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
463
is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' );
456
is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' );
464
# End of tests for bug 9788
457
# End of tests for bug 9788
Lines 488-499 AddReserve( Link Here
488
        borrowernumber => $requesters{$branch_1},
481
        borrowernumber => $requesters{$branch_1},
489
        biblionumber   => $bibnum,
482
        biblionumber   => $bibnum,
490
        priority       => $p,
483
        priority       => $p,
491
        itemnumber     => $itemnumber,
484
        itemnumber     => $item->itemnumber,
492
    }
485
    }
493
);
486
);
494
$p = C4::Reserves::CalculatePriority($bibnum);
487
$p = C4::Reserves::CalculatePriority($bibnum);
495
is($p, 2, 'CalculatePriority should now return priority 2');
488
is($p, 2, 'CalculatePriority should now return priority 2');
496
ModReserveAffect( $itemnumber,  $requesters{$branch_1} , 0);
489
ModReserveAffect( $item->itemnumber,  $requesters{$branch_1} , 0);
497
$p = C4::Reserves::CalculatePriority($bibnum);
490
$p = C4::Reserves::CalculatePriority($bibnum);
498
is($p, 1, 'CalculatePriority should now return priority 1');
491
is($p, 1, 'CalculatePriority should now return priority 1');
499
#add another biblio hold, no resdate
492
#add another biblio hold, no resdate
Lines 533-543 AddReserve( Link Here
533
    {
526
    {
534
        branchcode     => $branch_1,
527
        branchcode     => $branch_1,
535
        borrowernumber => $requesters{$branch_1},
528
        borrowernumber => $requesters{$branch_1},
536
        biblionumber   => $item_bibnum,
529
        biblionumber   => $bibnum,
537
        priority       => 1,
530
        priority       => 1,
538
    }
531
    }
539
);
532
);
540
my (undef, $canres, undef) = CheckReserves($itemnumber);
533
my (undef, $canres, undef) = CheckReserves($item->itemnumber);
541
534
542
is( CanReserveBeCanceledFromOpac(), undef,
535
is( CanReserveBeCanceledFromOpac(), undef,
543
    'CanReserveBeCanceledFromOpac should return undef if called without any parameter'
536
    'CanReserveBeCanceledFromOpac should return undef if called without any parameter'
Lines 559-565 is($cancancel, 1, 'Can user cancel its own reserve'); Link Here
559
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_2});
552
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_2});
560
is($cancancel, 0, 'Other user cant cancel reserve');
553
is($cancancel, 0, 'Other user cant cancel reserve');
561
554
562
ModReserveAffect($itemnumber, $requesters{$branch_1}, 1);
555
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 1);
563
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
556
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
564
is($cancancel, 0, 'Reserve in transfer status cant be canceled');
557
is($cancancel, 0, 'Reserve in transfer status cant be canceled');
565
558
Lines 568-580 AddReserve( Link Here
568
    {
561
    {
569
        branchcode     => $branch_1,
562
        branchcode     => $branch_1,
570
        borrowernumber => $requesters{$branch_1},
563
        borrowernumber => $requesters{$branch_1},
571
        biblionumber   => $item_bibnum,
564
        biblionumber   => $bibnum,
572
        priority       => 1,
565
        priority       => 1,
573
    }
566
    }
574
);
567
);
575
(undef, $canres, undef) = CheckReserves($itemnumber);
568
(undef, $canres, undef) = CheckReserves($item->itemnumber);
576
569
577
ModReserveAffect($itemnumber, $requesters{$branch_1}, 0);
570
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0);
578
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
571
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
579
is($cancancel, 0, 'Reserve in waiting status cant be canceled');
572
is($cancancel, 0, 'Reserve in waiting status cant be canceled');
580
573
Lines 613-620 is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_with_no_item->{bibl Link Here
613
####### EO Bug 13113 <<<
606
####### EO Bug 13113 <<<
614
       ####
607
       ####
615
608
616
$item = Koha::Items->find($itemnumber);
617
618
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $patron), "Reserving a book on item level" );
609
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $patron), "Reserving a book on item level" );
619
610
620
my $pickup_branch = $builder->build({ source => 'Branch' })->{ branchcode };
611
my $pickup_branch = $builder->build({ source => 'Branch' })->{ branchcode };
Lines 653-677 AddReserve( Link Here
653
    {
644
    {
654
        branchcode     => $branch_1,
645
        branchcode     => $branch_1,
655
        borrowernumber => $borrowernumber,
646
        borrowernumber => $borrowernumber,
656
        biblionumber   => $item_bibnum,
647
        biblionumber   => $bibnum,
657
        priority       => 1,
648
        priority       => 1,
658
    }
649
    }
659
);
650
);
660
MoveReserve( $itemnumber, $borrowernumber );
651
MoveReserve( $item->itemnumber, $borrowernumber );
661
($status)=CheckReserves( $itemnumber );
652
($status)=CheckReserves( $item->itemnumber );
662
is( $status, '', 'MoveReserve filled hold');
653
is( $status, '', 'MoveReserve filled hold');
663
#   hold from A waiting, today, no fut holds: MoveReserve should fill it
654
#   hold from A waiting, today, no fut holds: MoveReserve should fill it
664
AddReserve(
655
AddReserve(
665
    {
656
    {
666
        branchcode     => $branch_1,
657
        branchcode     => $branch_1,
667
        borrowernumber => $borrowernumber,
658
        borrowernumber => $borrowernumber,
668
        biblionumber   => $item_bibnum,
659
        biblionumber   => $bibnum,
669
        priority       => 1,
660
        priority       => 1,
670
        found          => 'W',
661
        found          => 'W',
671
    }
662
    }
672
);
663
);
673
MoveReserve( $itemnumber, $borrowernumber );
664
MoveReserve( $item->itemnumber, $borrowernumber );
674
($status)=CheckReserves( $itemnumber );
665
($status)=CheckReserves( $item->itemnumber );
675
is( $status, '', 'MoveReserve filled waiting hold');
666
is( $status, '', 'MoveReserve filled waiting hold');
676
#   hold from A pos 1, tomorrow, no fut holds: not filled
667
#   hold from A pos 1, tomorrow, no fut holds: not filled
677
$resdate= dt_from_string();
668
$resdate= dt_from_string();
Lines 681-693 AddReserve( Link Here
681
    {
672
    {
682
        branchcode     => $branch_1,
673
        branchcode     => $branch_1,
683
        borrowernumber => $borrowernumber,
674
        borrowernumber => $borrowernumber,
684
        biblionumber   => $item_bibnum,
675
        biblionumber   => $bibnum,
685
        priority       => 1,
676
        priority       => 1,
686
        reservation_date => $resdate,
677
        reservation_date => $resdate,
687
    }
678
    }
688
);
679
);
689
MoveReserve( $itemnumber, $borrowernumber );
680
MoveReserve( $item->itemnumber, $borrowernumber );
690
($status)=CheckReserves( $itemnumber, undef, 1 );
681
($status)=CheckReserves( $item->itemnumber, undef, 1 );
691
is( $status, 'Reserved', 'MoveReserve did not fill future hold');
682
is( $status, 'Reserved', 'MoveReserve did not fill future hold');
692
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
683
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
693
#   hold from A pos 1, tomorrow, fut holds=2: MoveReserve should fill it
684
#   hold from A pos 1, tomorrow, fut holds=2: MoveReserve should fill it
Lines 696-721 AddReserve( Link Here
696
    {
687
    {
697
        branchcode     => $branch_1,
688
        branchcode     => $branch_1,
698
        borrowernumber => $borrowernumber,
689
        borrowernumber => $borrowernumber,
699
        biblionumber   => $item_bibnum,
690
        biblionumber   => $bibnum,
700
        priority       => 1,
691
        priority       => 1,
701
        reservation_date => $resdate,
692
        reservation_date => $resdate,
702
    }
693
    }
703
);
694
);
704
MoveReserve( $itemnumber, $borrowernumber );
695
MoveReserve( $item->itemnumber, $borrowernumber );
705
($status)=CheckReserves( $itemnumber, undef, 2 );
696
($status)=CheckReserves( $item->itemnumber, undef, 2 );
706
is( $status, '', 'MoveReserve filled future hold now');
697
is( $status, '', 'MoveReserve filled future hold now');
707
#   hold from A waiting, tomorrow, fut holds=2: MoveReserve should fill it
698
#   hold from A waiting, tomorrow, fut holds=2: MoveReserve should fill it
708
AddReserve(
699
AddReserve(
709
    {
700
    {
710
        branchcode     => $branch_1,
701
        branchcode     => $branch_1,
711
        borrowernumber => $borrowernumber,
702
        borrowernumber => $borrowernumber,
712
        biblionumber   => $item_bibnum,
703
        biblionumber   => $bibnum,
713
        priority       => 1,
704
        priority       => 1,
714
        reservation_date => $resdate,
705
        reservation_date => $resdate,
715
    }
706
    }
716
);
707
);
717
MoveReserve( $itemnumber, $borrowernumber );
708
MoveReserve( $item->itemnumber, $borrowernumber );
718
($status)=CheckReserves( $itemnumber, undef, 2 );
709
($status)=CheckReserves( $item->itemnumber, undef, 2 );
719
is( $status, '', 'MoveReserve filled future waiting hold now');
710
is( $status, '', 'MoveReserve filled future waiting hold now');
720
#   hold from A pos 1, today+3, fut holds=2: MoveReserve should not fill it
711
#   hold from A pos 1, today+3, fut holds=2: MoveReserve should not fill it
721
$resdate= dt_from_string();
712
$resdate= dt_from_string();
Lines 725-737 AddReserve( Link Here
725
    {
716
    {
726
        branchcode     => $branch_1,
717
        branchcode     => $branch_1,
727
        borrowernumber => $borrowernumber,
718
        borrowernumber => $borrowernumber,
728
        biblionumber   => $item_bibnum,
719
        biblionumber   => $bibnum,
729
        priority       => 1,
720
        priority       => 1,
730
        reservation_date => $resdate,
721
        reservation_date => $resdate,
731
    }
722
    }
732
);
723
);
733
MoveReserve( $itemnumber, $borrowernumber );
724
MoveReserve( $item->itemnumber, $borrowernumber );
734
($status)=CheckReserves( $itemnumber, undef, 3 );
725
($status)=CheckReserves( $item->itemnumber, undef, 3 );
735
is( $status, 'Reserved', 'MoveReserve did not fill future hold of 3 days');
726
is( $status, 'Reserved', 'MoveReserve did not fill future hold of 3 days');
736
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
727
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
737
728
(-)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 218-243 $record->append_fields( Link Here
218
    )
222
    )
219
);
223
);
220
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', );
224
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', );
221
my @sampleitem1 = C4::Items::AddItem(
225
my $item_id1 = $builder->build_sample_item(
222
    {
226
    {
223
        barcode        => 1,
227
        biblionumber => $biblionumber,
228
        library      => $samplebranch->{branchcode},
229
        barcode        => 1,              # FIXME This must not be hardcoded!
224
        itemcallnumber => 'callnumber1',
230
        itemcallnumber => 'callnumber1',
225
        homebranch     => $samplebranch->{branchcode},
231
    }
226
        holdingbranch  => $samplebranch->{branchcode}
232
)->itemnumber;
227
    },
233
my $item_id2 = $builder->build_sample_item(
228
    $biblionumber
229
);
230
my $item_id1    = $sampleitem1[2];
231
my @sampleitem2 = C4::Items::AddItem(
232
    {
234
    {
233
        barcode        => 2,
235
        biblionumber => $biblionumber,
236
        library      => $samplebranch->{branchcode},
237
        barcode        => 2,              # FIXME This must not be hardcoded!
234
        itemcallnumber => 'callnumber2',
238
        itemcallnumber => 'callnumber2',
235
        homebranch     => $samplebranch->{branchcode},
239
    }
236
        holdingbranch  => $samplebranch->{branchcode}
240
)->itemnumber;
237
    },
241
238
    $biblionumber
239
);
240
my $item_id2 = $sampleitem2[2];
241
is( AddItemToCollection( $collection_id1, $item_id1 ),
242
is( AddItemToCollection( $collection_id1, $item_id1 ),
242
    1, "Sampleitem1 has been added to Collection1" );
243
    1, "Sampleitem1 has been added to Collection1" );
243
is( AddItemToCollection( $collection_id1, $item_id2 ),
244
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