Bug 32478: (follow-up) Tidy code

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2023-05-04 18:39:50 +00:00 committed by Tomas Cohen Arazi
parent ae9163d415
commit 89bc6d0967
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -2139,24 +2139,63 @@ sub AddReturn {
my $update_loc_rules = C4::Context->yaml_preference('UpdateItemLocationOnCheckin');
if ($update_loc_rules) {
if (defined $update_loc_rules->{_ALL_}) {
if ($update_loc_rules->{_ALL_} eq '_PERM_') { $update_loc_rules->{_ALL_} = $item->permanent_location; }
if ($update_loc_rules->{_ALL_} eq '_BLANK_') { $update_loc_rules->{_ALL_} = ''; }
if ( defined $update_loc_rules->{_ALL_} ) {
if ( $update_loc_rules->{_ALL_} eq '_PERM_' ) {
$update_loc_rules->{_ALL_} = $item->permanent_location;
}
if ( $update_loc_rules->{_ALL_} eq '_BLANK_' ) {
$update_loc_rules->{_ALL_} = '';
}
if (
( defined $item->location && $item->location ne $update_loc_rules->{_ALL_}) ||
(!defined $item->location && $update_loc_rules->{_ALL_} ne "")
) {
$messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{_ALL_} };
$item->location($update_loc_rules->{_ALL_})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1});
(
defined $item->location
&& $item->location ne $update_loc_rules->{_ALL_}
)
|| ( !defined $item->location
&& $update_loc_rules->{_ALL_} ne "" )
)
{
$messages->{'ItemLocationUpdated'} =
{ from => $item->location, to => $update_loc_rules->{_ALL_} };
$item->location( $update_loc_rules->{_ALL_} )->store(
{
log_action => 0,
skip_record_index => 1,
skip_holds_queue => 1
}
);
}
}
else {
foreach my $key ( keys %$update_loc_rules ) {
if ( $update_loc_rules->{$key} eq '_PERM_' ) { $update_loc_rules->{$key} = $item->permanent_location; }
elsif ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
if ( (defined $item->location && $item->location eq $key && $item->location ne $update_loc_rules->{$key}) || ($key eq '_BLANK_' && ( !defined $item->location || $item->location eq '' ) && $update_loc_rules->{$key} ne '') ) {
$messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{$key} };
$item->location($update_loc_rules->{$key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1});
if ( $update_loc_rules->{$key} eq '_PERM_' ) {
$update_loc_rules->{$key} = $item->permanent_location;
}
elsif ( $update_loc_rules->{$key} eq '_BLANK_' ) {
$update_loc_rules->{$key} = '';
}
if (
(
defined $item->location
&& $item->location eq $key
&& $item->location ne $update_loc_rules->{$key}
)
|| ( $key eq '_BLANK_'
&& ( !defined $item->location || $item->location eq '' )
&& $update_loc_rules->{$key} ne '' )
)
{
$messages->{'ItemLocationUpdated'} = {
from => $item->location,
to => $update_loc_rules->{$key}
};
$item->location( $update_loc_rules->{$key} )->store(
{
log_action => 0,
skip_record_index => 1,
skip_holds_queue => 1
}
);
last;
}
}