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

(-)a/C4/Circulation.pm (-63 / +7 lines)
Lines 1689-1694 sub AddIssue { Link Here
1689
                CartToShelf( $item_object->itemnumber );
1689
                CartToShelf( $item_object->itemnumber );
1690
            }
1690
            }
1691
1691
1692
            # Update item location
1693
            $item_object->update_item_location( 'checkout' );
1694
1692
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1695
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1693
                UpdateTotalIssues( $item_object->biblionumber, 1, undef, { skip_holds_queue => 1 } );
1696
                UpdateTotalIssues( $item_object->biblionumber, 1, undef, { skip_holds_queue => 1 } );
1694
            }
1697
            }
Lines 2143-2211 sub AddReturn { Link Here
2143
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
2146
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
2144
    my $patron_unblessed = $patron ? $patron->unblessed : {};
2147
    my $patron_unblessed = $patron ? $patron->unblessed : {};
2145
2148
2146
    my $update_loc_rules = C4::Context->yaml_preference('UpdateItemLocationOnCheckin');
2149
    # Update item location
2147
    if ($update_loc_rules) {
2150
    my $loc_messages = $item->update_item_location( 'checkin' );
2148
        if ( defined $update_loc_rules->{_ALL_} ) {
2151
    foreach my $loc_msg_key ( keys %$loc_messages ) {
2149
            if ( $update_loc_rules->{_ALL_} eq '_PERM_' ) {
2152
        $messages->{ $loc_msg_key } = $loc_messages->{ $loc_msg_key };
2150
                $update_loc_rules->{_ALL_} = $item->permanent_location;
2151
            }
2152
            if ( $update_loc_rules->{_ALL_} eq '_BLANK_' ) {
2153
                $update_loc_rules->{_ALL_} = '';
2154
            }
2155
            if (
2156
                (
2157
                    defined $item->location
2158
                    && $item->location ne $update_loc_rules->{_ALL_}
2159
                )
2160
                || ( !defined $item->location
2161
                    && $update_loc_rules->{_ALL_} ne "" )
2162
              )
2163
            {
2164
                $messages->{'ItemLocationUpdated'} =
2165
                  { from => $item->location, to => $update_loc_rules->{_ALL_} };
2166
                $item->location( $update_loc_rules->{_ALL_} )->store(
2167
                    {
2168
                        log_action        => 0,
2169
                        skip_record_index => 1,
2170
                        skip_holds_queue  => 1
2171
                    }
2172
                );
2173
            }
2174
        }
2175
        else {
2176
            foreach my $key ( keys %$update_loc_rules ) {
2177
                if ( $update_loc_rules->{$key} eq '_PERM_' ) {
2178
                    $update_loc_rules->{$key} = $item->permanent_location;
2179
                }
2180
                elsif ( $update_loc_rules->{$key} eq '_BLANK_' ) {
2181
                    $update_loc_rules->{$key} = '';
2182
                }
2183
                if (
2184
                    (
2185
                           defined $item->location
2186
                        && $item->location eq $key
2187
                        && $item->location ne $update_loc_rules->{$key}
2188
                    )
2189
                    || (   $key eq '_BLANK_'
2190
                        && ( !defined $item->location || $item->location eq '' )
2191
                        && $update_loc_rules->{$key} ne '' )
2192
                  )
2193
                {
2194
                    $messages->{'ItemLocationUpdated'} = {
2195
                        from => $item->location,
2196
                        to   => $update_loc_rules->{$key}
2197
                    };
2198
                    $item->location( $update_loc_rules->{$key} )->store(
2199
                        {
2200
                            log_action        => 0,
2201
                            skip_record_index => 1,
2202
                            skip_holds_queue  => 1
2203
                        }
2204
                    );
2205
                    last;
2206
                }
2207
            }
2208
        }
2209
    }
2153
    }
2210
2154
2211
    my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin');
2155
    my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin');
(-)a/Koha/Item.pm (+84 lines)
Lines 2128-2133 sub strings_map { Link Here
2128
    return $strings;
2128
    return $strings;
2129
}
2129
}
2130
2130
2131
=head3 update_item_location
2132
2133
    $item->update_item_location( $action );
2134
2135
Update the item location on checkin or checkout.
2136
2137
=cut
2138
2139
sub update_item_location {
2140
    my ( $self, $action ) = @_;
2141
2142
    my ($update_loc_rules, $messages);
2143
    if ( $action eq 'checkin' ) {
2144
        $update_loc_rules = C4::Context->yaml_preference('UpdateItemLocationOnCheckin');
2145
    } else {
2146
        $update_loc_rules = C4::Context->yaml_preference('UpdateItemLocationOnCheckout');
2147
    }
2148
2149
    if ($update_loc_rules) {
2150
        if ( defined $update_loc_rules->{_ALL_} ) {
2151
            if ( $update_loc_rules->{_ALL_} eq '_PERM_' ) {
2152
                $update_loc_rules->{_ALL_} = $self->permanent_location;
2153
            }
2154
            if ( $update_loc_rules->{_ALL_} eq '_BLANK_' ) {
2155
                $update_loc_rules->{_ALL_} = '';
2156
            }
2157
            if (
2158
                (
2159
                    defined $self->location
2160
                    && $self->location ne $update_loc_rules->{_ALL_}
2161
                )
2162
                || ( !defined $self->location
2163
                    && $update_loc_rules->{_ALL_} ne "" )
2164
              )
2165
            {
2166
                $messages->{'ItemLocationUpdated'} =
2167
                  { from => $self->location, to => $update_loc_rules->{_ALL_} };
2168
                $self->location( $update_loc_rules->{_ALL_} )->store(
2169
                    {
2170
                        log_action        => 0,
2171
                        skip_record_index => 1,
2172
                        skip_holds_queue  => 1
2173
                    }
2174
                );
2175
            }
2176
        }
2177
        else {
2178
            foreach my $key ( keys %$update_loc_rules ) {
2179
                if ( $update_loc_rules->{$key} eq '_PERM_' ) {
2180
                    $update_loc_rules->{$key} = $self->permanent_location;
2181
                }
2182
                elsif ( $update_loc_rules->{$key} eq '_BLANK_' ) {
2183
                    $update_loc_rules->{$key} = '';
2184
                }
2185
                if (
2186
                    (
2187
                           defined $self->location
2188
                        && $self->location eq $key
2189
                        && $self->location ne $update_loc_rules->{$key}
2190
                    )
2191
                    || (   $key eq '_BLANK_'
2192
                        && ( !defined $self->location || $self->location eq '' )
2193
                        && $update_loc_rules->{$key} ne '' )
2194
                  )
2195
                {
2196
                    $messages->{'ItemLocationUpdated'} = {
2197
                        from => $self->location,
2198
                        to   => $update_loc_rules->{$key}
2199
                    };
2200
                    $self->location( $update_loc_rules->{$key} )->store(
2201
                        {
2202
                            log_action        => 0,
2203
                            skip_record_index => 1,
2204
                            skip_holds_queue  => 1
2205
                        }
2206
                    );
2207
                    last;
2208
                }
2209
            }
2210
        }
2211
    }
2212
    return $messages;
2213
}
2214
2131
=head3 _type
2215
=head3 _type
2132
2216
2133
=cut
2217
=cut
(-)a/t/db_dependent/Circulation/issue.t (-17 / +63 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 52;
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 586-619 AddRenewal( Link Here
586
my ( $unseen_reset ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
586
my ( $unseen_reset ) = ( C4::Circulation::GetRenewCount( $unseen_patron->borrowernumber, $unseen_item->itemnumber ) )[3];
587
is( $unseen_reset, 0, 'seen renewal resets the unseen count' );
587
is( $unseen_reset, 0, 'seen renewal resets the unseen count' );
588
588
589
# Bug 21159 - Update item shelving location on checkout
589
my $itemnumber4 = Koha::Item->new(
590
my $itemnumber4 = Koha::Item->new(
590
    {
591
    {
591
        biblionumber   => $biblionumber,
592
        biblionumber   => $biblionumber,
592
        barcode        => 'barcode_6',
593
        barcode        => 'barcode_6',
593
        itemcallnumber => 'callnumber6',
594
        itemcallnumber => 'callnumber3',
594
        homebranch     => $branchcode_1,
595
        homebranch     => $branchcode_1,
595
        holdingbranch  => $branchcode_1,
596
        holdingbranch  => $branchcode_1,
596
        notforloan     => -1,
597
        location       => 'FIC',
597
        itype          => $itemtype,
598
        itype          => $itemtype
598
        location       => 'loc1'
599
    },
599
    },
600
)->store->itemnumber;
600
)->store->itemnumber;
601
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', q{} );
602
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', q{} );
603
AddIssue( $borrower_1, 'barcode_6');
604
my $item4 = Koha::Items->find( $itemnumber4 );
605
ok( $item4->location eq 'FIC', 'UpdateItemLocationOnCheckout does not modify value when not enabled' );
601
606
602
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckout', q{} );
607
#---
603
AddIssue( $borrower_2, 'barcode_6', dt_from_string );
608
AddReturn( 'barcode_6', $branchcode_1 );
604
$item = Koha::Items->find( $itemnumber4 );
609
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', 'FIC: GEN' );
605
ok( $item->notforloan eq -1, 'UpdateNotForLoanStatusOnCheckout does not modify value when not enabled' );
610
$log_count_before = $schema->resultset('ActionLog')->search({module => 'CATALOGUING'})->count();
611
AddIssue( $borrower_1, 'barcode_6' );
612
$item4 = Koha::Items->find( $itemnumber4 );
613
is( $item4->location, 'GEN', q{UpdateItemLocationOnCheckout updates location value from 'FIC' to 'GEN' with setting "FIC: GEN"} );
614
is( $item4->permanent_location, 'GEN', q{UpdateItemLocationOnCheckout updates permanent_location value from 'FIC' to 'GEN' with setting "FIC: GEN"} );
615
$log_count_after = $schema->resultset('ActionLog')->search({module => 'CATALOGUING'})->count();
616
is($log_count_before, $log_count_after, "Change from UpdateNotForLoanStatusOnCheckout is not logged");
617
AddReturn( 'barcode_6', $branchcode_1 );
618
AddIssue( $borrower_1, 'barcode_6' );
619
$item4 = Koha::Items->find( $itemnumber4 );
620
ok( $item4->location eq 'GEN', q{UpdateItemLocationOnCheckout does not update location value from 'GEN' with setting "FIC: GEN"} );
606
621
607
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckout', '-1: 0' );
622
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', '_ALL_: CART' );
608
AddReturn( 'barcode_6', $branchcode_1 );
623
AddReturn( 'barcode_6', $branchcode_1 );
609
my $test = AddIssue( $borrower_2, 'barcode_6', dt_from_string );
624
AddIssue( $borrower_1, 'barcode_6' );
610
$item = Koha::Items->find( $itemnumber4 );
625
$item4 = Koha::Items->find( $itemnumber4 );
611
ok( $item->notforloan eq 0, q{UpdateNotForLoanStatusOnCheckout updates notforloan value from -1 to 0 with setting "-1: 0"} );
626
ok( $item4->location eq 'CART', q{UpdateItemLocationOnCheckout updates location value from 'GEN' with setting "_ALL_: CART"} );
627
ok( $item4->permanent_location eq 'GEN', q{UpdateItemLocationOnCheckout does not update permanent_location value from 'GEN' with setting "_ALL_: CART"} );
612
628
613
AddIssue( $borrower_2, 'barcode_6', dt_from_string );
629
$item4->location('GEN')->store;
630
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', "GEN: _BLANK_\n_BLANK_: PROC\nPROC: _PERM_" );
631
AddReturn( 'barcode_6', $branchcode_1 );
632
AddIssue( $borrower_1, 'barcode_6' );
633
$item4 = Koha::Items->find( $itemnumber4 );
634
ok( $item4->location eq '', q{UpdateItemLocationOnCheckout updates location value from 'GEN' to '' with setting "GEN: _BLANK_"} );
614
AddReturn( 'barcode_6', $branchcode_1 );
635
AddReturn( 'barcode_6', $branchcode_1 );
615
$item = Koha::Items->find( $itemnumber4 );
636
AddIssue( $borrower_1, 'barcode_6' );
616
ok( $item->notforloan eq 0, q{UpdateNotForLoanStatusOnCheckout does not update notforloan value from 0 with setting "-1: 0"} );
637
$item4 = Koha::Items->find( $itemnumber4 );
638
ok( $item4->location eq 'PROC' , q{UpdateItemLocationOnCheckout updates location value from '' to 'PROC' with setting "_BLANK_: PROC"} );
639
ok( $item4->permanent_location eq '' , q{UpdateItemLocationOnCheckout does not update permanent_location value from '' to 'PROC' with setting "_BLANK_: PROC"} );
640
AddReturn( 'barcode_6', $branchcode_1 );
641
AddIssue( $borrower_1, 'barcode_6' );
642
$item4 = Koha::Items->find( $itemnumber4 );
643
ok( $item4->location eq '' , q{UpdateItemLocationOnCheckout updates location value from 'PROC' to '' with setting "PROC: _PERM_" } );
644
ok( $item4->permanent_location eq '' , q{UpdateItemLocationOnCheckout does not update permanent_location from '' with setting "PROC: _PERM_" } );
645
646
# Bug 28472
647
my $itemnumber5 = Koha::Item->new(
648
    {
649
        biblionumber   => $biblionumber,
650
        barcode        => 'barcode_7',
651
        itemcallnumber => 'callnumber5',
652
        homebranch     => $branchcode_1,
653
        holdingbranch  => $branchcode_1,
654
        location       => undef,
655
        itype          => $itemtype
656
    }
657
)->store->itemnumber;
658
659
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', '_ALL_: CART' );
660
AddIssue( $borrower_1, 'barcode_7' );
661
my $item5 = Koha::Items->find( $itemnumber5 );
662
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"} );
663
617
664
618
#End transaction
665
#End transaction
619
$schema->storage->txn_rollback;
666
$schema->storage->txn_rollback;
620
- 

Return to bug 21159