@@ -, +, @@ --- C4/Items.pm | 21 ++++++++++++++++----- 1 files changed, 16 insertions(+), 5 deletions(-) --- a/C4/Items.pm +++ a/C4/Items.pm @@ -537,23 +537,34 @@ sub ModItem { $item->{onloan} = undef if $item->{itemlost}; + + my @fields = qw( itemlost wthdrawn ); + + # Only call GetItem if we need to set an "on" date field if ( $item->{itemlost} || $item->{wthdrawn} ) { my $pre_mod_item = GetItem( $item->{'itemnumber'} ); - for my $field (qw( itemlost wthdrawn )) { + for my $field (@fields) { if ( defined( $item->{$field} ) ) { unless ( $pre_mod_item->{$field} ) { if ( $item->{$field} ) { $item->{ $field . '_on' } = - DateTime::Format::MySQL->format_datetime( dt_from_string() ); + DateTime::Format::MySQL->format_datetime( + dt_from_string() ); } } } - else { - $item->{ $field . '_on' } = undef; - } } } + # If the field is defined but empty, we are removing and, + # and thus need to clear out the 'on' field as well + for my $field (@fields) { + if ( defined( $item->{$field} ) && !$item->{$field} ) { + $item->{ $field . '_on' } = undef; + } + } + + _set_derived_columns_for_mod($item); _do_column_fixes_for_mod($item); # FIXME add checks --