From 2169319c439d49a9c708e8ff4d66d820b001440a Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 14 Jun 2013 09:59:55 -0400 Subject: [PATCH] Bug 9673 - Track when items are marked as lost or withdrawn - QA Followup 3 - Clear 'on' fields when clearing statuses --- C4/Items.pm | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index a4eaa34..60e5278 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -537,14 +537,19 @@ 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() ); } } } @@ -554,6 +559,15 @@ sub ModItem { } } + # 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 -- 1.7.2.5