From fe3a91938f38b2e0b12dff6f7ca20ac9923fddc9 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 19 Jul 2017 13:10:41 +0000 Subject: [PATCH] Bug 17672: Add damaged_on to items and deleteditems tables This patchset adds a 'damaged_on' column to store the date an item is marked damaged, analogous to withdrawn_on and itemlost_on To test: 1 - Apply patch 2 - Mark an item damaged via moredetail.pl (Items tab on left in details) 3 - Note the damaged on date apears below 4 - Unmark the item, the date is removed 5 - Go to the edit items screen (from top bar 'Edit->edit items') 6 - Mark item damaged - check db or moredetails.pl to see damaged_on date 7 - Unmark item damaged - confirm date is removed 8 - prove t/db_dependent/Items.t Signed-off-by: Owen Leonard Signed-off-by: Charles Farmer Signed-off-by: Katrin Fischer --- C4/Items.pm | 4 +-- admin/columns_settings.yml | 3 +- .../bug17672_add_damaged_on_column_to_items.perl | 9 ++++++ installer/data/mysql/kohastructure.sql | 2 ++ koha-tmpl/intranet-tmpl/prog/en/columns.def | 1 + .../prog/en/modules/catalogue/moredetail.tt | 3 ++ t/db_dependent/Items.t | 37 ++++++++++++++++++++++ 7 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug17672_add_damaged_on_column_to_items.perl diff --git a/C4/Items.pm b/C4/Items.pm index d0357f68d4..a3ecd87814 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -561,10 +561,10 @@ sub ModItem { $item->{'itemnumber'} = $itemnumber or return; - my @fields = qw( itemlost withdrawn ); + my @fields = qw( itemlost withdrawn damaged ); # Only call GetItem if we need to set an "on" date field - if ( $item->{itemlost} || $item->{withdrawn} ) { + if ( $item->{itemlost} || $item->{withdrawn} || $item->{damaged} ) { my $pre_mod_item = GetItem( $item->{'itemnumber'} ); for my $field (@fields) { if ( defined( $item->{$field} ) diff --git a/admin/columns_settings.yml b/admin/columns_settings.yml index a5047e769f..f56a745eb5 100644 --- a/admin/columns_settings.yml +++ b/admin/columns_settings.yml @@ -88,7 +88,8 @@ modules: itemst: # NOTE: These columns are in the same order as kohastructure.sql, and contain all items # columns except for the following internal/obsolete fields: stack, more_subfields_xml, - # cn_sort, permanent_location, itemlost_on, withdrawn_on, issues, renewals and reserves. + # cn_sort, permanent_location, damaged_on itemlost_on, withdrawn_on, issues, renewals and + # reserves. - columnname: barcode - diff --git a/installer/data/mysql/atomicupdate/bug17672_add_damaged_on_column_to_items.perl b/installer/data/mysql/atomicupdate/bug17672_add_damaged_on_column_to_items.perl new file mode 100644 index 0000000000..7e6348a600 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug17672_add_damaged_on_column_to_items.perl @@ -0,0 +1,9 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + $dbh->do( "ALTER TABLE items ADD COLUMN damaged_on DATETIME NULL AFTER damaged"); + $dbh->do( "ALTER TABLE deleteditems ADD COLUMN damaged_on DATETIME NULL AFTER damaged"); + + # Always end with this (adjust the bug info) + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 17672: Add damaged_on to items and deleteditems tables)\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 47939514d9..0880df0e1b 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -637,6 +637,7 @@ CREATE TABLE `deleteditems` ( `stack` tinyint(1) default NULL, `notforloan` tinyint(1) NOT NULL default 0, -- authorized value defining why this item is not for loan (MARC21 952$7) `damaged` tinyint(1) NOT NULL default 0, -- authorized value defining this item as damaged (MARC21 952$4) + `damaged_on` datetime DEFAULT NULL, -- the date and time an item was last marked as damaged, NULL if not damaged `itemlost` tinyint(1) NOT NULL default 0, -- authorized value defining this item as lost (MARC21 952$1) `itemlost_on` datetime DEFAULT NULL, -- the date and time an item was last marked as lost, NULL if not lost `withdrawn` tinyint(1) NOT NULL default 0, -- authorized value defining this item as withdrawn (MARC21 952$0) @@ -897,6 +898,7 @@ CREATE TABLE `items` ( -- holdings/item information `stack` tinyint(1) default NULL, `notforloan` tinyint(1) NOT NULL default 0, -- authorized value defining why this item is not for loan (MARC21 952$7) `damaged` tinyint(1) NOT NULL default 0, -- authorized value defining this item as damaged (MARC21 952$4) + `damaged_on` datetime DEFAULT NULL, -- the date and time an item was last marked as damaged, NULL if not damaged `itemlost` tinyint(1) NOT NULL default 0, -- authorized value defining this item as lost (MARC21 952$1) `itemlost_on` datetime DEFAULT NULL, -- the date and time an item was last marked as lost, NULL if not lost `withdrawn` tinyint(1) NOT NULL default 0, -- authorized value defining this item as withdrawn (MARC21 952$0) diff --git a/koha-tmpl/intranet-tmpl/prog/en/columns.def b/koha-tmpl/intranet-tmpl/prog/en/columns.def index 8d7c174069..21c74f2017 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/columns.def +++ b/koha-tmpl/intranet-tmpl/prog/en/columns.def @@ -100,6 +100,7 @@ Koha itemtype Inventory number Damaged status +Damaged on Materials specified Uniform Resource Identifier Additional subfields (XML) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt index 501012a80e..3fb7856d59 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt @@ -152,6 +152,9 @@   [% END %] + [% IF ITEM_DAT.damaged != "" && ITEM_DAT.damaged_on %] +
  • Damaged on:[% ITEM_DAT.damaged_on | $KohaDates %]  
  • + [% END %] [% END %] [% IF itemwithdrawnloop %] diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index e10c15e225..f8ac133ec3 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -24,6 +24,7 @@ use C4::Biblio; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use Koha::Library; +use Koha::DateUtils; use t::lib::Mocks; use t::lib::TestBuilder; @@ -108,6 +109,41 @@ subtest 'General Add, Get and Del tests' => sub { $schema->storage->txn_rollback; }; +subtest 'ModItem tests' => sub { + plan tests => 6; + + $schema->storage->txn_begin; + + my $builder = t::lib::TestBuilder->new; + my $item = $builder->build({ + source => 'Item', + value => { + itemlost => 0, + damaged => 0, + withdrawn => 0, + itemlost_on => undef, + damaged_on => undef, + withdrawn_on => undef, + } + }); + + my @fields = qw( itemlost withdrawn damaged ); + for my $field (@fields) { + $item->{$field} = 1; + ModItem( $item, $item->{biblionumber}, $item->{itemnumber} ); + my $post_mod_item = Koha::Items->find({ itemnumber => $item->{itemnumber} })->unblessed; + is( output_pref({ str => $post_mod_item->{$field."_on"}, dateonly => 1 }), output_pref({ dt => dt_from_string(), dateonly => 1 }), "When updating $field, $field"."_on is updated" ); + + $item->{$field} = 0; + ModItem( $item, $item->{biblionumber}, $item->{itemnumber} ); + $post_mod_item = Koha::Items->find({ itemnumber => $item->{itemnumber} })->unblessed; + is( $post_mod_item->{$field."_on"}, undef, "When clearing $field, $field"."_on is cleared" ); + } + + $schema->storage->txn_rollback; + +}; + subtest 'GetHiddenItemnumbers tests' => sub { plan tests => 9; @@ -732,6 +768,7 @@ subtest '_mod_item_dates' => sub { # check if itemlost_on was not touched $item->{itemlost_on} = '12345678'; $item->{withdrawn_on} = '12/31/2015 23:59:00'; + $item->{damaged_on} = '01/20/2017 09:00:00'; $orgitem = { %$item }; C4::Items::_mod_item_dates($item); is_deeply( $item, $orgitem, 'Colums with _on are not touched' ); -- 2.14.1