From 55a810e22c584095f714a107bff07c302bf07bbb Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 21 Mar 2013 07:18:34 -0700 Subject: [PATCH] Bug 9673 - Track when items are marked as lost or withdrawn - QA Followup --- C4/Items.pm | 30 ++++++++++++++++++++++++------ 1 files changed, 24 insertions(+), 6 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index b7d6055..854620e 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -30,8 +30,10 @@ use MARC::Record; use C4::ClassSource; use C4::Log; use List::MoreUtils qw/any/; +use DateTime::Format::MySQL; use Data::Dumper; # used as part of logging item record changes, not just for # debugging; so please don't remove this +use Koha::DateUtils qw/dt_from_string/; use vars qw($VERSION @ISA @EXPORT); @@ -535,16 +537,32 @@ sub ModItem { $item->{onloan} = undef if $item->{itemlost}; - for my $field ( qw( itemlost wthdrawn ) ) { - if ( defined( $item->{$field} ) ) { - if ( $item->{$field} ) { - $item->{$field . '_on'} = DateTime::Format::MySQL->format_datetime( DateTime->now() ); - } else { - $item->{$field . '_on'} = undef; + + 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 (@fields) { + if ( defined( $item->{$field} ) + and not pre_mod_item->{$field} + and $item->{$field} ) + { + $item->{ $field . '_on' } = + DateTime::Format::MySQL->format_datetime( dt_from_string() ); } } } + # 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