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

(-)a/C4/Circulation.pm (-26 / +5 lines)
Lines 1683-1688 sub AddIssue { Link Here
1683
                CartToShelf( $item_object->itemnumber );
1683
                CartToShelf( $item_object->itemnumber );
1684
            }
1684
            }
1685
1685
1686
            # Update item location
1687
            $item_object->update_item_location( 'checkout' );
1688
1686
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1689
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1687
                UpdateTotalIssues( $item_object->biblionumber, 1, undef, { skip_holds_queue => 1 } );
1690
                UpdateTotalIssues( $item_object->biblionumber, 1, undef, { skip_holds_queue => 1 } );
1688
            }
1691
            }
Lines 2117-2148 sub AddReturn { Link Here
2117
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
2120
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
2118
    my $patron_unblessed = $patron ? $patron->unblessed : {};
2121
    my $patron_unblessed = $patron ? $patron->unblessed : {};
2119
2122
2120
    my $update_loc_rules = Koha::Config::SysPrefs->find('UpdateItemLocationOnCheckin')->get_yaml_pref_hash();
2123
    # Update item location
2121
    map { $update_loc_rules->{$_} = $update_loc_rules->{$_}[0] } keys %$update_loc_rules; #We can only move to one location so we flatten the arrays
2124
    $messages = $item->update_item_location( 'checkin' );
2122
    if ($update_loc_rules) {
2123
        if (defined $update_loc_rules->{_ALL_}) {
2124
            if ($update_loc_rules->{_ALL_} eq '_PERM_') { $update_loc_rules->{_ALL_} = $item->permanent_location; }
2125
            if ($update_loc_rules->{_ALL_} eq '_BLANK_') { $update_loc_rules->{_ALL_} = ''; }
2126
            if (
2127
                ( defined $item->location && $item->location ne $update_loc_rules->{_ALL_}) ||
2128
                (!defined $item->location && $update_loc_rules->{_ALL_} ne "")
2129
               ) {
2130
                $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{_ALL_} };
2131
                $item->location($update_loc_rules->{_ALL_})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1});
2132
            }
2133
        }
2134
        else {
2135
            foreach my $key ( keys %$update_loc_rules ) {
2136
                if ( $update_loc_rules->{$key} eq '_PERM_' ) { $update_loc_rules->{$key} = $item->permanent_location; }
2137
                if ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
2138
                if ( ($item->location eq $key && $item->location ne $update_loc_rules->{$key}) || ($key eq '_BLANK_' && $item->location eq '' && $update_loc_rules->{$key} ne '') ) {
2139
                    $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{$key} };
2140
                    $item->location($update_loc_rules->{$key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1});
2141
                    last;
2142
                }
2143
            }
2144
        }
2145
    }
2146
2125
2147
    my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin');
2126
    my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin');
2148
    if ($yaml) {
2127
    if ($yaml) {
(-)a/Koha/Item.pm (+49 lines)
Lines 2058-2063 sub is_denied_renewal { Link Here
2058
    return 0;
2058
    return 0;
2059
}
2059
}
2060
2060
2061
=head3 update_item_location
2062
2063
    $item->update_item_location( $action );
2064
2065
Update the item location on checkin or checkout.
2066
2067
=cut
2068
2069
sub update_item_location {
2070
    my ( $self, $action ) = @_;
2071
2072
    my ($update_loc_rules, $messages);
2073
    if ( $action eq 'checkin' ) {
2074
        $update_loc_rules = Koha::Config::SysPrefs->find('UpdateItemLocationOnCheckin')->get_yaml_pref_hash();
2075
    } else {
2076
        $update_loc_rules = Koha::Config::SysPrefs->find('UpdateItemLocationOnCheckout')->get_yaml_pref_hash();
2077
    }
2078
2079
    map { $update_loc_rules->{$_} = $update_loc_rules->{$_}[0] } keys %$update_loc_rules; #We can only move to one location so we flatten the arrays
2080
    if ($update_loc_rules) {
2081
        if (defined $update_loc_rules->{_ALL_}) {
2082
            if ($update_loc_rules->{_ALL_} eq '_PERM_') { $update_loc_rules->{_ALL_} = $self->permanent_location; }
2083
            if ($update_loc_rules->{_ALL_} eq '_BLANK_') { $update_loc_rules->{_ALL_} = ''; }
2084
            if (
2085
                ( defined $self->location && $self->location ne $update_loc_rules->{_ALL_}) ||
2086
                (!defined $self->location && $update_loc_rules->{_ALL_} ne "")
2087
               ) {
2088
                $messages->{'ItemLocationUpdated'} = { from => $self->location, to => $update_loc_rules->{_ALL_} };
2089
                $self->location($update_loc_rules->{_ALL_})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1});
2090
            }
2091
        }
2092
        else {
2093
            foreach my $key ( keys %$update_loc_rules ) {
2094
                if ( $update_loc_rules->{$key} eq '_PERM_' ) { $update_loc_rules->{$key} = $self->permanent_location; }
2095
                if ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
2096
                if (
2097
                    (defined $self->location && $self->location eq $key && $self->location ne $update_loc_rules->{$key}) ||
2098
                    (defined $self->location && $key eq '_BLANK_' && $self->location eq '' && $update_loc_rules->{$key} ne '')
2099
                ) {
2100
                    $messages->{'ItemLocationUpdated'} = { from => $self->location, to => $update_loc_rules->{$key} };
2101
                    $self->location($update_loc_rules->{$key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1});
2102
                    last;
2103
                }
2104
            }
2105
        }
2106
    }
2107
    return $messages;
2108
}
2109
2061
=head3 _type
2110
=head3 _type
2062
2111
2063
=cut
2112
=cut
(-)a/t/db_dependent/Circulation/issue.t (-2 / +77 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 49;
20
use Test::More tests => 62;
21
use DateTime::Duration;
21
use DateTime::Duration;
22
22
23
use t::lib::Mocks;
23
use t::lib::Mocks;
Lines 543-547 AddRenewal( $unseen_patron->borrowernumber, $unseen_item->itemnumber, $branchcod Link Here
543
my ( $unseen_reset ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
543
my ( $unseen_reset ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
544
is( $unseen_reset, 0, 'seen renewal resets the unseen count' );
544
is( $unseen_reset, 0, 'seen renewal resets the unseen count' );
545
545
546
# Bug 21159 - Update item shelving location on checkout
547
my $itemnumber4 = Koha::Item->new(
548
    {
549
        biblionumber   => $biblionumber,
550
        barcode        => 'barcode_6',
551
        itemcallnumber => 'callnumber3',
552
        homebranch     => $branchcode_1,
553
        holdingbranch  => $branchcode_1,
554
        location       => 'FIC',
555
        itype          => $itemtype
556
    },
557
)->store->itemnumber;
558
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', q{} );
559
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', q{} );
560
AddIssue( $borrower_1, 'barcode_6');
561
my $item4 = Koha::Items->find( $itemnumber4 );
562
ok( $item4->location eq 'FIC', 'UpdateItemLocationOnCheckout does not modify value when not enabled' );
563
564
#---
565
AddReturn( 'barcode_6', $branchcode_1 );
566
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', 'FIC: GEN' );
567
$log_count_before = $schema->resultset('ActionLog')->search({module => 'CATALOGUING'})->count();
568
AddIssue( $borrower_1, 'barcode_6' );
569
$item4 = Koha::Items->find( $itemnumber4 );
570
is( $item4->location, 'GEN', q{UpdateItemLocationOnCheckout updates location value from 'FIC' to 'GEN' with setting "FIC: GEN"} );
571
is( $item4->permanent_location, 'GEN', q{UpdateItemLocationOnCheckout updates permanent_location value from 'FIC' to 'GEN' with setting "FIC: GEN"} );
572
$log_count_after = $schema->resultset('ActionLog')->search({module => 'CATALOGUING'})->count();
573
is($log_count_before, $log_count_after, "Change from UpdateNotForLoanStatusOnCheckout is not logged");
574
AddReturn( 'barcode_6', $branchcode_1 );
575
AddIssue( $borrower_1, 'barcode_6' );
576
$item4 = Koha::Items->find( $itemnumber4 );
577
ok( $item4->location eq 'GEN', q{UpdateItemLocationOnCheckout does not update location value from 'GEN' with setting "FIC: GEN"} );
578
579
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', '_ALL_: CART' );
580
AddReturn( 'barcode_6', $branchcode_1 );
581
AddIssue( $borrower_1, 'barcode_6' );
582
$item4 = Koha::Items->find( $itemnumber4 );
583
ok( $item4->location eq 'CART', q{UpdateItemLocationOnCheckout updates location value from 'GEN' with setting "_ALL_: CART"} );
584
ok( $item4->permanent_location eq 'GEN', q{UpdateItemLocationOnCheckout does not update permanent_location value from 'GEN' with setting "_ALL_: CART"} );
585
586
$item4->location('GEN')->store;
587
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', "GEN: _BLANK_\n_BLANK_: PROC\nPROC: _PERM_" );
588
AddReturn( 'barcode_6', $branchcode_1 );
589
AddIssue( $borrower_1, 'barcode_6' );
590
$item4 = Koha::Items->find( $itemnumber4 );
591
ok( $item4->location eq '', q{UpdateItemLocationOnCheckout updates location value from 'GEN' to '' with setting "GEN: _BLANK_"} );
592
AddReturn( 'barcode_6', $branchcode_1 );
593
AddIssue( $borrower_1, 'barcode_6' );
594
$item4 = Koha::Items->find( $itemnumber4 );
595
ok( $item4->location eq 'PROC' , q{UpdateItemLocationOnCheckout updates location value from '' to 'PROC' with setting "_BLANK_: PROC"} );
596
ok( $item4->permanent_location eq '' , q{UpdateItemLocationOnCheckout does not update permanent_location value from '' to 'PROC' with setting "_BLANK_: PROC"} );
597
AddReturn( 'barcode_6', $branchcode_1 );
598
AddIssue( $borrower_1, 'barcode_6' );
599
$item4 = Koha::Items->find( $itemnumber4 );
600
ok( $item4->location eq '' , q{UpdateItemLocationOnCheckout updates location value from 'PROC' to '' with setting "PROC: _PERM_" } );
601
ok( $item4->permanent_location eq '' , q{UpdateItemLocationOnCheckout does not update permanent_location from '' with setting "PROC: _PERM_" } );
602
603
# Bug 28472
604
my $itemnumber5 = Koha::Item->new(
605
    {
606
        biblionumber   => $biblionumber,
607
        barcode        => 'barcode_7',
608
        itemcallnumber => 'callnumber5',
609
        homebranch     => $branchcode_1,
610
        holdingbranch  => $branchcode_1,
611
        location       => undef,
612
        itype          => $itemtype
613
    }
614
)->store->itemnumber;
615
616
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', '_ALL_: CART' );
617
AddIssue( $borrower_1, 'barcode_7' );
618
my $item5 = Koha::Items->find( $itemnumber5 );
619
is( $item5->location, 'CART', q{UpdateItemLocationOnCheckout updates location value from NULL (i.e. the item has no shelving location set) to 'CART' with setting "_ALL_: CART"} );
620
621
546
#End transaction
622
#End transaction
547
$schema->storage->txn_rollback;
623
$schema->storage->txn_rollback;
548
- 

Return to bug 21159