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

(-)a/C4/Circulation.pm (-33 / +28 lines)
Lines 1458-1475 sub AddIssue { Link Here
1458
                }
1458
                }
1459
            }
1459
            }
1460
1460
1461
            ModItem(
1461
            $item_object->issues($item_object->issues + 1);
1462
                {
1462
            $item_object->holdingbranch(C4::Context->userenv->{'branch'});
1463
                    issues        => $item_object->issues + 1,
1463
            $item_object->itemlost(0);
1464
                    holdingbranch => C4::Context->userenv->{'branch'},
1464
            $item_object->onloan($datedue->ymd());
1465
                    itemlost      => 0,
1465
            $item_object->datelastborrowed(DateTime->now( time_zone => C4::Context->tz() )->ymd()); # FIXME we should use dt_from_string here
1466
                    onloan        => $datedue->ymd(),
1466
            $item_object->store({log_action => 0});
1467
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1468
                },
1469
                $item_object->biblionumber,
1470
                $item_object->itemnumber,
1471
                { log_action => 0 }
1472
            );
1473
            ModDateLastSeen( $item_object->itemnumber );
1467
            ModDateLastSeen( $item_object->itemnumber );
1474
1468
1475
            # If it costs to borrow this book, charge it to the patron's account.
1469
            # If it costs to borrow this book, charge it to the patron's account.
Lines 1867-1873 sub AddReturn { Link Here
1867
                . Dumper($issue->unblessed) . "\n";
1861
                . Dumper($issue->unblessed) . "\n";
1868
    } else {
1862
    } else {
1869
        $messages->{'NotIssued'} = $barcode;
1863
        $messages->{'NotIssued'} = $barcode;
1870
        ModItem({ onloan => undef }, $item->biblionumber, $item->itemnumber) if defined $item->onloan;
1864
        $item->onloan(undef)->store if defined $item->onloan;
1865
1871
        # even though item is not on loan, it may still be transferred;  therefore, get current branch info
1866
        # even though item is not on loan, it may still be transferred;  therefore, get current branch info
1872
        $doreturn = 0;
1867
        $doreturn = 0;
1873
        # No issue, no borrowernumber.  ONLY if $doreturn, *might* you have a $borrower later.
1868
        # No issue, no borrowernumber.  ONLY if $doreturn, *might* you have a $borrower later.
Lines 1878-1884 sub AddReturn { Link Here
1878
        }
1873
        }
1879
    }
1874
    }
1880
1875
1881
    my $item_unblessed = $item->unblessed;
1882
        # full item data, but no borrowernumber or checkout info (no issue)
1876
        # full item data, but no borrowernumber or checkout info (no issue)
1883
    my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch";
1877
    my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch";
1884
        # get the proper branch to which to return the item
1878
        # get the proper branch to which to return the item
Lines 1896-1902 sub AddReturn { Link Here
1896
            if ($update_loc_rules->{_ALL_} eq '_BLANK_') { $update_loc_rules->{_ALL_} = ''; }
1890
            if ($update_loc_rules->{_ALL_} eq '_BLANK_') { $update_loc_rules->{_ALL_} = ''; }
1897
            if ( $item->location ne $update_loc_rules->{_ALL_}) {
1891
            if ( $item->location ne $update_loc_rules->{_ALL_}) {
1898
                $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{_ALL_} };
1892
                $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{_ALL_} };
1899
                ModItem( { location => $update_loc_rules->{_ALL_} }, undef, $itemnumber );
1893
                $item->location($update_loc_rules->{_ALL_})->store;
1900
            }
1894
            }
1901
        }
1895
        }
1902
        else {
1896
        else {
Lines 1905-1911 sub AddReturn { Link Here
1905
                if ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
1899
                if ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
1906
                if ( ($item->location eq $key && $item->location ne $update_loc_rules->{$key}) || ($key eq '_BLANK_' && $item->location eq '' && $update_loc_rules->{$key} ne '') ) {
1900
                if ( ($item->location eq $key && $item->location ne $update_loc_rules->{$key}) || ($key eq '_BLANK_' && $item->location eq '' && $update_loc_rules->{$key} ne '') ) {
1907
                    $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{$key} };
1901
                    $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{$key} };
1908
                    ModItem( { location => $update_loc_rules->{$key} }, undef, $itemnumber );
1902
                    $item->location($update_loc_rules->{$key})->store;
1909
                    last;
1903
                    last;
1910
                }
1904
                }
1911
            }
1905
            }
Lines 1924-1930 sub AddReturn { Link Here
1924
            foreach my $key ( keys %$rules ) {
1918
            foreach my $key ( keys %$rules ) {
1925
                if ( $item->notforloan eq $key ) {
1919
                if ( $item->notforloan eq $key ) {
1926
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$key} };
1920
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$key} };
1927
                    ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, { log_action => 0 } );
1921
                    $item->notforloan($rules->{$key})->store({ log_action => 0 });
1928
                    last;
1922
                    last;
1929
                }
1923
                }
1930
            }
1924
            }
Lines 1932-1938 sub AddReturn { Link Here
1932
    }
1926
    }
1933
1927
1934
    # check if the return is allowed at this branch
1928
    # check if the return is allowed at this branch
1935
    my ($returnallowed, $message) = CanBookBeReturned($item_unblessed, $branch);
1929
    my ($returnallowed, $message) = CanBookBeReturned($item->unblessed, $branch);
1936
    unless ($returnallowed){
1930
    unless ($returnallowed){
1937
        $messages->{'Wrongbranch'} = {
1931
        $messages->{'Wrongbranch'} = {
1938
            Wrongbranch => $branch,
1932
            Wrongbranch => $branch,
Lines 1962-1968 sub AddReturn { Link Here
1962
            };
1956
            };
1963
            unless ( $@ ) {
1957
            unless ( $@ ) {
1964
                if ( C4::Context->preference('CalculateFinesOnReturn') && !$item->itemlost ) {
1958
                if ( C4::Context->preference('CalculateFinesOnReturn') && !$item->itemlost ) {
1965
                    _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed, return_date => $return_date } );
1959
                    _CalculateAndUpdateFine( { issue => $issue, item => $item->unblessed, borrower => $patron_unblessed, return_date => $return_date } );
1966
                }
1960
                }
1967
            } else {
1961
            } else {
1968
                carp "The checkin for the following issue failed, Please go to the about page, section 'data corrupted' to know how to fix this problem ($@)" . Dumper( $issue->unblessed );
1962
                carp "The checkin for the following issue failed, Please go to the about page, section 'data corrupted' to know how to fix this problem ($@)" . Dumper( $issue->unblessed );
Lines 1975-1981 sub AddReturn { Link Here
1975
1969
1976
        }
1970
        }
1977
1971
1978
        ModItem( { onloan => undef }, $item->biblionumber, $item->itemnumber, { log_action => 0 } );
1972
        $item->onloan(undef)->store({ log_action => 0 });
1979
    }
1973
    }
1980
1974
1981
    # the holdingbranch is updated if the document is returned to another location.
1975
    # the holdingbranch is updated if the document is returned to another location.
Lines 1983-1989 sub AddReturn { Link Here
1983
    my $item_holding_branch = $item->holdingbranch;
1977
    my $item_holding_branch = $item->holdingbranch;
1984
    if ($item->holdingbranch ne $branch) {
1978
    if ($item->holdingbranch ne $branch) {
1985
        UpdateHoldingbranch($branch, $item->itemnumber);
1979
        UpdateHoldingbranch($branch, $item->itemnumber);
1986
        $item_unblessed->{'holdingbranch'} = $branch; # update item data holdingbranch too # FIXME I guess this is for the _debar_user_on_return call later
1980
        $item->holdingbranch($branch); # update item data holdingbranch too # FIXME I guess this is for the _debar_user_on_return call later
1987
    }
1981
    }
1988
1982
1989
    my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
1983
    my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
Lines 2037-2043 sub AddReturn { Link Here
2037
2031
2038
        if ( $issue and $issue->is_overdue ) {
2032
        if ( $issue and $issue->is_overdue ) {
2039
        # fix fine days
2033
        # fix fine days
2040
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item_unblessed, dt_from_string($issue->date_due), $return_date );
2034
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item->unblessed, dt_from_string($issue->date_due), $return_date );
2041
            if ($reminder){
2035
            if ($reminder){
2042
                $messages->{'PrevDebarred'} = $debardate;
2036
                $messages->{'PrevDebarred'} = $debardate;
2043
            } else {
2037
            } else {
Lines 2090-2096 sub AddReturn { Link Here
2090
        if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) {
2084
        if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) {
2091
            SendCirculationAlert({
2085
            SendCirculationAlert({
2092
                type     => 'CHECKIN',
2086
                type     => 'CHECKIN',
2093
                item     => $item_unblessed,
2087
                item     => $item->unblessed,
2094
                borrower => $patron->unblessed,
2088
                borrower => $patron->unblessed,
2095
                branch   => $branch,
2089
                branch   => $branch,
2096
            });
2090
            });
Lines 2118-2124 sub AddReturn { Link Here
2118
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2112
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2119
           )) {
2113
           )) {
2120
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->itemnumber,$branch, $returnbranch;
2114
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->itemnumber,$branch, $returnbranch;
2121
            $debug and warn "item: " . Dumper($item_unblessed);
2115
            $debug and warn "item: " . Dumper($item->unblessed);
2122
            ModItemTransfer($item->itemnumber, $branch, $returnbranch);
2116
            ModItemTransfer($item->itemnumber, $branch, $returnbranch);
2123
            $messages->{'WasTransfered'} = 1;
2117
            $messages->{'WasTransfered'} = 1;
2124
        } else {
2118
        } else {
Lines 2204-2210 sub MarkIssueReturned { Link Here
2204
        # And finally delete the issue
2198
        # And finally delete the issue
2205
        $issue->delete;
2199
        $issue->delete;
2206
2200
2207
        ModItem( { 'onloan' => undef }, undef, $itemnumber, { log_action => 0 } );
2201
        $issue->item->onloan(undef)->store({ log_action => 0 });
2208
2202
2209
        if ( C4::Context->preference('StoreLastBorrower') ) {
2203
        if ( C4::Context->preference('StoreLastBorrower') ) {
2210
            my $item = Koha::Items->find( $itemnumber );
2204
            my $item = Koha::Items->find( $itemnumber );
Lines 2485-2490 sub _FixAccountForLostAndReturned { Link Here
2485
    $accountline->discard_changes->status('RETURNED');
2479
    $accountline->discard_changes->status('RETURNED');
2486
    $accountline->store;
2480
    $accountline->store;
2487
2481
2482
    $accountline->item->paidfor('')->store({ log_action => 0 });
2483
2488
    if ( defined $account and C4::Context->preference('AccountAutoReconcile') ) {
2484
    if ( defined $account and C4::Context->preference('AccountAutoReconcile') ) {
2489
        $account->reconcile_balance;
2485
        $account->reconcile_balance;
2490
    }
2486
    }
Lines 2927-2933 sub AddRenewal { Link Here
2927
2923
2928
        # Update the renewal count on the item, and tell zebra to reindex
2924
        # Update the renewal count on the item, and tell zebra to reindex
2929
        $renews = $item_object->renewals + 1;
2925
        $renews = $item_object->renewals + 1;
2930
        ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item_object->biblionumber, $itemnumber, { log_action => 0 } );
2926
        $item_object->renewals($renews);
2927
        $item_object->onloan($datedue);
2928
        $item_object->store({ log_action => 0 });
2931
2929
2932
        # Charge a new rental fee, if applicable
2930
        # Charge a new rental fee, if applicable
2933
        my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2931
        my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
Lines 3741-3747 sub LostItem{ Link Here
3741
3739
3742
    #When item is marked lost automatically cancel its outstanding transfers and set items holdingbranch to the transfer source branch (frombranch)
3740
    #When item is marked lost automatically cancel its outstanding transfers and set items holdingbranch to the transfer source branch (frombranch)
3743
    if (my ( $datesent,$frombranch,$tobranch ) = GetTransfers($itemnumber)) {
3741
    if (my ( $datesent,$frombranch,$tobranch ) = GetTransfers($itemnumber)) {
3744
        ModItem({holdingbranch => $frombranch}, undef, $itemnumber);
3742
        Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store;
3745
    }
3743
    }
3746
    my $transferdeleted = DeleteTransfer($itemnumber);
3744
    my $transferdeleted = DeleteTransfer($itemnumber);
3747
}
3745
}
Lines 3809-3820 sub ProcessOfflineReturn { Link Here
3809
                $itemnumber,
3807
                $itemnumber,
3810
                $operation->{timestamp},
3808
                $operation->{timestamp},
3811
            );
3809
            );
3812
            ModItem(
3810
            $item->renewals(0);
3813
                { renewals => 0, onloan => undef },
3811
            $item->onloan(undef);
3814
                $issue->{'biblionumber'},
3812
            $item->store({ log_action => 0 });
3815
                $itemnumber,
3816
                { log_action => 0 }
3817
            );
3818
            return "Success.";
3813
            return "Success.";
3819
        } else {
3814
        } else {
3820
            return "Item not issued.";
3815
            return "Item not issued.";
(-)a/C4/CourseReserves.pm (-11 / +8 lines)
Lines 20-26 use Modern::Perl; Link Here
20
use List::MoreUtils qw(any);
20
use List::MoreUtils qw(any);
21
21
22
use C4::Context;
22
use C4::Context;
23
use C4::Items qw(ModItem);
24
use C4::Circulation qw(GetOpenIssue);
23
use C4::Circulation qw(GetOpenIssue);
25
24
26
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG @FIELDS);
25
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG @FIELDS);
Lines 538-544 sub _UpdateCourseItem { Link Here
538
          : ()
537
          : ()
539
      } @FIELDS;
538
      } @FIELDS;
540
539
541
    ModItem( \%mod_params, undef, $course_item->{'itemnumber'} );
540
    Koha::Items->find( $course_item->{itemnumber} )
541
               ->set( \%mod_params )
542
               ->store;
542
}
543
}
543
544
544
=head2 _ModStoredFields
545
=head2 _ModStoredFields
Lines 587-600 sub _RevertFields { Link Here
587
    return unless ($ci_id);
588
    return unless ($ci_id);
588
589
589
    my $course_item = GetCourseItem( ci_id => $params{'ci_id'} );
590
    my $course_item = GetCourseItem( ci_id => $params{'ci_id'} );
590
591
    my $course_item_object;
591
    my $mod_item_params;
592
    foreach my $field ( @FIELDS ) {
592
    foreach my $field ( @FIELDS ) {
593
        next unless defined $course_item->{$field};
593
        next unless defined $course_item->{$field};
594
        $mod_item_params->{$field} = $course_item->{$field};
594
        $course_item->$field($course_item->{$field});
595
    }
595
    }
596
596
    $course_item_object->store;
597
    ModItem( $mod_item_params, undef, $course_item->{'itemnumber'} ) if $mod_item_params && %$mod_item_params;
598
}
597
}
599
598
600
=head2 _SwapAllFields
599
=head2 _SwapAllFields
Lines 610-625 sub _SwapAllFields { Link Here
610
    my $course_item = GetCourseItem( ci_id => $ci_id );
609
    my $course_item = GetCourseItem( ci_id => $ci_id );
611
    my $item = Koha::Items->find($course_item->{'itemnumber'});
610
    my $item = Koha::Items->find($course_item->{'itemnumber'});
612
611
613
    my %course_item_fields;
614
    my %item_fields;
612
    my %item_fields;
615
    foreach (@FIELDS) {
613
    foreach (@FIELDS) {
616
        if ( defined( $course_item->{$_} ) ) {
614
        if ( defined( $course_item->{$_} ) ) {
617
            $course_item_fields{$_} = $course_item->{$_};
618
            $item_fields{$_}        = $item->$_ || q{};
615
            $item_fields{$_}        = $item->$_ || q{};
616
            $item->$_($course_item->{$_});
619
        }
617
        }
620
    }
618
    }
621
619
    $item->store;
622
    ModItem( \%course_item_fields, undef, $course_item->{'itemnumber'} ) if %course_item_fields;
623
    _ModStoredFields( %item_fields, ci_id => $ci_id );
620
    _ModStoredFields( %item_fields, ci_id => $ci_id );
624
}
621
}
625
622
(-)a/C4/Items.pm (-11 / +16 lines)
Lines 135-141 sub CartToShelf { Link Here
135
135
136
    my $item = Koha::Items->find($itemnumber);
136
    my $item = Koha::Items->find($itemnumber);
137
    if ( $item->location eq 'CART' ) {
137
    if ( $item->location eq 'CART' ) {
138
        ModItem({ location => $item->permanent_location}, undef, $itemnumber);
138
        $item->location($item->permanent_location)->store;
139
    }
139
    }
140
}
140
}
141
141
Lines 369-376 sub ModItemFromMarc { Link Here
369
    }
369
    }
370
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
370
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
371
371
372
    ModItem( $item, $biblionumber, $itemnumber, { unlinked_item_subfields => $unlinked_item_subfields } );
372
    my $item_object = Koha::Items->find($itemnumber);
373
    return $item;
373
    $item_object->more_subfields_xml(_get_unlinked_subfields_xml($unlinked_item_subfields))->store;
374
375
    return $item_object->get_from_storage->unblessed;
374
}
376
}
375
377
376
=head2 ModItem
378
=head2 ModItem
Lines 500-506 sub ModItemTransfer { Link Here
500
        VALUES (?, ?, NOW(), ?)");
502
        VALUES (?, ?, NOW(), ?)");
501
    $sth->execute($itemnumber, $frombranch, $tobranch);
503
    $sth->execute($itemnumber, $frombranch, $tobranch);
502
504
503
    ModItem({ holdingbranch => $frombranch }, undef, $itemnumber, { log_action => 0 });
505
    # FIXME we are fetching the item twice in the 2 next statements!
506
    Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store({ log_action => 0 });
504
    ModDateLastSeen($itemnumber);
507
    ModDateLastSeen($itemnumber);
505
    return;
508
    return;
506
}
509
}
Lines 520-530 sub ModDateLastSeen { Link Here
520
523
521
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
524
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
522
525
523
    my $params;
526
    my $item = Koha::Items->find($itemnumber);
524
    $params->{datelastseen} = $today;
527
    $item->datelastseen($today);
525
    $params->{itemlost} = 0 unless $leave_item_lost;
528
    $item->itemlost(0) unless $leave_item_lost;
526
529
    $item->store({ log_action => 0 });
527
    ModItem( $params, undef, $itemnumber, { log_action => 0 } );
528
}
530
}
529
531
530
=head2 DelItem
532
=head2 DelItem
Lines 2502-2514 sub ToggleNewStatus { Link Here
2502
        while ( my $values = $sth->fetchrow_hashref ) {
2504
        while ( my $values = $sth->fetchrow_hashref ) {
2503
            my $biblionumber = $values->{biblionumber};
2505
            my $biblionumber = $values->{biblionumber};
2504
            my $itemnumber = $values->{itemnumber};
2506
            my $itemnumber = $values->{itemnumber};
2507
            my $item = Koha::Items->find($itemnumber);
2505
            for my $substitution ( @$substitutions ) {
2508
            for my $substitution ( @$substitutions ) {
2509
                my $field = $substitution->{item_field};
2510
                my $value = $substitution->{value};
2506
                next unless $substitution->{field};
2511
                next unless $substitution->{field};
2507
                next if ( defined $values->{ $substitution->{item_field} } and $values->{ $substitution->{item_field} } eq $substitution->{value} );
2512
                next if ( defined $values->{ $substitution->{item_field} } and $values->{ $substitution->{item_field} } eq $substitution->{value} );
2508
                C4::Items::ModItem( { $substitution->{item_field} => $substitution->{value} }, $biblionumber, $itemnumber )
2513
                $item->$field($value);
2509
                    unless $report_only;
2510
                push @{ $report->{$itemnumber} }, $substitution;
2514
                push @{ $report->{$itemnumber} }, $substitution;
2511
            }
2515
            }
2516
            $item->store unless $report_only;
2512
        }
2517
        }
2513
    }
2518
    }
2514
2519
(-)a/Koha/Item.pm (-6 / +55 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use Carp;
22
use Carp;
23
use List::MoreUtils qw(any);
23
use List::MoreUtils qw(any);
24
use Data::Dumper;
24
25
25
use Koha::Database;
26
use Koha::Database;
26
use Koha::DateUtils qw( dt_from_string );
27
use Koha::DateUtils qw( dt_from_string );
Lines 56-62 Koha::Item - Koha Item object class Link Here
56
=cut
57
=cut
57
58
58
sub store {
59
sub store {
59
    my ($self) = @_;
60
    my ($self, $params) = @_;
61
62
    my $log_action = $params->{log_action} // 1;
60
63
61
    # We do not want to oblige callers to pass this value
64
    # We do not want to oblige callers to pass this value
62
    # Dev conveniences vs performance?
65
    # Dev conveniences vs performance?
Lines 69-74 sub store { Link Here
69
        $self->itype($self->biblio->biblioitem->itemtype);
72
        $self->itype($self->biblio->biblioitem->itemtype);
70
    }
73
    }
71
74
75
    if ( $self->itemcallnumber ) { # This could be improved, we should recalculate it only if changed
76
        my $cn_sort = GetClassSort($self->cn_source, $self->itemcallnumber, "");
77
        $self->cn_sort($cn_sort);
78
    }
79
72
    my $today = dt_from_string;
80
    my $today = dt_from_string;
73
    unless ( $self->in_storage ) { #AddItem
81
    unless ( $self->in_storage ) { #AddItem
74
        unless ( $self->permanent_location ) {
82
        unless ( $self->permanent_location ) {
Lines 85-99 sub store { Link Here
85
            $self->dateaccessioned($today);
93
            $self->dateaccessioned($today);
86
        }
94
        }
87
95
88
        if ( $self->itemcallnumber ) { # This could be improved, we should recalculate it only if changed
96
        C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" );
89
            my $cn_sort = GetClassSort($self->cn_source, $self->itemcallnumber, "");
97
90
            $self->cn_sort($cn_sort);
98
        logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" )
99
          if $log_action && C4::Context->preference("CataloguingLog");
100
101
        $self->_after_item_action_hooks({ action => 'create' });
102
103
    } else { # ModItem
104
105
        { # Update *_on  fields if needed
106
          # Why not for AddItem as well?
107
            my @fields = qw( itemlost withdrawn damaged );
108
109
            # Only retrieve the item if we need to set an "on" date field
110
            if ( $self->itemlost || $self->withdrawn || $self->damaged ) {
111
                my $pre_mod_item = $self->get_from_storage;
112
                for my $field (@fields) {
113
                    if (    $self->$field
114
                        and not $pre_mod_item->$field )
115
                    {
116
                        my $field_on = "${field}_on";
117
                        $self->$field_on(
118
                          DateTime::Format::MySQL->format_datetime( dt_from_string() )
119
                        );
120
                    }
121
                }
122
            }
123
124
            # If the field is defined but empty, we are removing and,
125
            # and thus need to clear out the 'on' field as well
126
            for my $field (@fields) {
127
                if ( defined( $self->$field ) && !$self->$field ) {
128
                    my $field_on = "${field}_on";
129
                    $self->$field_on(undef);
130
                }
131
            }
132
        }
133
134
        if ( defined $self->location and $self->location ne 'CART' and $self->location ne 'PROC' and not $self->permanent_location ) {
135
            $self->permanent_location($self->location);
91
        }
136
        }
92
137
138
        $self->timestamp(undef) if $self->timestamp; # Maybe move this to Koha::Object->store?
139
93
        C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" );
140
        C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" );
94
141
95
        logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" )
142
        $self->_after_item_action_hooks({ action => 'modify' });
96
          if C4::Context->preference("CataloguingLog");
143
144
        logaction( "CATALOGUING", "MODIFY", $self->itemnumber, "item " . Dumper($self->unblessed) )
145
          if $log_action && C4::Context->preference("CataloguingLog");
97
146
98
    }
147
    }
99
148
(-)a/acqui/finishreceive.pl (-12 / +7 lines)
Lines 171-188 if ($quantityrec > $origquantityrec ) { Link Here
171
my $new_order_object = Koha::Acquisition::Orders->find( $new_ordernumber ); # FIXME we should not need to refetch it
171
my $new_order_object = Koha::Acquisition::Orders->find( $new_ordernumber ); # FIXME we should not need to refetch it
172
my $items = $new_order_object->items;
172
my $items = $new_order_object->items;
173
while ( my $item = $items->next )  {
173
while ( my $item = $items->next )  {
174
    ModItem(
174
    $item->booksellerid($booksellerid); # TODO This should be done using ->set, but bug 21761 is not resolved
175
        {
175
    $item->dateaccessioned($dateaccessioned);
176
            booksellerid         => $booksellerid,
176
    $item->datelastseen($datereceived);
177
            dateaccessioned      => $datereceived,
177
    $item->price($unitprice);
178
            datelastseen         => $datereceived,
178
    $item->replacementprice($replacementprice);
179
            price                => $unitprice,
179
    $item->replacementpricedate($datereceived);
180
            replacementprice     => $replacementprice,
180
    $item->store;
181
            replacementpricedate => $datereceived,
182
        },
183
        $biblionumber,
184
        $item->itemnumber,
185
    );
186
}
181
}
187
182
188
print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid&sticky_filters=1");
183
print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid&sticky_filters=1");
(-)a/catalogue/updateitem.pl (-8 / +8 lines)
Lines 45-51 my $confirm=$cgi->param('confirm'); Link Here
45
my $dbh = C4::Context->dbh;
45
my $dbh = C4::Context->dbh;
46
46
47
# get the rest of this item's information
47
# get the rest of this item's information
48
my $item_data_hashref = Koha::Items->find($itemnumber)->unblessed;
48
my $item = Koha::Items->find($itemnumber);
49
my $item_data_hashref = $item->unblessed;
49
50
50
# make sure item statuses are set to 0 if empty or NULL
51
# make sure item statuses are set to 0 if empty or NULL
51
for ($damaged,$itemlost,$withdrawn) {
52
for ($damaged,$itemlost,$withdrawn) {
Lines 55-85 for ($damaged,$itemlost,$withdrawn) { Link Here
55
}
56
}
56
57
57
# modify MARC item if input differs from items table.
58
# modify MARC item if input differs from items table.
58
my $item_changes = {};
59
if ( $op eq "set_non_public_note" ) {
59
if ( $op eq "set_non_public_note" ) {
60
    checkauth($cgi, 0, {editcatalogue => 'edit_items'}, 'intranet');
60
    checkauth($cgi, 0, {editcatalogue => 'edit_items'}, 'intranet');
61
    if ((not defined  $item_data_hashref->{'itemnotes_nonpublic'}) or $itemnotes_nonpublic ne $item_data_hashref->{'itemnotes_nonpublic'}) {
61
    if ((not defined  $item_data_hashref->{'itemnotes_nonpublic'}) or $itemnotes_nonpublic ne $item_data_hashref->{'itemnotes_nonpublic'}) {
62
        $item_changes->{'itemnotes_nonpublic'} = $itemnotes_nonpublic;
62
        $item->itemnotes_nonpublic($itemnotes_nonpublic);
63
    }
63
    }
64
}
64
}
65
elsif ( $op eq "set_public_note" ) { # i.e., itemnotes parameter passed from form
65
elsif ( $op eq "set_public_note" ) { # i.e., itemnotes parameter passed from form
66
    checkauth($cgi, 0, {editcatalogue => 'edit_items'}, 'intranet');
66
    checkauth($cgi, 0, {editcatalogue => 'edit_items'}, 'intranet');
67
    if ((not defined  $item_data_hashref->{'itemnotes'}) or $itemnotes ne $item_data_hashref->{'itemnotes'}) {
67
    if ((not defined  $item_data_hashref->{'itemnotes'}) or $itemnotes ne $item_data_hashref->{'itemnotes'}) {
68
        $item_changes->{'itemnotes'} = $itemnotes;
68
        $item->itemnotes($itemnotes);
69
    }
69
    }
70
} elsif ( $op eq "set_lost" && $itemlost ne $item_data_hashref->{'itemlost'}) {
70
} elsif ( $op eq "set_lost" && $itemlost ne $item_data_hashref->{'itemlost'}) {
71
    $item_changes->{'itemlost'} = $itemlost;
71
    $item->itemlost($itemlost);
72
} elsif ( $op eq "set_withdrawn" && $withdrawn ne $item_data_hashref->{'withdrawn'}) {
72
} elsif ( $op eq "set_withdrawn" && $withdrawn ne $item_data_hashref->{'withdrawn'}) {
73
    $item_changes->{'withdrawn'} = $withdrawn;
73
    $item->withdrawn($withdrawn);
74
} elsif ( $op eq "set_damaged" && $damaged ne $item_data_hashref->{'damaged'}) {
74
} elsif ( $op eq "set_damaged" && $damaged ne $item_data_hashref->{'damaged'}) {
75
    $item_changes->{'damaged'} = $damaged;
75
    $item->damaged($damaged);
76
} else {
76
} else {
77
    #nothings changed, so do nothing.
77
    #nothings changed, so do nothing.
78
    print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber#item$itemnumber");
78
    print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber#item$itemnumber");
79
	exit;
79
	exit;
80
}
80
}
81
81
82
ModItem($item_changes, $biblionumber, $itemnumber);
82
$item->store;
83
83
84
LostItem($itemnumber, 'moredetail') if $op eq "set_lost";
84
LostItem($itemnumber, 'moredetail') if $op eq "set_lost";
85
85
(-)a/cataloguing/additem.pl (-10 / +5 lines)
Lines 76-94 sub set_item_default_location { Link Here
76
    my $itemnumber = shift;
76
    my $itemnumber = shift;
77
    my $item       = Koha::Items->find($itemnumber);
77
    my $item       = Koha::Items->find($itemnumber);
78
    if ( C4::Context->preference('NewItemsDefaultLocation') ) {
78
    if ( C4::Context->preference('NewItemsDefaultLocation') ) {
79
        ModItem(
79
        $item->permanent_location($item->location);
80
            {
80
        $item->location(C4::Context->preference('NewItemsDefaultLocation'));
81
                permanent_location => $item->location,
82
                location => C4::Context->preference('NewItemsDefaultLocation')
83
            },
84
            undef,
85
            $itemnumber
86
        );
87
    }
81
    }
88
    else {
82
    else {
89
        ModItem( { permanent_location => $item->location }, undef, $itemnumber )
83
        # It seems that we are dealing with that in too many places
90
          unless defined $item->permanent_location;
84
        $item->permanent_location($item->location) unless defined $item->permanent_location;
91
    }
85
    }
86
    $item->store;
92
}
87
}
93
88
94
# NOTE: This code is subject to change in the future with the implemenation of ajax based autobarcode code
89
# NOTE: This code is subject to change in the future with the implemenation of ajax based autobarcode code
(-)a/circ/pendingreserves.pl (-2 / +5 lines)
Lines 26-32 use C4::Output; Link Here
26
use CGI qw ( -utf8 );
26
use CGI qw ( -utf8 );
27
use C4::Auth;
27
use C4::Auth;
28
use C4::Debug;
28
use C4::Debug;
29
use C4::Items qw( ModItem ModItemTransfer );
29
use C4::Items qw( ModItemTransfer );
30
use C4::Reserves qw( ModReserveCancelAll );
30
use C4::Reserves qw( ModReserveCancelAll );
31
use Koha::Biblios;
31
use Koha::Biblios;
32
use Koha::DateUtils;
32
use Koha::DateUtils;
Lines 114-120 if ( $op eq 'cancel_reserve' and $reserve_id ) { Link Here
114
            }
114
            }
115
            else {
115
            else {
116
                eval {
116
                eval {
117
                    C4::Items::ModItem( $assignments, undef, $item->itemnumber );
117
                    while ( my ( $f, $v ) = each( %$assignments ) ) {
118
                        $item->$f($v);
119
                    }
120
                    $item->store;
118
                };
121
                };
119
                warn "Unable to modify item itemnumber=" . $item->itemnumber . ": $@" if $@;
122
                warn "Unable to modify item itemnumber=" . $item->itemnumber . ": $@" if $@;
120
            }
123
            }
(-)a/misc/cronjobs/longoverdue.pl (-1 / +2 lines)
Lines 383-389 foreach my $startrange (sort keys %$lost) { Link Here
383
            }
383
            }
384
            printf ("Due %s: item %5s from borrower %5s to lost: %s\n", $row->{date_due}, $row->{itemnumber}, $row->{borrowernumber}, $lostvalue) if($verbose);
384
            printf ("Due %s: item %5s from borrower %5s to lost: %s\n", $row->{date_due}, $row->{itemnumber}, $row->{borrowernumber}, $lostvalue) if($verbose);
385
            if($confirm) {
385
            if($confirm) {
386
                ModItem({ itemlost => $lostvalue }, $row->{'biblionumber'}, $row->{'itemnumber'});
386
                Koha::Items->find( $row->{itemnumber} )->itemlost($lostvalue)
387
                  ->store;
387
                if ( $charge && $charge eq $lostvalue ) {
388
                if ( $charge && $charge eq $lostvalue ) {
388
                    LostItem( $row->{'itemnumber'}, 'cronjob', $mark_returned );
389
                    LostItem( $row->{'itemnumber'}, 'cronjob', $mark_returned );
389
                } elsif ( $mark_returned ) {
390
                } elsif ( $mark_returned ) {
(-)a/misc/maintenance/touch_all_items.pl (-1 / +3 lines)
Lines 32-37 use Getopt::Long; Link Here
32
use Koha::Script;
32
use Koha::Script;
33
use C4::Context;
33
use C4::Context;
34
use C4::Items;
34
use C4::Items;
35
use Koha::Items;
35
use Pod::Usage;
36
use Pod::Usage;
36
37
37
38
Lines 75-87 if (defined $outfile) { Link Here
75
   open(OUT, ">&STDOUT") || die ("Couldn't duplicate STDOUT: $!");
76
   open(OUT, ">&STDOUT") || die ("Couldn't duplicate STDOUT: $!");
76
}
77
}
77
78
79
# FIXME Would be better to call Koha::Items->search here
78
my $sth_fetch = $dbh->prepare("SELECT biblionumber, itemnumber, itemcallnumber FROM items $whereclause");
80
my $sth_fetch = $dbh->prepare("SELECT biblionumber, itemnumber, itemcallnumber FROM items $whereclause");
79
$sth_fetch->execute();
81
$sth_fetch->execute();
80
82
81
# fetch info from the search
83
# fetch info from the search
82
while (my ($biblionumber, $itemnumber, $itemcallnumber) = $sth_fetch->fetchrow_array){
84
while (my ($biblionumber, $itemnumber, $itemcallnumber) = $sth_fetch->fetchrow_array){
83
   
85
   
84
  eval { ModItem({itemcallnumber => $itemcallnumber}, $biblionumber, $itemnumber); };
86
  eval { Koha::Items->find($itemnumber)->itemcallnumber($itemcallnumber)->store; };
85
  my $modok = $@ ? 0 : 1;
87
  my $modok = $@ ? 0 : 1;
86
88
87
  if ($modok) {
89
  if ($modok) {
(-)a/misc/migration_tools/fix_onloan.pl (-17 / +7 lines)
Lines 1-13 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use strict;
3
use Modern::Perl;
4
#use warnings; FIXME - Bug 2505
5
6
use Koha::Script;
4
use Koha::Script;
7
use C4::Context;
5
use Koha::Items;
8
use C4::Items;
9
use C4::Biblio;
10
11
#
6
#
12
# the items.onloan field did not exist in koha 2.2
7
# the items.onloan field did not exist in koha 2.2
13
# in koha 3.0, it's used to define item availability
8
# in koha 3.0, it's used to define item availability
Lines 15-30 use C4::Biblio; Link Here
15
# and put it in the MARC::Record of the item
10
# and put it in the MARC::Record of the item
16
#
11
#
17
12
18
my $dbh=C4::Context->dbh;
13
my $items = Koha::Items->({ onloan => { '!=' => undef } });
19
14
20
# if (C4::Context->preference("marcflavour") ne "UNIMARC") {
21
#     print "this script is for UNIMARC only\n";
22
#     exit;
23
# }
24
my $rqbiblios=$dbh->prepare("SELECT biblionumber,itemnumber,onloan FROM items WHERE items.onloan IS NOT NULL");
25
$rqbiblios->execute;
26
$|=1;
15
$|=1;
27
while (my ($biblionumber,$itemnumber,$onloan)= $rqbiblios->fetchrow){
16
while ( my $item = $items->next ) {
28
    ModItem({onloan => "$onloan"}, $biblionumber, $itemnumber);
17
    $item->store;
29
    print "Onloan : $onloan for $biblionumber / $itemnumber\n";
18
    print sprintf "Onloan : %s for %s / %s\n", $item->onloan, $item->biblionumber, $item->itemnumber;
19
}
30
}
20
}
(-)a/offline_circ/process_koc.pl (-1 / +1 lines)
Lines 339-345 sub kocReturnItem { Link Here
339
            $patron->privacy
339
            $patron->privacy
340
        );
340
        );
341
341
342
        ModItem({ onloan => undef }, $biblio->biblionumber, $item->itemnumber);
342
        $item->onloadn(undef)->store;
343
        ModDateLastSeen( $item->itemnumber );
343
        ModDateLastSeen( $item->itemnumber );
344
344
345
        push @output,
345
        push @output,
(-)a/serials/serials-edit.pl (-1 / +6 lines)
Lines 268-274 if ( $op and $op eq 'serialchangestatus' ) { Link Here
268
                    my $subscriptioninfos = GetSubscription($subscriptionids[$i]);
268
                    my $subscriptioninfos = GetSubscription($subscriptionids[$i]);
269
269
270
                    # Changing the status to "available" and the itemtype according to the previousitemtype db field
270
                    # Changing the status to "available" and the itemtype according to the previousitemtype db field
271
                    ModItem({notforloan => 0, itype => $subscriptioninfos->{'previousitemtype'} }, undef, $itemnumber);
271
                    $serialitem->set(
272
                        {
273
                            notforloan => 0,
274
                            itype => $subscriptioninfos->{'previousitemtype'}
275
                        }
276
                    )->store;
272
                }
277
                }
273
            }
278
            }
274
        }
279
        }
(-)a/svc/checkin (-1 lines)
Lines 24-30 use CGI; Link Here
24
use JSON qw(to_json);
24
use JSON qw(to_json);
25
25
26
use C4::Circulation;
26
use C4::Circulation;
27
use C4::Items qw(ModItem);
28
use C4::Context;
27
use C4::Context;
29
use C4::Auth qw(check_cookie_auth);
28
use C4::Auth qw(check_cookie_auth);
30
use Koha::Checkouts;
29
use Koha::Checkouts;
(-)a/t/db_dependent/Circulation.t (-13 / +13 lines)
Lines 466-475 subtest "CanBookBeRenewed tests" => sub { Link Here
466
    is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
466
    is( $renewokay, 1, 'Can renew item 2, item-level hold is on item 1');
467
467
468
    # Items can't fill hold for reasons
468
    # Items can't fill hold for reasons
469
    ModItem({ notforloan => 1 }, $biblio->biblionumber, $item_1->itemnumber);
469
    $item_1->notforloan(1)->store;
470
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1);
470
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1);
471
    is( $renewokay, 1, 'Can renew, item is marked not for loan, hold does not block');
471
    is( $renewokay, 1, 'Can renew, item is marked not for loan, hold does not block');
472
    ModItem({ notforloan => 0, itype => $itemtype }, $biblio->biblionumber, $item_1->itemnumber);
472
    $item_1->set({notforloan => 0, itype => $itemtype })->store;
473
473
474
    # FIXME: Add more for itemtype not for loan etc.
474
    # FIXME: Add more for itemtype not for loan etc.
475
475
Lines 1235-1241 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1235
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' );
1235
    is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable and onshelfhold are enabled' );
1236
1236
1237
    # Setting item not checked out to be not for loan but holdable
1237
    # Setting item not checked out to be not for loan but holdable
1238
    ModItem({ notforloan => -1 }, $biblio->biblionumber, $item_2->itemnumber);
1238
    $item_2->notforloan(-1)->store;
1239
1239
1240
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber );
1240
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber );
1241
    is( $renewokay, 0, 'Bug 14337 - Verify the borrower can not renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled but the only available item is notforloan' );
1241
    is( $renewokay, 0, 'Bug 14337 - Verify the borrower can not renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled but the only available item is notforloan' );
Lines 2139-2145 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2139
        AddIssue( $patron->unblessed, $item->barcode );
2139
        AddIssue( $patron->unblessed, $item->barcode );
2140
2140
2141
        # Simulate item marked as lost
2141
        # Simulate item marked as lost
2142
        ModItem( { itemlost => 3 }, $biblio->biblionumber, $item->itemnumber );
2142
        $item->itemlost(3)->store;
2143
        LostItem( $item->itemnumber, 1 );
2143
        LostItem( $item->itemnumber, 1 );
2144
2144
2145
        my $processing_fee_lines = Koha::Account::Lines->search(
2145
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2203-2209 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2203
        AddIssue( $patron->unblessed, $item->barcode );
2203
        AddIssue( $patron->unblessed, $item->barcode );
2204
2204
2205
        # Simulate item marked as lost
2205
        # Simulate item marked as lost
2206
        ModItem( { itemlost => 1 }, $biblio->biblionumber, $item->itemnumber );
2206
        $item->itemlost(1)->store;
2207
        LostItem( $item->itemnumber, 1 );
2207
        LostItem( $item->itemnumber, 1 );
2208
2208
2209
        my $processing_fee_lines = Koha::Account::Lines->search(
2209
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2273-2279 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2273
        AddIssue( $patron->unblessed, $item->barcode );
2273
        AddIssue( $patron->unblessed, $item->barcode );
2274
2274
2275
        # Simulate item marked as lost
2275
        # Simulate item marked as lost
2276
        ModItem( { itemlost => 3 }, $biblio->biblionumber, $item->itemnumber );
2276
        $item->itemlost(3)->store;
2277
        LostItem( $item->itemnumber, 1 );
2277
        LostItem( $item->itemnumber, 1 );
2278
2278
2279
        my $processing_fee_lines = Koha::Account::Lines->search(
2279
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2326-2332 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2326
        AddIssue( $patron->unblessed, $item->barcode );
2326
        AddIssue( $patron->unblessed, $item->barcode );
2327
2327
2328
        # Simulate item marked as lost
2328
        # Simulate item marked as lost
2329
        ModItem( { itemlost => 1 }, $biblio->biblionumber, $item->itemnumber );
2329
        $item->itemlost(1)->store;
2330
        LostItem( $item->itemnumber, 1 );
2330
        LostItem( $item->itemnumber, 1 );
2331
2331
2332
        my $processing_fee_lines = Koha::Account::Lines->search(
2332
        my $processing_fee_lines = Koha::Account::Lines->search(
Lines 2426-2432 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2426
                }
2426
                }
2427
            }
2427
            }
2428
        );
2428
        );
2429
        my $item_id = Koha::Item->new(
2429
        my $item = Koha::Item->new(
2430
            {
2430
            {
2431
                biblionumber     => $biblio->biblionumber,
2431
                biblionumber     => $biblio->biblionumber,
2432
                homebranch       => $library->branchcode,
2432
                homebranch       => $library->branchcode,
Lines 2435-2450 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2435
                replacementprice => $replacement_amount,
2435
                replacementprice => $replacement_amount,
2436
                itype            => $item_type->itemtype
2436
                itype            => $item_type->itemtype
2437
            },
2437
            },
2438
        )->store->itemnumber;
2438
        )->store;
2439
2439
2440
        AddIssue( $patron->unblessed, $barcode );
2440
        AddIssue( $patron->unblessed, $barcode );
2441
2441
2442
        # Simulate item marked as lost
2442
        # Simulate item marked as lost
2443
        ModItem( { itemlost => 1 }, $biblio->biblionumber, $item_id );
2443
        $item->itemlost(1)->store;
2444
        LostItem( $item_id, 1 );
2444
        LostItem( $item->itemnumber, 1 );
2445
2445
2446
        my $lost_fee_lines = Koha::Account::Lines->search(
2446
        my $lost_fee_lines = Koha::Account::Lines->search(
2447
            { borrowernumber => $patron->id, itemnumber => $item_id, debit_type_code => 'LOST' } );
2447
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'LOST' } );
2448
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2448
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2449
        my $lost_fee_line = $lost_fee_lines->next;
2449
        my $lost_fee_line = $lost_fee_lines->next;
2450
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2450
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
Lines 2476-2482 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2476
2476
2477
        t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 1 );
2477
        t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 1 );
2478
2478
2479
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id );
2479
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2480
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2480
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2481
2481
2482
        is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PROCESSING - payment (LOST_RETURN)' );
2482
        is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PROCESSING - payment (LOST_RETURN)' );
(-)a/t/db_dependent/Circulation/Returns.t (-1 / +1 lines)
Lines 324-330 subtest 'BlockReturnOfLostItems' => sub { Link Here
324
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
324
    my $checkout = AddIssue( $patron->unblessed, $item->barcode );
325
325
326
    # Mark the item as lost
326
    # Mark the item as lost
327
    ModItem({itemlost => 1}, $biblio->biblionumber, $item->itemnumber);
327
    $item->itemlost(1)->store;
328
328
329
    t::lib::Mocks::mock_preference('BlockReturnOfLostItems', 1);
329
    t::lib::Mocks::mock_preference('BlockReturnOfLostItems', 1);
330
    my ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
330
    my ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
(-)a/t/db_dependent/Holds.t (-8 / +8 lines)
Lines 282-288 ok( Link Here
282
);
282
);
283
283
284
{
284
{
285
    my $item_bibnum;my $item_bibitemnum;
286
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
285
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
287
    $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
286
    $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' });
288
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
287
    $itemnumber = $builder->build_sample_item({ library => $branch_1, biblionumber => $biblio->biblionumber })->itemnumber;
Lines 299-305 ok( Link Here
299
    is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
298
    is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
300
}
299
}
301
300
302
ModItem({ damaged => 1 }, $biblio->biblionumber, $itemnumber);
301
Koha::Items->find($itemnumber)->damaged(1)->store; # FIXME The $itemnumber is a bit confusing here
303
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
302
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
304
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" );
303
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" );
305
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" );
304
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" );
Lines 322-328 ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for d Link Here
322
321
323
# Regression test for bug 9532
322
# Regression test for bug 9532
324
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
323
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' });
325
$itemnumber = $builder->build_sample_item({ library => $branch_1, itype => 'CANNOT', biblionumber => $biblio->biblionumber})->itemnumber;
324
$item = $builder->build_sample_item({ library => $branch_1, itype => 'CANNOT', biblionumber => $biblio->biblionumber});
326
AddReserve(
325
AddReserve(
327
    $branch_1,
326
    $branch_1,
328
    $borrowernumbers[0],
327
    $borrowernumbers[0],
Lines 331-349 AddReserve( Link Here
331
    1,
330
    1,
332
);
331
);
333
is(
332
is(
334
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves',
333
    CanItemBeReserved( $borrowernumbers[0], $item->itemnumber)->{status}, 'tooManyReserves',
335
    "cannot request item if policy that matches on item-level item type forbids it"
334
    "cannot request item if policy that matches on item-level item type forbids it"
336
);
335
);
337
ModItem({ itype => 'CAN' }, $biblio->biblionumber, $itemnumber);
336
337
$item->itype('CAN')->store;
338
ok(
338
ok(
339
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK',
339
    CanItemBeReserved( $borrowernumbers[0], $item->itemnumber)->{status} eq 'OK',
340
    "can request item if policy that matches on item type allows it"
340
    "can request item if policy that matches on item type allows it"
341
);
341
);
342
342
343
t::lib::Mocks::mock_preference('item-level_itypes', 0);
343
t::lib::Mocks::mock_preference('item-level_itypes', 0);
344
ModItem({ itype => undef }, $biblio->biblionumber, $itemnumber);
344
$item->itype(undef)->store;
345
ok(
345
ok(
346
    CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves',
346
    CanItemBeReserved( $borrowernumbers[0], $item->itemnumber)->{status} eq 'tooManyReserves',
347
    "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)"
347
    "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)"
348
);
348
);
349
349
(-)a/t/db_dependent/Items.t (-20 / +19 lines)
Lines 83-92 subtest 'General Add, Get and Del tests' => sub { Link Here
83
    # Do not modify anything, and do not explode!
83
    # Do not modify anything, and do not explode!
84
    my $dbh = C4::Context->dbh;
84
    my $dbh = C4::Context->dbh;
85
    local $dbh->{RaiseError} = 1;
85
    local $dbh->{RaiseError} = 1;
86
    ModItem({}, $biblio->biblionumber, $itemnumber);
86
    $getitem->set({})->store;
87
87
88
    # Modify item; setting barcode.
88
    # Modify item; setting barcode.
89
    ModItem({ barcode => '987654321' }, $biblio->biblionumber, $itemnumber);
89
    $getitem->barcode('987654321')->store;
90
    my $moditem = Koha::Items->find($itemnumber);
90
    my $moditem = Koha::Items->find($itemnumber);
91
    cmp_ok($moditem->barcode, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->barcode . '.');
91
    cmp_ok($moditem->barcode, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->barcode . '.');
92
92
Lines 108-119 subtest 'General Add, Get and Del tests' => sub { Link Here
108
    is( $getitem->location, $location, "The location should not have been modified" );
108
    is( $getitem->location, $location, "The location should not have been modified" );
109
    is( $getitem->permanent_location, 'my permanent location', "The permanent_location should not have modified" );
109
    is( $getitem->permanent_location, 'my permanent location', "The permanent_location should not have modified" );
110
110
111
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber);
111
    $getitem->location($location)->store;
112
    $getitem = Koha::Items->find($itemnumber);
112
    $getitem = Koha::Items->find($itemnumber);
113
    is( $getitem->location, $location, "The location should have been set to correct location" );
113
    is( $getitem->location, $location, "The location should have been set to correct location" );
114
    is( $getitem->permanent_location, $location, "The permanent_location should have been set to location" );
114
    is( $getitem->permanent_location, $location, "The permanent_location should have been set to location" );
115
115
116
    ModItem({ location => 'CART' }, $biblio->biblionumber, $itemnumber);
116
    $getitem->location('CART')->store;
117
    $getitem = Koha::Items->find($itemnumber);
117
    $getitem = Koha::Items->find($itemnumber);
118
    is( $getitem->location, 'CART', "The location should have been set to CART" );
118
    is( $getitem->location, 'CART', "The location should have been set to CART" );
119
    is( $getitem->permanent_location, $location, "The permanent_location should not have been set to CART" );
119
    is( $getitem->permanent_location, $location, "The permanent_location should not have been set to CART" );
Lines 134-141 subtest 'ModItem tests' => sub { Link Here
134
    $schema->storage->txn_begin;
134
    $schema->storage->txn_begin;
135
135
136
    my $builder = t::lib::TestBuilder->new;
136
    my $builder = t::lib::TestBuilder->new;
137
    my $item = $builder->build({
137
    my $item = $builder->build_object({
138
        source => 'Item',
138
        class  => 'Koha::Items',
139
        value  => {
139
        value  => {
140
            itemlost     => 0,
140
            itemlost     => 0,
141
            damaged      => 0,
141
            damaged      => 0,
Lines 148-162 subtest 'ModItem tests' => sub { Link Here
148
148
149
    my @fields = qw( itemlost withdrawn damaged );
149
    my @fields = qw( itemlost withdrawn damaged );
150
    for my $field (@fields) {
150
    for my $field (@fields) {
151
        $item->{$field} = 1;
151
        my $field_on = "${field}_on";
152
        ModItem( $item, $item->{biblionumber}, $item->{itemnumber} );
152
        $item->$field(1)->store;
153
        my $post_mod_item = Koha::Items->find({ itemnumber => $item->{itemnumber} })->unblessed;
153
        my $post_mod_item = $item->get_from_storage;
154
        is( output_pref({ str => $post_mod_item->{$field."_on"}, dateonly => 1 }), output_pref({ dt => dt_from_string(), dateonly => 1 }), "When updating $field, $field"."_on is updated" );
154
        is( output_pref({ str => $post_mod_item->$field_on, dateonly => 1 }), output_pref({ dt => dt_from_string(), dateonly => 1 }), "When updating $field, $field_on is updated" );
155
155
156
        $item->{$field} = 0;
156
        $item->$field(0)->store;
157
        ModItem( $item, $item->{biblionumber}, $item->{itemnumber} );
157
        $post_mod_item = $item->get_from_storage;
158
        $post_mod_item = Koha::Items->find({ itemnumber => $item->{itemnumber} })->unblessed;
158
        is( $post_mod_item->$field_on, undef, "When clearing $field, $field_on is cleared" );
159
        is( $post_mod_item->{$field."_on"}, undef, "When clearing $field, $field"."_on is cleared" );
160
    }
159
    }
161
160
162
    $schema->storage->txn_rollback;
161
    $schema->storage->txn_rollback;
Lines 926-953 subtest 'Test logging for ModItem' => sub { Link Here
926
    my $biblio = $builder->build_sample_biblio();
925
    my $biblio = $builder->build_sample_biblio();
927
926
928
    # Add an item.
927
    # Add an item.
929
    my $itemnumber = $builder->build_sample_item(
928
    my $item = $builder->build_sample_item(
930
        {
929
        {
931
            biblionumber => $biblio->biblionumber,
930
            biblionumber => $biblio->biblionumber,
932
            library      => $library->{homebranch},
931
            library      => $library->{homebranch},
933
            location     => $location,
932
            location     => $location,
934
            itype        => $itemtype->{itemtype}
933
            itype        => $itemtype->{itemtype}
935
        }
934
        }
936
    )->itemnumber;
935
    );
937
936
938
    # False means no logging
937
    # False means no logging
939
    $schema->resultset('ActionLog')->search()->delete();
938
    $schema->resultset('ActionLog')->search()->delete();
940
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber, { log_action => 0 });
939
    $item->location($location)->store({ log_action => 0 });
941
    is( $schema->resultset('ActionLog')->count(), 0, 'False value does not trigger logging' );
940
    is( $schema->resultset('ActionLog')->count(), 0, 'False value does not trigger logging' );
942
941
943
    # True means logging
942
    # True means logging
944
    $schema->resultset('ActionLog')->search()->delete();
943
    $schema->resultset('ActionLog')->search()->delete();
945
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber, { log_action => 1 });
944
    $item->location($location)->store({ log_action => 1 });
946
    is( $schema->resultset('ActionLog')->count(), 1, 'True value does trigger logging' );
945
    is( $schema->resultset('ActionLog')->count(), 1, 'True value does trigger logging' );
947
946
948
    # Undefined defaults to true
947
    # Undefined defaults to true
949
    $schema->resultset('ActionLog')->search()->delete();
948
    $schema->resultset('ActionLog')->search()->delete();
950
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber);
949
    $item->location($location)->store();
951
    is( $schema->resultset('ActionLog')->count(), 1, 'Undefined value defaults to true, triggers logging' );
950
    is( $schema->resultset('ActionLog')->count(), 1, 'Undefined value defaults to true, triggers logging' );
952
951
953
    $schema->storage->txn_rollback;
952
    $schema->storage->txn_rollback;
(-)a/t/db_dependent/Items/AutomaticItemModificationByAge.t (-1 / +1 lines)
Lines 124-130 is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNew Link Here
124
my $dt_today = dt_from_string;
124
my $dt_today = dt_from_string;
125
my $days5ago = $dt_today->add_duration( DateTime::Duration->new( days => -5 ) );
125
my $days5ago = $dt_today->add_duration( DateTime::Duration->new( days => -5 ) );
126
126
127
C4::Items::ModItem( { dateaccessioned => $days5ago }, $biblionumber, $itemnumber );
127
$modified_item->dateaccessioned($days5ago)->store;
128
128
129
@rules = (
129
@rules = (
130
    {
130
    {
(-)a/t/db_dependent/Items_DelItemCheck.t (-15 / +15 lines)
Lines 80-88 my $biblio = $builder->build( Link Here
80
    }
80
    }
81
);
81
);
82
82
83
my $item = $builder->build(
83
my $item = $builder->build_object(
84
    {
84
    {
85
        source => 'Item',
85
        class => 'Koha::Items',
86
        value  => {
86
        value  => {
87
            biblionumber  => $biblio->{biblionumber},
87
            biblionumber  => $biblio->{biblionumber},
88
            homebranch    => $branch->{branchcode},
88
            homebranch    => $branch->{branchcode},
Lines 95-135 my $item = $builder->build( Link Here
95
95
96
# book_on_loan
96
# book_on_loan
97
97
98
AddIssue( $patron, $item->{barcode} );
98
AddIssue( $patron, $item->barcode );
99
99
100
is(
100
is(
101
    ItemSafeToDelete( $biblio->{biblionumber}, $item->{itemnumber} ),
101
    ItemSafeToDelete( $biblio->{biblionumber}, $item->itemnumber ),
102
    'book_on_loan',
102
    'book_on_loan',
103
    'ItemSafeToDelete reports item on loan',
103
    'ItemSafeToDelete reports item on loan',
104
);
104
);
105
105
106
is(
106
is(
107
    DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} ),
107
    DelItemCheck( $biblio->{biblionumber}, $item->itemnumber ),
108
    'book_on_loan',
108
    'book_on_loan',
109
    'item that is on loan cannot be deleted',
109
    'item that is on loan cannot be deleted',
110
);
110
);
111
111
112
AddReturn( $item->{barcode}, $branch->{branchcode} );
112
AddReturn( $item->barcode, $branch->{branchcode} );
113
113
114
# book_reserved is tested in t/db_dependent/Reserves.t
114
# book_reserved is tested in t/db_dependent/Reserves.t
115
115
116
# not_same_branch
116
# not_same_branch
117
t::lib::Mocks::mock_preference('IndependentBranches', 1);
117
t::lib::Mocks::mock_preference('IndependentBranches', 1);
118
ModItem( { homebranch => $branch2->{branchcode}, holdingbranch => $branch2->{branchcode} }, $biblio->{biblionumber}, $item->{itemnumber} );
118
$item->set( { homebranch => $branch2->{branchcode}, holdingbranch => $branch2->{branchcode} })->store;
119
119
120
is(
120
is(
121
    ItemSafeToDelete( $biblio->{biblionumber}, $item->{itemnumber} ),
121
    ItemSafeToDelete( $biblio->{biblionumber}, $item->itemnumber ),
122
    'not_same_branch',
122
    'not_same_branch',
123
    'ItemSafeToDelete reports IndependentBranches restriction',
123
    'ItemSafeToDelete reports IndependentBranches restriction',
124
);
124
);
125
125
126
is(
126
is(
127
    DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} ),
127
    DelItemCheck( $biblio->{biblionumber}, $item->itemnumber ),
128
    'not_same_branch',
128
    'not_same_branch',
129
    'IndependentBranches prevents deletion at another branch',
129
    'IndependentBranches prevents deletion at another branch',
130
);
130
);
131
131
132
ModItem( { homebranch => $branch->{branchcode}, holdingbranch => $branch->{branchcode} }, $biblio->{biblionumber}, $item->{itemnumber} );
132
$item->set( { homebranch => $branch->{branchcode}, holdingbranch => $branch->{branchcode} })->store;
133
133
134
# linked_analytics
134
# linked_analytics
135
135
Lines 139-151 ModItem( { homebranch => $branch->{branchcode}, holdingbranch => $branch->{branc Link Here
139
    $module->mock( GetAnalyticsCount => sub { return 1 } );
139
    $module->mock( GetAnalyticsCount => sub { return 1 } );
140
140
141
    is(
141
    is(
142
        ItemSafeToDelete( $biblio->{biblionumber}, $item->{itemnumber} ),
142
        ItemSafeToDelete( $biblio->{biblionumber}, $item->itemnumber ),
143
        'linked_analytics',
143
        'linked_analytics',
144
        'ItemSafeToDelete reports linked analytics',
144
        'ItemSafeToDelete reports linked analytics',
145
    );
145
    );
146
146
147
    is(
147
    is(
148
        DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} ),
148
        DelItemCheck( $biblio->{biblionumber}, $item->itemnumber ),
149
        'linked_analytics',
149
        'linked_analytics',
150
        'Linked analytics prevents deletion of item',
150
        'Linked analytics prevents deletion of item',
151
    );
151
    );
Lines 153-166 ModItem( { homebranch => $branch->{branchcode}, holdingbranch => $branch->{branc Link Here
153
}
153
}
154
154
155
is(
155
is(
156
    ItemSafeToDelete( $biblio->{biblionumber}, $item->{itemnumber} ),
156
    ItemSafeToDelete( $biblio->{biblionumber}, $item->itemnumber ),
157
    1,
157
    1,
158
    'ItemSafeToDelete shows item safe to delete'
158
    'ItemSafeToDelete shows item safe to delete'
159
);
159
);
160
160
161
DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} );
161
DelItemCheck( $biblio->{biblionumber}, $item->itemnumber );
162
162
163
my $test_item = Koha::Items->find( $item->{itemnumber} );
163
my $test_item = Koha::Items->find( $item->itemnumber );
164
164
165
is( $test_item, undef,
165
is( $test_item, undef,
166
    "DelItemCheck should delete item if ItemSafeToDelete returns true"
166
    "DelItemCheck should delete item if ItemSafeToDelete returns true"
(-)a/t/db_dependent/Labels/t_Label.t (-4 / +4 lines)
Lines 62-78 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 $itemnumber = $builder->build_sample_item(
65
my $item = $builder->build_sample_item(
66
    {
66
    {
67
        biblionumber => $bibnum,
67
        biblionumber => $bibnum,
68
        library      => $branch_1,
68
        library      => $branch_1,
69
        itype        => $itemtype,
69
        itype        => $itemtype,
70
    }
70
    }
71
)->itemnumber;
71
);
72
72
73
# Modify item; setting barcode.
73
# Modify item; setting barcode.
74
my $testbarcode = '97531';
74
my $testbarcode = '97531';
75
ModItem( { barcode => $testbarcode }, $bibnum, $itemnumber );
75
$item->barcode($testbarcode)->store;
76
76
77
my $layout = C4::Labels::Layout->new( layout_name => 'TEST' );
77
my $layout = C4::Labels::Layout->new( layout_name => 'TEST' );
78
78
Lines 99-105 my $dummy_template_values = { Link Here
99
99
100
my $label = C4::Labels::Label->new(
100
my $label = C4::Labels::Label->new(
101
    batch_id         => $batch_id,
101
    batch_id         => $batch_id,
102
    item_number      => $itemnumber,
102
    item_number      => $item->itemnumber,
103
    llx              => $llx,
103
    llx              => $llx,
104
    lly              => $lly,
104
    lly              => $lly,
105
    width            => $dummy_template_values->{'label_width'},
105
    width            => $dummy_template_values->{'label_width'},
(-)a/t/db_dependent/Reserves.t (-2 / +2 lines)
Lines 85-91 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 $itemnumber = $builder->build_sample_item({ biblionumber => $bibnum, library => $branch_1, itype => $itemtype })->itemnumber;
88
my $item = $builder->build_sample_item({ biblionumber => $bibnum, library => $branch_1, itype => $itemtype });
89
89
90
my $biblio_with_no_item = $builder->build({
90
my $biblio_with_no_item = $builder->build({
91
    source => 'Biblio'
91
    source => 'Biblio'
Lines 94-100 my $biblio_with_no_item = $builder->build({ Link Here
94
94
95
# Modify item; setting barcode.
95
# Modify item; setting barcode.
96
my $testbarcode = '97531';
96
my $testbarcode = '97531';
97
ModItem({ barcode => $testbarcode }, $bibnum, $itemnumber);
97
$item->barcode($testbarcode)->store; # FIXME We should not hardcode a barcode! Also, what's the purpose of this?
98
98
99
# Create a borrower
99
# Create a borrower
100
my %data = (
100
my %data = (
(-)a/t/db_dependent/api/v1/holds.t (-1 / +1 lines)
Lines 504-507 subtest 'PUT /holds/{hold_id}/priority tests' => sub { Link Here
504
    is( $hold_3->discard_changes->priority, 3, 'Priority adjusted correctly' );
504
    is( $hold_3->discard_changes->priority, 3, 'Priority adjusted correctly' );
505
505
506
    $schema->storage->txn_rollback;
506
    $schema->storage->txn_rollback;
507
};
507
};
(-)a/tools/inventory.pl (-7 / +6 lines)
Lines 199-219 if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { Link Here
199
        } else {
199
        } else {
200
            my $item = Koha::Items->find({barcode => $barcode});
200
            my $item = Koha::Items->find({barcode => $barcode});
201
            if ( $item ) {
201
            if ( $item ) {
202
                $item = $item->unblessed;
202
                my $item_unblessed = $item->unblessed;
203
                # Modify date last seen for scanned items, remove lost status
203
                # Modify date last seen for scanned items, remove lost status
204
                ModItem( { itemlost => 0, datelastseen => $date }, undef, $item->{'itemnumber'} );
204
                $item->set({ itemlost => 0, datelastseen => $date })->store;
205
                $moddatecount++;
205
                $moddatecount++;
206
                # update item hash accordingly
206
                # update item hash accordingly
207
                $item->{itemlost} = 0;
207
                $item_unblessed->{itemlost} = 0;
208
                $item->{datelastseen} = $date;
208
                $item_unblessed->{datelastseen} = $date;
209
                unless ( $dont_checkin ) {
209
                unless ( $dont_checkin ) {
210
                    $qonloan->execute($barcode);
210
                    $qonloan->execute($barcode);
211
                    if ($qonloan->rows){
211
                    if ($qonloan->rows){
212
                        my $data = $qonloan->fetchrow_hashref;
212
                        my $data = $qonloan->fetchrow_hashref;
213
                        my ($doreturn, $messages, $iteminformation, $borrower) =AddReturn($barcode, $data->{homebranch});
213
                        my ($doreturn, $messages, $iteminformation, $borrower) =AddReturn($barcode, $data->{homebranch});
214
                        if( $doreturn ) {
214
                        if( $doreturn ) {
215
                            $item->{onloan} = undef;
215
                            $item_unblessed->{onloan} = undef;
216
                            $item->{datelastseen} = dt_from_string;
216
                            $item_unblessed->{datelastseen} = dt_from_string;
217
                        } else {
217
                        } else {
218
                            push @errorloop, { barcode => $barcode, ERR_ONLOAN_NOT_RET => 1 };
218
                            push @errorloop, { barcode => $barcode, ERR_ONLOAN_NOT_RET => 1 };
219
                        }
219
                        }
220
- 

Return to bug 23463