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

(-)a/C4/Circulation.pm (-27 / +6 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 1787-1793 sub AddIssue { Link Here
1787
            ) if C4::Context->preference('RealTimeHoldsQueue');
1790
            ) if C4::Context->preference('RealTimeHoldsQueue');
1788
        }
1791
        }
1789
    }
1792
    }
1790
    return $issue;
1793
    return ($issue);
1791
}
1794
}
1792
1795
1793
=head2 GetLoanLength
1796
=head2 GetLoanLength
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 (-4 / +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 493-500 AddReturn( 'barcode_5', $branchcode_1 ); Link Here
493
my $item3 = Koha::Items->find( $itemnumber3 );
493
my $item3 = Koha::Items->find( $itemnumber3 );
494
is( $item3->location, 'CART', q{UpdateItemLocationOnCheckin updates location value from NULL (i.e. the item has no shelving location set) to 'CART' with setting "_ALL_: CART"} );
494
is( $item3->location, 'CART', q{UpdateItemLocationOnCheckin updates location value from NULL (i.e. the item has no shelving location set) to 'CART' with setting "_ALL_: CART"} );
495
495
496
497
498
# Bug 14640 - Cancel the hold on checking out if asked
496
# Bug 14640 - Cancel the hold on checking out if asked
499
my $reserve_id = AddReserve(
497
my $reserve_id = AddReserve(
500
    {
498
    {
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];
541
my ( $unseen_reset ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
544
is( $unseen_reset, 0, 'seen renewal resets the unseen count' );
542
is( $unseen_reset, 0, 'seen renewal resets the unseen count' );
545
543
544
# Bug 21159 - Update item shelving location on checkout
545
my $itemnumber4 = Koha::Item->new(
546
    {
547
        biblionumber   => $biblionumber,
548
        barcode        => 'barcode_6',
549
        itemcallnumber => 'callnumber3',
550
        homebranch     => $branchcode_1,
551
        holdingbranch  => $branchcode_1,
552
        location       => 'FIC',
553
        itype          => $itemtype
554
    },
555
)->store->itemnumber;
556
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', q{} );
557
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', q{} );
558
AddIssue( $borrower_1, 'barcode_6');
559
my $item4 = Koha::Items->find( $itemnumber4 );
560
ok( $item4->location eq 'FIC', 'UpdateItemLocationOnCheckout does not modify value when not enabled' );
561
562
#---
563
AddReturn( 'barcode_6', $branchcode_1 );
564
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', 'FIC: GEN' );
565
$log_count_before = $schema->resultset('ActionLog')->search({module => 'CATALOGUING'})->count();
566
AddIssue( $borrower_1, 'barcode_6' );
567
$item4 = Koha::Items->find( $itemnumber4 );
568
is( $item4->location, 'GEN', q{UpdateItemLocationOnCheckout updates location value from 'FIC' to 'GEN' with setting "FIC: GEN"} );
569
is( $item4->permanent_location, 'GEN', q{UpdateItemLocationOnCheckout updates permanent_location value from 'FIC' to 'GEN' with setting "FIC: GEN"} );
570
$log_count_after = $schema->resultset('ActionLog')->search({module => 'CATALOGUING'})->count();
571
is($log_count_before, $log_count_after, "Change from UpdateNotForLoanStatusOnCheckout is not logged");
572
AddReturn( 'barcode_6', $branchcode_1 );
573
AddIssue( $borrower_1, 'barcode_6' );
574
$item4 = Koha::Items->find( $itemnumber4 );
575
ok( $item4->location eq 'GEN', q{UpdateItemLocationOnCheckout does not update location value from 'GEN' with setting "FIC: GEN"} );
576
577
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', '_ALL_: CART' );
578
AddReturn( 'barcode_6', $branchcode_1 );
579
AddIssue( $borrower_1, 'barcode_6' );
580
$item4 = Koha::Items->find( $itemnumber4 );
581
ok( $item4->location eq 'CART', q{UpdateItemLocationOnCheckout updates location value from 'GEN' with setting "_ALL_: CART"} );
582
ok( $item4->permanent_location eq 'GEN', q{UpdateItemLocationOnCheckout does not update permanent_location value from 'GEN' with setting "_ALL_: CART"} );
583
584
$item4->location('GEN')->store;
585
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', "GEN: _BLANK_\n_BLANK_: PROC\nPROC: _PERM_" );
586
AddReturn( 'barcode_6', $branchcode_1 );
587
AddIssue( $borrower_1, 'barcode_6' );
588
$item4 = Koha::Items->find( $itemnumber4 );
589
ok( $item4->location eq '', q{UpdateItemLocationOnCheckout updates location value from 'GEN' to '' with setting "GEN: _BLANK_"} );
590
AddReturn( 'barcode_6', $branchcode_1 );
591
AddIssue( $borrower_1, 'barcode_6' );
592
$item4 = Koha::Items->find( $itemnumber4 );
593
ok( $item4->location eq 'PROC' , q{UpdateItemLocationOnCheckout updates location value from '' to 'PROC' with setting "_BLANK_: PROC"} );
594
ok( $item4->permanent_location eq '' , q{UpdateItemLocationOnCheckout does not update permanent_location value from '' to 'PROC' with setting "_BLANK_: PROC"} );
595
AddReturn( 'barcode_6', $branchcode_1 );
596
AddIssue( $borrower_1, 'barcode_6' );
597
$item4 = Koha::Items->find( $itemnumber4 );
598
ok( $item4->location eq '' , q{UpdateItemLocationOnCheckout updates location value from 'PROC' to '' with setting "PROC: _PERM_" } );
599
ok( $item4->permanent_location eq '' , q{UpdateItemLocationOnCheckout does not update permanent_location from '' with setting "PROC: _PERM_" } );
600
601
# Bug 28472
602
my $itemnumber5 = Koha::Item->new(
603
    {
604
        biblionumber   => $biblionumber,
605
        barcode        => 'barcode_7',
606
        itemcallnumber => 'callnumber5',
607
        homebranch     => $branchcode_1,
608
        holdingbranch  => $branchcode_1,
609
        location       => undef,
610
        itype          => $itemtype
611
    }
612
)->store->itemnumber;
613
614
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', '_ALL_: CART' );
615
AddIssue( $borrower_1, 'barcode_7' );
616
my $item5 = Koha::Items->find( $itemnumber5 );
617
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"} );
618
619
546
#End transaction
620
#End transaction
547
$schema->storage->txn_rollback;
621
$schema->storage->txn_rollback;
548
- 

Return to bug 21159