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

(-)a/C4/Circulation.pm (-63 / +7 lines)
Lines 1684-1689 sub AddIssue { Link Here
1684
                CartToShelf( $item_object->itemnumber );
1684
                CartToShelf( $item_object->itemnumber );
1685
            }
1685
            }
1686
1686
1687
            # Update item location
1688
            $item_object->update_item_location( 'checkout' );
1689
1687
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1690
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1688
                UpdateTotalIssues( $item_object->biblionumber, 1, undef, { skip_holds_queue => 1 } );
1691
                UpdateTotalIssues( $item_object->biblionumber, 1, undef, { skip_holds_queue => 1 } );
1689
            }
1692
            }
Lines 2152-2220 sub AddReturn { Link Here
2152
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
2155
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
2153
    my $patron_unblessed = $patron ? $patron->unblessed : {};
2156
    my $patron_unblessed = $patron ? $patron->unblessed : {};
2154
2157
2155
    my $update_loc_rules = C4::Context->yaml_preference('UpdateItemLocationOnCheckin');
2158
    # Update item location
2156
    if ($update_loc_rules) {
2159
    my $loc_messages = $item->update_item_location( 'checkin' );
2157
        if ( defined $update_loc_rules->{_ALL_} ) {
2160
    foreach my $loc_msg_key ( keys %$loc_messages ) {
2158
            if ( $update_loc_rules->{_ALL_} eq '_PERM_' ) {
2161
        $messages->{ $loc_msg_key } = $loc_messages->{ $loc_msg_key };
2159
                $update_loc_rules->{_ALL_} = $item->permanent_location;
2160
            }
2161
            if ( $update_loc_rules->{_ALL_} eq '_BLANK_' ) {
2162
                $update_loc_rules->{_ALL_} = '';
2163
            }
2164
            if (
2165
                (
2166
                    defined $item->location
2167
                    && $item->location ne $update_loc_rules->{_ALL_}
2168
                )
2169
                || ( !defined $item->location
2170
                    && $update_loc_rules->{_ALL_} ne "" )
2171
              )
2172
            {
2173
                $messages->{'ItemLocationUpdated'} =
2174
                  { from => $item->location, to => $update_loc_rules->{_ALL_} };
2175
                $item->location( $update_loc_rules->{_ALL_} )->store(
2176
                    {
2177
                        log_action        => 0,
2178
                        skip_record_index => 1,
2179
                        skip_holds_queue  => 1
2180
                    }
2181
                );
2182
            }
2183
        }
2184
        else {
2185
            foreach my $key ( keys %$update_loc_rules ) {
2186
                if ( $update_loc_rules->{$key} eq '_PERM_' ) {
2187
                    $update_loc_rules->{$key} = $item->permanent_location;
2188
                }
2189
                elsif ( $update_loc_rules->{$key} eq '_BLANK_' ) {
2190
                    $update_loc_rules->{$key} = '';
2191
                }
2192
                if (
2193
                    (
2194
                           defined $item->location
2195
                        && $item->location eq $key
2196
                        && $item->location ne $update_loc_rules->{$key}
2197
                    )
2198
                    || (   $key eq '_BLANK_'
2199
                        && ( !defined $item->location || $item->location eq '' )
2200
                        && $update_loc_rules->{$key} ne '' )
2201
                  )
2202
                {
2203
                    $messages->{'ItemLocationUpdated'} = {
2204
                        from => $item->location,
2205
                        to   => $update_loc_rules->{$key}
2206
                    };
2207
                    $item->location( $update_loc_rules->{$key} )->store(
2208
                        {
2209
                            log_action        => 0,
2210
                            skip_record_index => 1,
2211
                            skip_holds_queue  => 1
2212
                        }
2213
                    );
2214
                    last;
2215
                }
2216
            }
2217
        }
2218
    }
2162
    }
2219
2163
2220
    my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin');
2164
    my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin');
(-)a/Koha/Item.pm (+84 lines)
Lines 2171-2176 sub strings_map { Link Here
2171
    return $strings;
2171
    return $strings;
2172
}
2172
}
2173
2173
2174
=head3 update_item_location
2175
2176
    $item->update_item_location( $action );
2177
2178
Update the item location on checkin or checkout.
2179
2180
=cut
2181
2182
sub update_item_location {
2183
    my ( $self, $action ) = @_;
2184
2185
    my ($update_loc_rules, $messages);
2186
    if ( $action eq 'checkin' ) {
2187
        $update_loc_rules = C4::Context->yaml_preference('UpdateItemLocationOnCheckin');
2188
    } else {
2189
        $update_loc_rules = C4::Context->yaml_preference('UpdateItemLocationOnCheckout');
2190
    }
2191
2192
    if ($update_loc_rules) {
2193
        if ( defined $update_loc_rules->{_ALL_} ) {
2194
            if ( $update_loc_rules->{_ALL_} eq '_PERM_' ) {
2195
                $update_loc_rules->{_ALL_} = $self->permanent_location;
2196
            }
2197
            if ( $update_loc_rules->{_ALL_} eq '_BLANK_' ) {
2198
                $update_loc_rules->{_ALL_} = '';
2199
            }
2200
            if (
2201
                (
2202
                    defined $self->location
2203
                    && $self->location ne $update_loc_rules->{_ALL_}
2204
                )
2205
                || ( !defined $self->location
2206
                    && $update_loc_rules->{_ALL_} ne "" )
2207
              )
2208
            {
2209
                $messages->{'ItemLocationUpdated'} =
2210
                  { from => $self->location, to => $update_loc_rules->{_ALL_} };
2211
                $self->location( $update_loc_rules->{_ALL_} )->store(
2212
                    {
2213
                        log_action        => 0,
2214
                        skip_record_index => 1,
2215
                        skip_holds_queue  => 1
2216
                    }
2217
                );
2218
            }
2219
        }
2220
        else {
2221
            foreach my $key ( keys %$update_loc_rules ) {
2222
                if ( $update_loc_rules->{$key} eq '_PERM_' ) {
2223
                    $update_loc_rules->{$key} = $self->permanent_location;
2224
                }
2225
                elsif ( $update_loc_rules->{$key} eq '_BLANK_' ) {
2226
                    $update_loc_rules->{$key} = '';
2227
                }
2228
                if (
2229
                    (
2230
                           defined $self->location
2231
                        && $self->location eq $key
2232
                        && $self->location ne $update_loc_rules->{$key}
2233
                    )
2234
                    || (   $key eq '_BLANK_'
2235
                        && ( !defined $self->location || $self->location eq '' )
2236
                        && $update_loc_rules->{$key} ne '' )
2237
                  )
2238
                {
2239
                    $messages->{'ItemLocationUpdated'} = {
2240
                        from => $self->location,
2241
                        to   => $update_loc_rules->{$key}
2242
                    };
2243
                    $self->location( $update_loc_rules->{$key} )->store(
2244
                        {
2245
                            log_action        => 0,
2246
                            skip_record_index => 1,
2247
                            skip_holds_queue  => 1
2248
                        }
2249
                    );
2250
                    last;
2251
                }
2252
            }
2253
        }
2254
    }
2255
    return $messages;
2256
}
2257
2174
=head3 _type
2258
=head3 _type
2175
2259
2176
=cut
2260
=cut
(-)a/t/db_dependent/Circulation/issue.t (-2 / +78 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 53;
20
use Test::More tests => 66;
21
use DateTime::Duration;
21
use DateTime::Duration;
22
22
23
use t::lib::Mocks;
23
use t::lib::Mocks;
Lines 641-645 AddReturn( 'barcode_6', $branchcode_1 ); Link Here
641
$item = Koha::Items->find( $itemnumber4 );
641
$item = Koha::Items->find( $itemnumber4 );
642
ok( $item->notforloan eq 0, q{UpdateNotForLoanStatusOnCheckout does not update notforloan value from 0 with setting "-1: 0"} );
642
ok( $item->notforloan eq 0, q{UpdateNotForLoanStatusOnCheckout does not update notforloan value from 0 with setting "-1: 0"} );
643
643
644
# Bug 21159 - Update item shelving location on checkout
645
my $itemnumber5 = Koha::Item->new(
646
    {
647
        biblionumber   => $biblionumber,
648
        barcode        => 'barcode_7',
649
        itemcallnumber => 'callnumber3',
650
        homebranch     => $branchcode_1,
651
        holdingbranch  => $branchcode_1,
652
        location       => 'FIC',
653
        itype          => $itemtype
654
    },
655
)->store->itemnumber;
656
657
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', q{} );
658
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', q{} );
659
AddIssue( $patron_1, 'barcode_7');
660
my $item5 = Koha::Items->find( $itemnumber5 );
661
ok( $item5->location eq 'FIC', 'UpdateItemLocationOnCheckout does not modify value when not enabled' );
662
663
#---
664
AddReturn( 'barcode_7', $branchcode_1 );
665
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', 'FIC: GEN' );
666
$log_count_before = $schema->resultset('ActionLog')->search({module => 'CATALOGUING'})->count();
667
AddIssue( $patron_1, 'barcode_7' );
668
$item5 = Koha::Items->find( $itemnumber5 );
669
is( $item5->location, 'GEN', q{UpdateItemLocationOnCheckout updates location value from 'FIC' to 'GEN' with setting "FIC: GEN"} );
670
is( $item5->permanent_location, 'GEN', q{UpdateItemLocationOnCheckout updates permanent_location value from 'FIC' to 'GEN' with setting "FIC: GEN"} );
671
$log_count_after = $schema->resultset('ActionLog')->search({module => 'CATALOGUING'})->count();
672
is($log_count_before, $log_count_after, "Change from UpdateNotForLoanStatusOnCheckout is not logged");
673
AddReturn( 'barcode_7', $branchcode_1 );
674
AddIssue( $patron_1, 'barcode_7' );
675
$item5 = Koha::Items->find( $itemnumber5 );
676
ok( $item5->location eq 'GEN', q{UpdateItemLocationOnCheckout does not update location value from 'GEN' with setting "FIC: GEN"} );
677
678
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', '_ALL_: CART' );
679
AddReturn( 'barcode_7', $branchcode_1 );
680
AddIssue( $patron_1, 'barcode_7' );
681
$item5 = Koha::Items->find( $itemnumber5 );
682
ok( $item5->location eq 'CART', q{UpdateItemLocationOnCheckout updates location value from 'GEN' with setting "_ALL_: CART"} );
683
ok( $item5->permanent_location eq 'GEN', q{UpdateItemLocationOnCheckout does not update permanent_location value from 'GEN' with setting "_ALL_: CART"} );
684
685
$item5->location('GEN')->store;
686
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', "GEN: _BLANK_\n_BLANK_: PROC\nPROC: _PERM_" );
687
AddReturn( 'barcode_7', $branchcode_1 );
688
AddIssue( $patron_1, 'barcode_7' );
689
$item5 = Koha::Items->find( $itemnumber5 );
690
ok( $item5->location eq '', q{UpdateItemLocationOnCheckout updates location value from 'GEN' to '' with setting "GEN: _BLANK_"} );
691
AddReturn( 'barcode_7', $branchcode_1 );
692
AddIssue( $patron_1, 'barcode_7' );
693
$item5 = Koha::Items->find( $itemnumber5 );
694
ok( $item5->location eq 'PROC' , q{UpdateItemLocationOnCheckout updates location value from '' to 'PROC' with setting "_BLANK_: PROC"} );
695
ok( $item5->permanent_location eq '' , q{UpdateItemLocationOnCheckout does not update permanent_location value from '' to 'PROC' with setting "_BLANK_: PROC"} );
696
AddReturn( 'barcode_7', $branchcode_1 );
697
AddIssue( $patron_1, 'barcode_7' );
698
$item5 = Koha::Items->find( $itemnumber5 );
699
ok( $item5->location eq '' , q{UpdateItemLocationOnCheckout updates location value from 'PROC' to '' with setting "PROC: _PERM_" } );
700
ok( $item5->permanent_location eq '' , q{UpdateItemLocationOnCheckout does not update permanent_location from '' with setting "PROC: _PERM_" } );
701
702
# Bug 28472
703
my $itemnumber6 = Koha::Item->new(
704
    {
705
        biblionumber   => $biblionumber,
706
        barcode        => 'barcode_8',
707
        itemcallnumber => 'callnumber5',
708
        homebranch     => $branchcode_1,
709
        holdingbranch  => $branchcode_1,
710
        location       => undef,
711
        itype          => $itemtype
712
    }
713
)->store->itemnumber;
714
715
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', '_ALL_: CART' );
716
AddIssue( $patron_1, 'barcode_8' );
717
my $item6 = Koha::Items->find( $itemnumber6 );
718
is( $item6->location, 'CART', q{UpdateItemLocationOnCheckout updates location value from NULL (i.e. the item has no shelving location set) to 'CART' with setting "_ALL_: CART"} );
719
720
644
#End transaction
721
#End transaction
645
$schema->storage->txn_rollback;
722
$schema->storage->txn_rollback;
646
- 

Return to bug 21159