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

(-)a/C4/Circulation.pm (-26 / +5 lines)
Lines 1675-1680 sub AddIssue { Link Here
1675
                CartToShelf( $item_object->itemnumber );
1675
                CartToShelf( $item_object->itemnumber );
1676
            }
1676
            }
1677
1677
1678
            # Update item location
1679
            $item_object->update_item_location( 'checkout' );
1680
1678
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1681
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1679
                UpdateTotalIssues( $item_object->biblionumber, 1, undef, { skip_holds_queue => 1 } );
1682
                UpdateTotalIssues( $item_object->biblionumber, 1, undef, { skip_holds_queue => 1 } );
1680
            }
1683
            }
Lines 2104-2135 sub AddReturn { Link Here
2104
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
2107
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
2105
    my $patron_unblessed = $patron ? $patron->unblessed : {};
2108
    my $patron_unblessed = $patron ? $patron->unblessed : {};
2106
2109
2107
    my $update_loc_rules = Koha::Config::SysPrefs->find('UpdateItemLocationOnCheckin')->get_yaml_pref_hash();
2110
    # Update item location
2108
    map { $update_loc_rules->{$_} = $update_loc_rules->{$_}[0] } keys %$update_loc_rules; #We can only move to one location so we flatten the arrays
2111
    $messages = $item->update_item_location( 'checkin' );
2109
    if ($update_loc_rules) {
2110
        if (defined $update_loc_rules->{_ALL_}) {
2111
            if ($update_loc_rules->{_ALL_} eq '_PERM_') { $update_loc_rules->{_ALL_} = $item->permanent_location; }
2112
            if ($update_loc_rules->{_ALL_} eq '_BLANK_') { $update_loc_rules->{_ALL_} = ''; }
2113
            if (
2114
                ( defined $item->location && $item->location ne $update_loc_rules->{_ALL_}) ||
2115
                (!defined $item->location && $update_loc_rules->{_ALL_} ne "")
2116
               ) {
2117
                $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{_ALL_} };
2118
                $item->location($update_loc_rules->{_ALL_})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1});
2119
            }
2120
        }
2121
        else {
2122
            foreach my $key ( keys %$update_loc_rules ) {
2123
                if ( $update_loc_rules->{$key} eq '_PERM_' ) { $update_loc_rules->{$key} = $item->permanent_location; }
2124
                if ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
2125
                if ( ($item->location eq $key && $item->location ne $update_loc_rules->{$key}) || ($key eq '_BLANK_' && $item->location eq '' && $update_loc_rules->{$key} ne '') ) {
2126
                    $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{$key} };
2127
                    $item->location($update_loc_rules->{$key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1});
2128
                    last;
2129
                }
2130
            }
2131
        }
2132
    }
2133
2112
2134
    my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin');
2113
    my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin');
2135
    if ($yaml) {
2114
    if ($yaml) {
(-)a/Koha/Item.pm (+50 lines)
Lines 1912-1917 sub is_notforloan { Link Here
1912
    return $is_notforloan;
1912
    return $is_notforloan;
1913
}
1913
}
1914
1914
1915
=head3 update_item_location
1916
1917
    $item->update_item_location( $action );
1918
1919
Update the item location on checkin or checkout. 
1920
1921
=cut
1922
1923
sub update_item_location {
1924
    my ( $self, $action ) = @_;
1925
1926
    my ($update_loc_rules, $messages);
1927
    if ( $action eq 'checkin' ) {
1928
        $update_loc_rules = Koha::Config::SysPrefs->find('UpdateItemLocationOnCheckin')->get_yaml_pref_hash();
1929
    } else {
1930
        $update_loc_rules = Koha::Config::SysPrefs->find('UpdateItemLocationOnCheckout')->get_yaml_pref_hash();
1931
    }
1932
1933
    map { $update_loc_rules->{$_} = $update_loc_rules->{$_}[0] } keys %$update_loc_rules; #We can only move to one location so we flatten the arrays
1934
    if ($update_loc_rules) {
1935
        if (defined $update_loc_rules->{_ALL_}) {
1936
            if ($update_loc_rules->{_ALL_} eq '_PERM_') { $update_loc_rules->{_ALL_} = $self->permanent_location; }
1937
            if ($update_loc_rules->{_ALL_} eq '_BLANK_') { $update_loc_rules->{_ALL_} = ''; }
1938
            if (
1939
                ( defined $self->location && $self->location ne $update_loc_rules->{_ALL_}) ||
1940
                (!defined $self->location && $update_loc_rules->{_ALL_} ne "")
1941
               ) {
1942
                $messages->{'ItemLocationUpdated'} = { from => $self->location, to => $update_loc_rules->{_ALL_} };
1943
                $self->location($update_loc_rules->{_ALL_})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1});
1944
            }
1945
        }
1946
        else {
1947
            foreach my $key ( keys %$update_loc_rules ) {
1948
                if ( $update_loc_rules->{$key} eq '_PERM_' ) { $update_loc_rules->{$key} = $self->permanent_location; }
1949
                if ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
1950
		if ( 
1951
		    (defined $self->location && $self->location eq $key && $self->location ne $update_loc_rules->{$key}) || 
1952
		    (defined $self->location && $key eq '_BLANK_' && $self->location eq '' && $update_loc_rules->{$key} ne '') 
1953
	        ) {
1954
                    $messages->{'ItemLocationUpdated'} = { from => $self->location, to => $update_loc_rules->{$key} };
1955
                    $self->location($update_loc_rules->{$key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1});
1956
                    last;
1957
                }
1958
            }
1959
        }
1960
    }
1961
1962
    return $messages;
1963
}
1964
1915
=head3 _type
1965
=head3 _type
1916
1966
1917
=cut
1967
=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 => 50;
20
use Test::More tests => 63;
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