From 1393088acb97d24421f5b2c8476c256c91bf0e64 Mon Sep 17 00:00:00 2001 From: Joy Nelson Date: Tue, 19 May 2020 23:46:46 +0000 Subject: [PATCH] Revert "Bug 23727: Editing course reserve items is broken" This reverts commit 07eefd07b635cc50b5210bccf5c56e283db63680. --- C4/CourseReserves.pm | 172 +++++++++--------- Koha/Course/Instructors.pm | 2 +- Koha/Course/Item.pm | 36 ---- Koha/Course/Items.pm | 2 +- Koha/Course/Reserves.pm | 2 +- course_reserves/add_items.pl | 32 +--- course_reserves/batch_add_items.pl | 19 +- .../course_reserves/add_items-step2.tt | 91 ++------- .../course_reserves/batch_add_items.tt | 41 +---- .../modules/course_reserves/course-details.tt | 24 ++- t/db_dependent/CourseReserves/CourseItems.t | 101 ++++------ 11 files changed, 178 insertions(+), 344 deletions(-) diff --git a/C4/CourseReserves.pm b/C4/CourseReserves.pm index 9146e7e9be..2c130af192 100644 --- a/C4/CourseReserves.pm +++ b/C4/CourseReserves.pm @@ -23,11 +23,6 @@ use C4::Context; use C4::Items qw(ModItem); use C4::Circulation qw(GetOpenIssue); -use Koha::Courses; -use Koha::Course::Instructors; -use Koha::Course::Items; -use Koha::Course::Reserves; - use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG @FIELDS); BEGIN { @@ -84,17 +79,19 @@ sub GetCourse { my ($course_id) = @_; warn whoami() . "( $course_id )" if $DEBUG; - my $course = Koha::Courses->find( $course_id ); - return undef unless $course; - $course = $course->unblessed; + my $query = "SELECT * FROM courses WHERE course_id = ?"; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare($query); + $sth->execute($course_id); - my $dbh = C4::Context->dbh; - my $query = " + my $course = $sth->fetchrow_hashref(); + + $query = " SELECT b.* FROM course_instructors ci LEFT JOIN borrowers b ON ( ci.borrowernumber = b.borrowernumber ) WHERE course_id = ? "; - my $sth = $dbh->prepare($query); + $sth = $dbh->prepare($query); $sth->execute($course_id); $course->{'instructors'} = $sth->fetchall_arrayref( {} ); @@ -308,7 +305,7 @@ sub EnableOrDisableCourseItem { ## or disable and already disabled item, ## as that would cause the fields to swap if ( $course_item->{'enabled'} ne $enabled ) { - _SwapAllFields($ci_id, $enabled ); + _SwapAllFields($ci_id); my $query = " UPDATE course_items @@ -496,20 +493,23 @@ sub _AddCourseItem { my (%params) = @_; warn identify_myself(%params) if $DEBUG; - $params{holdingbranch} ||= undef; # Can't be empty string, FK constraint + my ( @fields, @values ); - my %data = map { $_ => $params{$_} } @FIELDS; - my %enabled = map { $_ . "_enabled" => $params{ $_ . "_enabled" } } @FIELDS; + push( @fields, 'itemnumber = ?' ); + push( @values, $params{'itemnumber'} ); - my $ci = Koha::Course::Item->new( - { - itemnumber => $params{itemnumber}, - %data, - %enabled, - } - )->store(); + foreach (@FIELDS) { + push( @fields, "$_ = ?" ); + push( @values, $params{$_} || undef ); + } + + my $query = "INSERT INTO course_items SET " . join( ',', @fields ); + my $dbh = C4::Context->dbh; + $dbh->do( $query, undef, @values ); + + my $ci_id = $dbh->last_insert_id( undef, undef, 'course_items', 'ci_id' ); - return $ci->id; + return $ci_id; } =head2 _UpdateCourseItem @@ -525,34 +525,57 @@ sub _UpdateCourseItem { my $ci_id = $params{'ci_id'}; my $course_item = $params{'course_item'}; - $params{holdingbranch} ||= undef; # Can't be empty string, FK constraint - return unless ( $ci_id || $course_item ); - $course_item = Koha::Course::Items->find( $ci_id || $course_item->{ci_id} ); + $course_item = GetCourseItem( ci_id => $ci_id ) + unless ($course_item); + $ci_id = $course_item->{'ci_id'} unless ($ci_id); + + my %mod_params = + map { + defined $params{$_} && $params{$_} ne '' + ? ( $_ => $params{$_} ) + : () + } @FIELDS; + + ModItem( \%mod_params, undef, $course_item->{'itemnumber'} ); +} + +=head2 _ModStoredFields + + _ModStoredFields( %params ); + + Updates the values for the 'original' fields in course_items + for a given ci_id + +=cut + +sub _ModStoredFields { + my (%params) = @_; + warn identify_myself(%params) if $DEBUG; - my %data = map { $_ => $params{$_} } @FIELDS; - my %enabled = map { $_ . "_enabled" => $params{ $_ . "_enabled" } } @FIELDS; + return unless ( $params{'ci_id'} ); - $course_item->update( { %data, %enabled } ); - if ( $course_item->is_enabled ) { - my $item_fields = {}; - $item_fields->{itype} = $course_item->itype if $course_item->itype_enabled; - $item_fields->{ccode} = $course_item->ccode if $course_item->ccode_enabled; - $item_fields->{location} = $course_item->location if $course_item->location_enabled; - $item_fields->{holdingbranch} = $course_item->holdingbranch if $course_item->holdingbranch_enabled; + my ( @fields_to_update, @values_to_update ); - ModItem( $item_fields, undef, $course_item->itemnumber ) if keys %$item_fields; + foreach (@FIELDS) { + if ( defined($params{$_}) ) { + push( @fields_to_update, $_ ); + push( @values_to_update, $params{$_} ); + } } + my $query = "UPDATE course_items SET " . join( ',', map { "$_=?" } @fields_to_update ) . " WHERE ci_id = ?"; + + C4::Context->dbh->do( $query, undef, @values_to_update, $params{'ci_id'} ) + if (@values_to_update); + } =head2 _RevertFields _RevertFields( ci_id => $ci_id, fields => \@fields_to_revert ); - Copies fields from course item storage back to the actual item - =cut sub _RevertFields { @@ -561,23 +584,17 @@ sub _RevertFields { my $ci_id = $params{'ci_id'}; - return unless $ci_id; - - my $course_item = Koha::Course::Items->find( $ci_id ); + return unless ($ci_id); - my $item_fields = {}; - $item_fields->{itype} = $course_item->itype_storage if $course_item->itype_enabled; - $item_fields->{ccode} = $course_item->ccode_storage if $course_item->ccode_enabled; - $item_fields->{location} = $course_item->location_storage if $course_item->location_enabled; - $item_fields->{holdingbranch} = $course_item->holdingbranch_storage if $course_item->holdingbranch_enabled; + my $course_item = GetCourseItem( ci_id => $params{'ci_id'} ); - ModItem( $item_fields, undef, $course_item->itemnumber ) if keys %$item_fields; + my $mod_item_params; + foreach my $field ( @FIELDS ) { + next unless defined $course_item->{$field}; + $mod_item_params->{$field} = $course_item->{$field}; + } - $course_item->itype_storage(undef); - $course_item->ccode_storage(undef); - $course_item->location_storage(undef); - $course_item->holdingbranch_storage(undef); - $course_item->store(); + ModItem( $mod_item_params, undef, $course_item->{'itemnumber'} ) if $mod_item_params && %$mod_item_params; } =head2 _SwapAllFields @@ -587,41 +604,23 @@ sub _RevertFields { =cut sub _SwapAllFields { - my ( $ci_id, $enabled ) = @_; + my ($ci_id) = @_; warn "C4::CourseReserves::_SwapFields( $ci_id )" if $DEBUG; - my $course_item = Koha::Course::Items->find( $ci_id ); - my $item = Koha::Items->find( $course_item->itemnumber ); - - if ( $enabled eq 'yes' ) { # Copy item fields to course item storage, course item fields to item - $course_item->itype_storage( $item->effective_itemtype ) if $course_item->itype_enabled; - $course_item->ccode_storage( $item->ccode ) if $course_item->ccode_enabled; - $course_item->location_storage( $item->location ) if $course_item->location_enabled; - $course_item->holdingbranch_storage( $item->holdingbranch ) if $course_item->holdingbranch_enabled; - $course_item->store(); - - my $item_fields = {}; - $item_fields->{itype} = $course_item->itype if $course_item->itype_enabled; - $item_fields->{ccode} = $course_item->ccode if $course_item->ccode_enabled; - $item_fields->{location} = $course_item->location if $course_item->location_enabled; - $item_fields->{holdingbranch} = $course_item->holdingbranch if $course_item->holdingbranch_enabled; - - ModItem( $item_fields, undef, $course_item->itemnumber ) if keys %$item_fields; - } else { # Copy course item storage to item - my $item_fields = {}; - $item_fields->{itype} = $course_item->itype_storage if $course_item->itype_enabled; - $item_fields->{ccode} = $course_item->ccode_storage if $course_item->ccode_enabled; - $item_fields->{location} = $course_item->location_storage if $course_item->location_enabled; - $item_fields->{holdingbranch} = $course_item->holdingbranch_storage if $course_item->holdingbranch_enabled; - - ModItem( $item_fields, undef, $course_item->itemnumber ) if keys %$item_fields; - - $course_item->itype_storage(undef); - $course_item->ccode_storage(undef); - $course_item->location_storage(undef); - $course_item->holdingbranch_storage(undef); - $course_item->store(); + my $course_item = GetCourseItem( ci_id => $ci_id ); + my $item = Koha::Items->find($course_item->{'itemnumber'}); + + my %course_item_fields; + my %item_fields; + foreach (@FIELDS) { + if ( defined( $course_item->{$_} ) ) { + $course_item_fields{$_} = $course_item->{$_}; + $item_fields{$_} = $item->$_ || q{}; + } } + + ModItem( \%course_item_fields, undef, $course_item->{'itemnumber'} ) if %course_item_fields; + _ModStoredFields( %item_fields, ci_id => $ci_id ); } =head2 GetCourseItems { @@ -678,10 +677,9 @@ sub DelCourseItem { my $ci_id = $params{'ci_id'}; - my $course_item = Koha::Course::Items->find( $ci_id ); - return unless $course_item; + return unless ($ci_id); - _RevertFields( ci_id => $ci_id ) if $course_item->enabled eq 'yes'; + _RevertFields( ci_id => $ci_id ); my $query = " DELETE FROM course_items diff --git a/Koha/Course/Instructors.pm b/Koha/Course/Instructors.pm index 68211eb793..418ec4f717 100644 --- a/Koha/Course/Instructors.pm +++ b/Koha/Course/Instructors.pm @@ -19,7 +19,7 @@ use Modern::Perl; use Carp; -use Koha::Course::Instructor; +use Koha::Course; use base qw(Koha::Objects); diff --git a/Koha/Course/Item.pm b/Koha/Course/Item.pm index 948a90c84b..7f9cd917d6 100644 --- a/Koha/Course/Item.pm +++ b/Koha/Course/Item.pm @@ -21,48 +21,12 @@ use Carp; use base qw(Koha::Object); -use Koha::Course::Reserves; - =head1 NAME Koha::Course::Item - Koha Course Item Object class =head1 API -=head2 Methods - -=head3 is_enabled - -=cut - -sub is_enabled { - my ( $self ) = @_; - - return $self->enabled eq 'yes'; -} - -=head3 course_reserves - -=cut - -sub course_reserves { - my ($self) = @_; - - my $rs = $self->_result->course_reserves; - return Koha::Course::Reserves->_new_from_dbic( $rs ); -} - -=head3 item - -=cut - -sub item { - my ($self) = @_; - - my $rs = $self->_result->itemnumber; - return Koha::Item->_new_from_dbic( $rs ); -} - =head2 Internal methods =cut diff --git a/Koha/Course/Items.pm b/Koha/Course/Items.pm index 7fc713dee1..efd06084b9 100644 --- a/Koha/Course/Items.pm +++ b/Koha/Course/Items.pm @@ -19,7 +19,7 @@ use Modern::Perl; use Carp; -use Koha::Course::Item; +use Koha::Course; use base qw(Koha::Objects); diff --git a/Koha/Course/Reserves.pm b/Koha/Course/Reserves.pm index 631ba49a93..c23a7a95ee 100644 --- a/Koha/Course/Reserves.pm +++ b/Koha/Course/Reserves.pm @@ -19,7 +19,7 @@ use Modern::Perl; use Carp; -use Koha::Course::Reserve; +use Koha::Course; use base qw(Koha::Objects); diff --git a/course_reserves/add_items.pl b/course_reserves/add_items.pl index 2a7a1e85d5..0819e4787f 100755 --- a/course_reserves/add_items.pl +++ b/course_reserves/add_items.pl @@ -39,14 +39,12 @@ my $action = $cgi->param('action') || ''; my $course_id = $cgi->param('course_id') || ''; my $barcode = $cgi->param('barcode') || ''; my $return = $cgi->param('return') || ''; -my $itemnumber = $cgi->param('itemnumber') || ''; +my $itemnumber = ($cgi->param('itemnumber') && $action eq 'lookup') ? $cgi->param('itemnumber') : ''; my $is_edit = $cgi->param('is_edit') || ''; $barcode =~ s/^\s*|\s*$//g; #remove leading/trailing whitespace my $item = Koha::Items->find( { ( $itemnumber ? ( itemnumber => $itemnumber ) : ( barcode => $barcode ) ) } ); -$itemnumber = $item->id if $item; - my $title = ($item) ? $item->biblio->title : undef; my $step = ( $action eq 'lookup' && $item ) ? '2' : '1'; @@ -69,12 +67,12 @@ if ( !$item && $action eq 'lookup' ){ $template->param( course => GetCourse($course_id) ); if ( $action eq 'lookup' and $item ) { - my $course_item = Koha::Course::Items->find({ itemnumber => $item->id }); + my $course_item = GetCourseItem( itemnumber => $item->itemnumber ); my $course_reserve = ($course_item) ? GetCourseReserve( course_id => $course_id, - ci_id => $course_item->ci_id, + ci_id => $course_item->{'ci_id'} ) : undef; @@ -93,26 +91,12 @@ if ( $action eq 'lookup' and $item ) { ); } elsif ( $action eq 'add' ) { - my $itype = scalar $cgi->param('itype'); - my $ccode = scalar $cgi->param('ccode'); - my $holdingbranch = scalar $cgi->param('holdingbranch'); - my $location = scalar $cgi->param('location'); - - my $itype_enabled = scalar $cgi->param('itype_enabled') ? 1 : 0; - my $ccode_enabled = scalar $cgi->param('ccode_enabled') ? 1 : 0; - my $holdingbranch_enabled = scalar $cgi->param('holdingbranch_enabled') ? 1 : 0; - my $location_enabled = scalar $cgi->param('location_enabled') ? 1 : 0; - my $ci_id = ModCourseItem( - itemnumber => $itemnumber, - itype => $itype, - ccode => $ccode, - holdingbranch => $holdingbranch, - location => $location, - itype_enabled => $itype_enabled, - ccode_enabled => $ccode_enabled, - holdingbranch_enabled => $holdingbranch_enabled, - location_enabled => $location_enabled, + itemnumber => scalar $cgi->param('itemnumber'), + itype => scalar $cgi->param('itype'), + ccode => scalar $cgi->param('ccode'), + holdingbranch => scalar $cgi->param('holdingbranch'), + location => scalar $cgi->param('location'), ); my $cr_id = ModCourseReserve( diff --git a/course_reserves/batch_add_items.pl b/course_reserves/batch_add_items.pl index 2a924b6f35..76d0caa0b5 100755 --- a/course_reserves/batch_add_items.pl +++ b/course_reserves/batch_add_items.pl @@ -42,11 +42,6 @@ my $location = $cgi->param('location'); my $staff_note = $cgi->param('staff_note'); my $public_note = $cgi->param('public_note'); -my $itype_enabled = scalar $cgi->param('itype_enabled') ? 1 : 0; -my $ccode_enabled = scalar $cgi->param('ccode_enabled') ? 1 : 0; -my $holdingbranch_enabled = scalar $cgi->param('holdingbranch_enabled') ? 1 : 0; -my $location_enabled = scalar $cgi->param('location_enabled') ? 1 : 0; - my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "course_reserves/batch_add_items.tt", @@ -83,15 +78,11 @@ if ( $course_id && $course ) { foreach my $item (@items) { my $ci_id = ModCourseItem( - itemnumber => $item->id, - itype => $itype, - ccode => $ccode, - holdingbranch => $holdingbranch, - location => $location, - itype_enabled => $itype_enabled, - ccode_enabled => $ccode_enabled, - holdingbranch_enabled => $holdingbranch_enabled, - location_enabled => $location_enabled, + itemnumber => $item->id, + itype => $itype, + ccode => $ccode, + holdingbranch => $holdingbranch, + location => $location, ); my $cr_id = ModCourseReserve( diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/add_items-step2.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/add_items-step2.tt index 2e3fb93c86..061821d708 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/add_items-step2.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/add_items-step2.tt @@ -1,5 +1,4 @@ [% USE Branches %] -[% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Course reserves ›[% IF is_edit || course_reserve %] Edit item[% ELSE %] Add items[% END %] [% INCLUDE 'doc-head-close.inc' %] @@ -17,7 +16,7 @@
[% IF course_reserve && !is_edit%]
This course already has this item on reserve.
[% END %] - [% IF course_item %]
Number of courses reserving this item: [% course_item.course_reserves.count | html %]
[% END %] + [% IF course_item %]
Number of courses reserving this item: [% course_item.course_reserves.size | html %]
[% END %]
@@ -40,22 +39,11 @@ [% IF item_level_itypes %]
  • + - [% ELSE %] - - [% END %] - - [% IF course_item.itype_enabled %] - - [% END %] - - [% FOREACH it IN itypes %] - [% IF it.itemtype == course_item.itype %] + [% IF course_item.itype.defined && ( ( course.enabled == 'yes' && it.itemtype == item.itype ) || ( course.enabled == 'no' && it.itemtype == course_item.itype ) ) %] [% ELSE %] @@ -66,23 +54,12 @@ [% END %]
  • - - - [% IF course_item.ccode_enabled %] - - [% ELSE %] - - [% END %] + + - [% ELSE %] - + - [% IF course_item.location_enabled %] - - [% ELSE %] - - [% END %] - - [% IF course_item.location_enabled %] - - [% END %] - - [% FOREACH s IN locations %] - [% IF s.authorised_value == course_item.location %] + [% IF course_item.location.defined && ( ( course.enabled == 'yes' && s.authorised_value == item.location ) || ( course.enabled == 'no' && s.authorised_value == course_item.location ) ) %] [% ELSE %] @@ -119,22 +85,10 @@
  • - - [% IF course_item.holdingbranch_enabled %] - - [% ELSE %] - - [% END %] - - [% IF course_item.holdingbranch_enabled %] - - [% END %] - - + - + [% FOREACH it IN ItemTypes.Get() %] @@ -49,10 +46,9 @@ [% END %]
  • - - - + [% FOREACH c IN AuthorisedValues.Get('CCODE') %] [% END %] @@ -61,9 +57,8 @@
  • - - + [% FOREACH s IN AuthorisedValues.Get('LOC') %] [% END %] @@ -72,9 +67,8 @@
  • - - + [% FOREACH b IN Branches.all() %] [% END %] @@ -138,21 +132,4 @@
  • -[% MACRO jsinclude BLOCK %] - -[% END %] - [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt index d9b2ceb302..5b45fc9b5f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt @@ -101,13 +101,17 @@ [% cr.item.itemcallnumber | html %] [% IF item_level_itypes %] - [% IF cr.course_item.itype_enabled %] + [% IF cr.course_item.itype.defined %] [% IF cr.course_item.enabled == 'yes' %] - [% ItemTypes.GetDescription( cr.item.effective_itemtype ) | html %] - ([% ItemTypes.GetDescription( cr.course_item.itype_storage ) | html %]) + [% ItemTypes.GetDescription( cr.item.itype) | html %] + [% IF cr.item.itype %] + ([% ItemTypes.GetDescription( cr.course_item.itype ) | html %]) + [% END %] [% ELSE %] [% ItemTypes.GetDescription( cr.course_item.itype ) | html %] - ([% ItemTypes.GetDescription( cr.item.effective_itemtype) | html %]) + [% IF cr.item.itype %] + ([% ItemTypes.GetDescription( cr.item.itype) | html %]) + [% END %] [% END %] [% ELSE %] Unchanged @@ -118,11 +122,11 @@ [% END %] - [% IF cr.course_item.ccode_enabled %] + [% IF cr.course_item.ccode.defined %] [% IF cr.course_item.enabled == 'yes' %] [% AuthorisedValues.GetByCode( 'CCODE', cr.item.ccode ) | html %] [% IF cr.item.ccode %] - ([% AuthorisedValues.GetByCode( 'CCODE', cr.course_item.ccode_storage ) | html %]) + ([% AuthorisedValues.GetByCode( 'CCODE', cr.course_item.ccode ) | html %]) [% END %] [% ELSE %] [% AuthorisedValues.GetByCode( 'CCODE', cr.course_item.ccode ) | html %] @@ -138,11 +142,11 @@ [% END %] - [% IF cr.course_item.location_enabled %] + [% IF cr.course_item.location.defined %] [% IF cr.course_item.enabled == 'yes' %] [% AuthorisedValues.GetByCode( 'LOC', cr.item.permanent_location ) | html %] [% IF cr.item.permanent_location %] - ([% AuthorisedValues.GetByCode( 'LOC', cr.course_item.location_storage ) | html %]) + ([% AuthorisedValues.GetByCode( 'LOC', cr.course_item.location ) | html %]) [% END %] [% ELSE %] [% AuthorisedValues.GetByCode( 'LOC', cr.course_item.location ) | html %] @@ -158,11 +162,11 @@ [% END %] - [% IF cr.course_item.holdingbranch_enabled %] + [% IF cr.course_item.holdingbranch.defined %] [% IF cr.course_item.enabled == 'yes' %] [% Branches.GetName( cr.item.holdingbranch ) | html %] [% IF cr.item.holdingbranch %] - ([% Branches.GetName( cr.course_item.holdingbranch_storage ) | html %]) + ([% Branches.GetName( cr.course_item.holdingbranch ) | html %]) [% END %] [% ELSE %] [% Branches.GetName( cr.course_item.holdingbranch ) | html %] diff --git a/t/db_dependent/CourseReserves/CourseItems.t b/t/db_dependent/CourseReserves/CourseItems.t index fe375b424f..c5ce9652ff 100644 --- a/t/db_dependent/CourseReserves/CourseItems.t +++ b/t/db_dependent/CourseReserves/CourseItems.t @@ -38,22 +38,17 @@ create_dependent_objects(); my ($biblionumber, $itemnumber) = create_bib_and_item(); my $ci_id = ModCourseItem( - itemnumber => $itemnumber, - itype_enabled => 1, - ccode_enabled => 1, - holdingbranch_enabled => 1, - location_enabled => 1, - itype => 'BK_foo', - ccode => 'BOOK', - holdingbranch => 'B2', - location => 'TH', + itemnumber => $itemnumber, + itype => 'BK_foo', + ccode => 'BOOK', + holdingbranch => 'B2', + location => 'TH', ); my $course = $builder->build({ source => 'CourseReserve', value => { ci_id => $ci_id, - enabled => 'no', } }); @@ -65,27 +60,23 @@ my $cr_id = ModCourseReserve( ); my $course_item = GetCourseItem( ci_id => $ci_id ); -is($course_item->{itype_storage}, 'CD_foo', 'Course item itype storage should be CD_foo'); -is($course_item->{ccode_storage}, 'CD', 'Course item ccode storage should be CD'); -is($course_item->{holdingbranch_storage}, 'B1', 'Course item holding branch storage should be B1'); -is($course_item->{location_storage}, 'HR', 'Course item location storage should be HR'); +is($course_item->{itype}, 'CD_foo', 'Course item itype should be CD_foo'); +is($course_item->{ccode}, 'CD', 'Course item ccode should be CD'); +is($course_item->{holdingbranch}, 'B1', 'Course item holding branch should be B1'); +is($course_item->{location}, 'HR', 'Course item location should be HR'); my $item = Koha::Items->find($itemnumber); -is($item->effective_itemtype, 'BK_foo', 'Item type in course should be BK_foo'); +is($item->itype, 'BK_foo', 'Item type in course should be BK_foo'); is($item->ccode, 'BOOK', 'Item ccode in course should be BOOK'); is($item->holdingbranch, 'B2', 'Item holding branch in course should be B2'); is($item->location, 'TH', 'Item location in course should be TH'); ModCourseItem( - itemnumber => $itemnumber, - itype_enabled => 1, - ccode_enabled => 1, - holdingbranch_enabled => 1, - location_enabled => 1, - itype => 'BK_foo', - ccode => 'DVD', - holdingbranch => 'B3', - location => 'TH', + itemnumber => $itemnumber, + itype => 'BK_foo', + ccode => 'DVD', + holdingbranch => 'B3', + location => 'TH', ); ModCourseReserve( @@ -96,20 +87,20 @@ ModCourseReserve( ); $course_item = GetCourseItem( ci_id => $ci_id ); -is($course_item->{itype_storage}, 'CD_foo', 'Course item itype storage should be CD_foo'); -is($course_item->{ccode_storage}, 'CD', 'Course item ccode storage should be CD'); -is($course_item->{holdingbranch_storage}, 'B1', 'Course item holding branch storage should be B1'); -is($course_item->{location_storage}, 'HR', 'Course item location storage should be HR'); +is($course_item->{itype}, 'CD_foo', 'Course item itype should be CD_foo'); +is($course_item->{ccode}, 'CD', 'Course item ccode should be CD'); +is($course_item->{holdingbranch}, 'B1', 'Course item holding branch should be B1'); +is($course_item->{location}, 'HR', 'Course item location should be HR'); $item = Koha::Items->find($itemnumber); -is($item->effective_itemtype, 'BK_foo', 'Item type in course should be BK_foo'); +is($item->itype, 'BK_foo', 'Item type in course should be BK_foo'); is($item->ccode, 'DVD', 'Item ccode in course should be DVD'); is($item->holdingbranch, 'B3', 'Item holding branch in course should be B3'); is($item->location, 'TH', 'Item location in course should be TH'); DelCourseReserve( cr_id => $cr_id ); $item = Koha::Items->find($itemnumber); -is($item->effective_itemtype, 'CD_foo', 'Item type removed from course should be set back to CD_foo'); +is($item->itype, 'CD_foo', 'Item type removed from course should be set back to CD_foo'); is($item->ccode, 'CD', 'Item ccode removed from course should be set back to CD'); is($item->holdingbranch, 'B1', 'Item holding branch removed from course should be set back B1'); is($item->location, 'HR', 'Item location removed from course should be TH'); @@ -121,15 +112,11 @@ $item = Koha::Items->find($itemnumber); is($item->ccode, '', 'Item ccode should be empty'); my $ci_id2 = ModCourseItem( - itemnumber => $itemnumber, - itype_enabled => 1, - ccode_enabled => 1, - holdingbranch_enabled => 1, - location_enabled => 1, - itype => 'CD_foo', - ccode => 'BOOK', - holdingbranch => 'B1', - location => 'HR', + itemnumber => $itemnumber, + itype => 'CD_foo', + ccode => 'BOOK', + holdingbranch => 'B1', + location => 'HR', ); my $cr_id2 = ModCourseReserve( @@ -143,18 +130,14 @@ $item = Koha::Items->find($itemnumber); is($item->ccode, 'BOOK', 'Item ccode should be BOOK'); my $course_item2 = GetCourseItem( ci_id => $ci_id2 ); -is($course_item2->{ccode_storage}, '', 'Course item ccode storage should be empty'); +is($course_item2->{ccode}, '', 'Course item ccode should be empty'); ModCourseItem( - itemnumber => $itemnumber, - itype_enabled => 1, - ccode_enabled => 1, - holdingbranch_enabled => 1, - location_enabled => 1, - itype => 'CD_foo', - ccode => 'DVD', - holdingbranch => 'B1', - location => 'HR', + itemnumber => $itemnumber, + itype => 'CD_foo', + ccode => 'DVD', + holdingbranch => 'B1', + location => 'HR', ); ModCourseReserve( @@ -168,21 +151,17 @@ $item = Koha::Items->find($itemnumber); is($item->ccode, 'DVD', 'Item ccode should be DVD'); ModCourseItem( - itemnumber => $itemnumber, - itype_enabled => 1, - ccode_enabled => 1, - holdingbranch_enabled => 0, # LEAVE UNCHANGED - location_enabled => 1, - itype => 'BK', - ccode => 'BOOK', - holdingbranch => undef, # LEAVE UNCHANGED - location => 'TH', + itemnumber => $itemnumber, + itype => 'BK', + ccode => 'BOOK', + holdingbranch => '', # LEAVE UNCHANGED + location => 'TH', ); $item = Koha::Items->find($itemnumber); is($item->ccode, 'BOOK', 'Item ccode should be BOOK'); $course_item2 = GetCourseItem( ci_id => $ci_id2 ); -is($course_item2->{ccode_storage}, '', 'Course item ccode storage should be empty'); +is($course_item2->{ccode}, '', 'Course item ccode should be empty'); DelCourseReserve( cr_id => $cr_id2 ); $item = Koha::Items->find($itemnumber); @@ -216,7 +195,7 @@ subtest 'Ensure item info is preserved' => sub { #Remove course reservei DelCourseReserve( cr_id => $course_reserve_id ); my $item_after = Koha::Items->find( $item->itemnumber ); - is( $item->effective_itemtype, $item_after->itype, "Itemtype is unchanged after adding to and removing from course reserves for inactive course"); + is( $item->itype, $item_after->itype, "Itemtype is unchanged after adding to and removing from course reserves for inactive course"); is( $item->location, $item_after->location, "Location is unchanged after adding to and removing from course reserves for inactive course"); is( $item->holdingbranch, $item_after->holdingbranch, "Holdingbranch is unchanged after adding to and removing from course reserves for inactive course"); is( $item->ccode, $item_after->ccode, "Collection is unchanged after adding to and removing from course reserves for inactive course"); @@ -246,7 +225,7 @@ subtest 'Ensure item info is preserved' => sub { #Remove course reserve DelCourseReserve( cr_id => $course_reserve_id ); $item_after = Koha::Items->find( $item->itemnumber ); - is( $item->effective_itemtype, $item_after->itype, "Itemtype is unchanged after adding to and removing from course reserves for inactive course"); + is( $item->itype, $item_after->itype, "Itemtype is unchanged after adding to and removing from course reserves for inactive course"); is( $item->location, $item_after->location, "Location is unchanged after adding to and removing from course reserves for inactive course"); is( $item->holdingbranch, $item_after->holdingbranch, "Holdingbranch is unchanged after adding to and removing from course reserves for inactive course"); is( $item->ccode, $item_after->ccode, "Collection is unchanged after adding to and removing from course reserves for inactive course"); -- 2.39.5