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

(-)a/Koha/Item.pm (-12 / +8 lines)
Lines 2171-2176 sub strings_map { Link Here
2171
    return $strings;
2171
    return $strings;
2172
}
2172
}
2173
2173
2174
2174
=head3 update_item_location
2175
=head3 update_item_location
2175
2176
2176
    $item->update_item_location( $action );
2177
    $item->update_item_location( $action );
Lines 2182-2188 Update the item location on checkin or checkout. Link Here
2182
sub update_item_location {
2183
sub update_item_location {
2183
    my ( $self, $action ) = @_;
2184
    my ( $self, $action ) = @_;
2184
2185
2185
    my ($update_loc_rules, $messages);
2186
    my ( $update_loc_rules, $messages );
2186
    if ( $action eq 'checkin' ) {
2187
    if ( $action eq 'checkin' ) {
2187
        $update_loc_rules = C4::Context->yaml_preference('UpdateItemLocationOnCheckin');
2188
        $update_loc_rules = C4::Context->yaml_preference('UpdateItemLocationOnCheckin');
2188
    } else {
2189
    } else {
Lines 2198-2213 sub update_item_location { Link Here
2198
                $update_loc_rules->{_ALL_} = '';
2199
                $update_loc_rules->{_ALL_} = '';
2199
            }
2200
            }
2200
            if (
2201
            if (
2201
                (
2202
                ( defined $self->location && $self->location ne $update_loc_rules->{_ALL_} )
2202
                    defined $self->location
2203
                    && $self->location ne $update_loc_rules->{_ALL_}
2204
                )
2205
                || ( !defined $self->location
2203
                || ( !defined $self->location
2206
                    && $update_loc_rules->{_ALL_} ne "" )
2204
                    && $update_loc_rules->{_ALL_} ne "" )
2207
              )
2205
                )
2208
            {
2206
            {
2209
                $messages->{'ItemLocationUpdated'} =
2207
                $messages->{'ItemLocationUpdated'} =
2210
                  { from => $self->location, to => $update_loc_rules->{_ALL_} };
2208
                    { from => $self->location, to => $update_loc_rules->{_ALL_} };
2211
                $self->location( $update_loc_rules->{_ALL_} )->store(
2209
                $self->location( $update_loc_rules->{_ALL_} )->store(
2212
                    {
2210
                    {
2213
                        log_action        => 0,
2211
                        log_action        => 0,
Lines 2216-2228 sub update_item_location { Link Here
2216
                    }
2214
                    }
2217
                );
2215
                );
2218
            }
2216
            }
2219
        }
2217
        } else {
2220
        else {
2221
            foreach my $key ( keys %$update_loc_rules ) {
2218
            foreach my $key ( keys %$update_loc_rules ) {
2222
                if ( $update_loc_rules->{$key} eq '_PERM_' ) {
2219
                if ( $update_loc_rules->{$key} eq '_PERM_' ) {
2223
                    $update_loc_rules->{$key} = $self->permanent_location;
2220
                    $update_loc_rules->{$key} = $self->permanent_location;
2224
                }
2221
                } elsif ( $update_loc_rules->{$key} eq '_BLANK_' ) {
2225
                elsif ( $update_loc_rules->{$key} eq '_BLANK_' ) {
2226
                    $update_loc_rules->{$key} = '';
2222
                    $update_loc_rules->{$key} = '';
2227
                }
2223
                }
2228
                if (
2224
                if (
Lines 2234-2240 sub update_item_location { Link Here
2234
                    || (   $key eq '_BLANK_'
2230
                    || (   $key eq '_BLANK_'
2235
                        && ( !defined $self->location || $self->location eq '' )
2231
                        && ( !defined $self->location || $self->location eq '' )
2236
                        && $update_loc_rules->{$key} ne '' )
2232
                        && $update_loc_rules->{$key} ne '' )
2237
                  )
2233
                    )
2238
                {
2234
                {
2239
                    $messages->{'ItemLocationUpdated'} = {
2235
                    $messages->{'ItemLocationUpdated'} = {
2240
                        from => $self->location,
2236
                        from => $self->location,
(-)a/installer/data/mysql/atomicupdate/bug_21159-add_UpdateItemLocationOnCheckout_syspref.pl (-4 / +7 lines)
Lines 1-12 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
return {
3
return {
4
    bug_number => "21159",
4
    bug_number  => "21159",
5
    description => "Add new system preference UpdateItemLocationOnCheckout",
5
    description => "Add new system preference UpdateItemLocationOnCheckout",
6
    up => sub {
6
    up          => sub {
7
        my ($args) = @_;
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
9
10
        $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('UpdateItemLocationOnCheckout', '', 'NULL', 'This is a list of value pairs.\n Examples:\n\nPROC: FIC - causes an item in the Processing Center location to be updated into the Fiction location on check out.\nFIC: GEN - causes an item in the Fiction location to be updated into the General stacks location on check out.\n_BLANK_:FIC - causes an item that has no location to be updated into the Fiction location on check out.\nFIC: _BLANK_ - causes an item in location FIC to be updated to a blank location on check out.\n_ALL_:FIC - causes all items to be updated into the Fiction location on check out.\nPROC: _PERM_ - causes an item that is in the Processing Center to be updated to it''s permanent location.\n\nGeneral rule: if the location value on the left matches the item''s current location, it will be updated to match the location value on the right.\nNote: PROC and CART are special values, for these locations only can location and permanent_location differ, in all other cases an update will affect both. Items in the CART location will be returned to their permanent location on checkout.\n\nThe special term _BLANK_ may be used on either side of a value pair to update or remove the location from items with no location assigned.\nThe special term _ALL_ is used on the left side of the colon (:) to affect all items.\nThe special term _PERM_ is used on the right side of the colon (:) to return items to their permanent location.', 'Free') });
10
        $dbh->do(
11
            q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('UpdateItemLocationOnCheckout', '', 'NULL', 'This is a list of value pairs.\n Examples:\n\nPROC: FIC - causes an item in the Processing Center location to be updated into the Fiction location on check out.\nFIC: GEN - causes an item in the Fiction location to be updated into the General stacks location on check out.\n_BLANK_:FIC - causes an item that has no location to be updated into the Fiction location on check out.\nFIC: _BLANK_ - causes an item in location FIC to be updated to a blank location on check out.\n_ALL_:FIC - causes all items to be updated into the Fiction location on check out.\nPROC: _PERM_ - causes an item that is in the Processing Center to be updated to it''s permanent location.\n\nGeneral rule: if the location value on the left matches the item''s current location, it will be updated to match the location value on the right.\nNote: PROC and CART are special values, for these locations only can location and permanent_location differ, in all other cases an update will affect both. Items in the CART location will be returned to their permanent location on checkout.\n\nThe special term _BLANK_ may be used on either side of a value pair to update or remove the location from items with no location assigned.\nThe special term _ALL_ is used on the left side of the colon (:) to affect all items.\nThe special term _PERM_ is used on the right side of the colon (:) to return items to their permanent location.', 'Free') }
12
        );
13
        say $out "Added new system preference 'UpdateItemLocationOnCheckout'";
11
    },
14
    },
12
};
15
};
(-)a/t/db_dependent/Circulation/issue.t (-26 / +60 lines)
Lines 480-485 my $itemnumber2 = Koha::Item->new( Link Here
480
    }
480
    }
481
)->store->itemnumber;
481
)->store->itemnumber;
482
482
483
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', q{} );
484
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin',  q{} );
485
483
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', q{} );
486
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', q{} );
484
AddReturn( 'barcode_4', $branchcode_1 );
487
AddReturn( 'barcode_4', $branchcode_1 );
485
my $item2 = Koha::Items->find( $itemnumber2 );
488
my $item2 = Koha::Items->find( $itemnumber2 );
Lines 655-703 my $itemnumber5 = Koha::Item->new( Link Here
655
)->store->itemnumber;
658
)->store->itemnumber;
656
659
657
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', q{} );
660
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', q{} );
658
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin', q{} );
661
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckin',  q{} );
659
AddIssue( $patron_1, 'barcode_7');
662
AddIssue( $patron_1, 'barcode_7' );
660
my $item5 = Koha::Items->find( $itemnumber5 );
663
my $item5 = Koha::Items->find($itemnumber5);
661
ok( $item5->location eq 'FIC', 'UpdateItemLocationOnCheckout does not modify value when not enabled' );
664
ok( $item5->location eq 'FIC', 'UpdateItemLocationOnCheckout does not modify value when not enabled' );
662
665
663
#---
666
#---
664
AddReturn( 'barcode_7', $branchcode_1 );
667
AddReturn( 'barcode_7', $branchcode_1 );
665
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', 'FIC: GEN' );
668
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', 'FIC: GEN' );
666
$log_count_before = $schema->resultset('ActionLog')->search({module => 'CATALOGUING'})->count();
669
$log_count_before = $schema->resultset('ActionLog')->search( { module => 'CATALOGUING' } )->count();
667
AddIssue( $patron_1, 'barcode_7' );
670
AddIssue( $patron_1, 'barcode_7' );
668
$item5 = Koha::Items->find( $itemnumber5 );
671
$item5 = Koha::Items->find($itemnumber5);
669
is( $item5->location, 'GEN', q{UpdateItemLocationOnCheckout updates location value from 'FIC' to 'GEN' with setting "FIC: GEN"} );
672
is(
670
is( $item5->permanent_location, 'GEN', q{UpdateItemLocationOnCheckout updates permanent_location value from 'FIC' to 'GEN' with setting "FIC: GEN"} );
673
    $item5->location, 'GEN',
671
$log_count_after = $schema->resultset('ActionLog')->search({module => 'CATALOGUING'})->count();
674
    q{UpdateItemLocationOnCheckout updates location value from 'FIC' to 'GEN' with setting "FIC: GEN"}
672
is($log_count_before, $log_count_after, "Change from UpdateNotForLoanStatusOnCheckout is not logged");
675
);
676
is(
677
    $item5->permanent_location, 'GEN',
678
    q{UpdateItemLocationOnCheckout updates permanent_location value from 'FIC' to 'GEN' with setting "FIC: GEN"}
679
);
680
$log_count_after = $schema->resultset('ActionLog')->search( { module => 'CATALOGUING' } )->count();
681
is( $log_count_before, $log_count_after, "Change from UpdateNotForLoanStatusOnCheckout is not logged" );
673
AddReturn( 'barcode_7', $branchcode_1 );
682
AddReturn( 'barcode_7', $branchcode_1 );
674
AddIssue( $patron_1, 'barcode_7' );
683
AddIssue( $patron_1, 'barcode_7' );
675
$item5 = Koha::Items->find( $itemnumber5 );
684
$item5 = Koha::Items->find($itemnumber5);
676
ok( $item5->location eq 'GEN', q{UpdateItemLocationOnCheckout does not update location value from 'GEN' with setting "FIC: GEN"} );
685
ok(
686
    $item5->location eq 'GEN',
687
    q{UpdateItemLocationOnCheckout does not update location value from 'GEN' with setting "FIC: GEN"}
688
);
677
689
678
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', '_ALL_: CART' );
690
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', '_ALL_: CART' );
679
AddReturn( 'barcode_7', $branchcode_1 );
691
AddReturn( 'barcode_7', $branchcode_1 );
680
AddIssue( $patron_1, 'barcode_7' );
692
AddIssue( $patron_1, 'barcode_7' );
681
$item5 = Koha::Items->find( $itemnumber5 );
693
$item5 = Koha::Items->find($itemnumber5);
682
ok( $item5->location eq 'CART', q{UpdateItemLocationOnCheckout updates location value from 'GEN' with setting "_ALL_: CART"} );
694
ok(
683
ok( $item5->permanent_location eq 'GEN', q{UpdateItemLocationOnCheckout does not update permanent_location value from 'GEN' with setting "_ALL_: CART"} );
695
    $item5->location eq 'CART',
696
    q{UpdateItemLocationOnCheckout updates location value from 'GEN' with setting "_ALL_: CART"}
697
);
698
ok(
699
    $item5->permanent_location eq 'GEN',
700
    q{UpdateItemLocationOnCheckout does not update permanent_location value from 'GEN' with setting "_ALL_: CART"}
701
);
684
702
685
$item5->location('GEN')->store;
703
$item5->location('GEN')->store;
686
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', "GEN: _BLANK_\n_BLANK_: PROC\nPROC: _PERM_" );
704
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', "GEN: _BLANK_\n_BLANK_: PROC\nPROC: _PERM_" );
687
AddReturn( 'barcode_7', $branchcode_1 );
705
AddReturn( 'barcode_7', $branchcode_1 );
688
AddIssue( $patron_1, 'barcode_7' );
706
AddIssue( $patron_1, 'barcode_7' );
689
$item5 = Koha::Items->find( $itemnumber5 );
707
$item5 = Koha::Items->find($itemnumber5);
690
ok( $item5->location eq '', q{UpdateItemLocationOnCheckout updates location value from 'GEN' to '' with setting "GEN: _BLANK_"} );
708
ok(
709
    $item5->location eq '',
710
    q{UpdateItemLocationOnCheckout updates location value from 'GEN' to '' with setting "GEN: _BLANK_"}
711
);
691
AddReturn( 'barcode_7', $branchcode_1 );
712
AddReturn( 'barcode_7', $branchcode_1 );
692
AddIssue( $patron_1, 'barcode_7' );
713
AddIssue( $patron_1, 'barcode_7' );
693
$item5 = Koha::Items->find( $itemnumber5 );
714
$item5 = Koha::Items->find($itemnumber5);
694
ok( $item5->location eq 'PROC' , q{UpdateItemLocationOnCheckout updates location value from '' to 'PROC' with setting "_BLANK_: PROC"} );
715
ok(
695
ok( $item5->permanent_location eq '' , q{UpdateItemLocationOnCheckout does not update permanent_location value from '' to 'PROC' with setting "_BLANK_: PROC"} );
716
    $item5->location eq 'PROC',
717
    q{UpdateItemLocationOnCheckout updates location value from '' to 'PROC' with setting "_BLANK_: PROC"}
718
);
719
ok(
720
    $item5->permanent_location eq '',
721
    q{UpdateItemLocationOnCheckout does not update permanent_location value from '' to 'PROC' with setting "_BLANK_: PROC"}
722
);
696
AddReturn( 'barcode_7', $branchcode_1 );
723
AddReturn( 'barcode_7', $branchcode_1 );
697
AddIssue( $patron_1, 'barcode_7' );
724
AddIssue( $patron_1, 'barcode_7' );
698
$item5 = Koha::Items->find( $itemnumber5 );
725
$item5 = Koha::Items->find($itemnumber5);
699
ok( $item5->location eq '' , q{UpdateItemLocationOnCheckout updates location value from 'PROC' to '' with setting "PROC: _PERM_" } );
726
ok(
700
ok( $item5->permanent_location eq '' , q{UpdateItemLocationOnCheckout does not update permanent_location from '' with setting "PROC: _PERM_" } );
727
    $item5->location eq '',
728
    q{UpdateItemLocationOnCheckout updates location value from 'PROC' to '' with setting "PROC: _PERM_" }
729
);
730
ok(
731
    $item5->permanent_location eq '',
732
    q{UpdateItemLocationOnCheckout does not update permanent_location from '' with setting "PROC: _PERM_" }
733
);
701
734
702
# Bug 28472
735
# Bug 28472
703
my $itemnumber6 = Koha::Item->new(
736
my $itemnumber6 = Koha::Item->new(
Lines 714-722 my $itemnumber6 = Koha::Item->new( Link Here
714
747
715
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', '_ALL_: CART' );
748
t::lib::Mocks::mock_preference( 'UpdateItemLocationOnCheckout', '_ALL_: CART' );
716
AddIssue( $patron_1, 'barcode_8' );
749
AddIssue( $patron_1, 'barcode_8' );
717
my $item6 = Koha::Items->find( $itemnumber6 );
750
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"} );
751
is(
719
752
    $item6->location, 'CART',
753
    q{UpdateItemLocationOnCheckout updates location value from NULL (i.e. the item has no shelving location set) to 'CART' with setting "_ALL_: CART"}
754
);
720
755
721
#End transaction
756
#End transaction
722
$schema->storage->txn_rollback;
757
$schema->storage->txn_rollback;
723
- 

Return to bug 21159