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
	    my $messages = $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 (-1 / +47 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
    my $update_location = $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 ( ($self->location eq $key && $self->location ne $update_loc_rules->{$key}) || ($key eq '_BLANK_' && $self->location eq '' && $update_loc_rules->{$key} ne '') ) {
1951
		    $messages->{'ItemLocationUpdated'} = { from => $self->location, to => $update_loc_rules->{$key} };
1952
                    $self->location($update_loc_rules->{$key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1});
1953
                    last;
1954
                }
1955
            }
1956
        }
1957
    }    
1958
1959
    return $messages;
1960
}
1961
1915
=head3 _type
1962
=head3 _type
1916
1963
1917
=cut
1964
=cut
1918
- 

Return to bug 21159