LP1940105: Perl detach material correctly resets item location
authorJane Sandberg <sandbergja@gmail.com>
Sat, 3 Sep 2022 00:49:55 +0000 (17:49 -0700)
committerMichele Morgan <mmorgan@noblenet.org>
Tue, 18 Oct 2022 20:51:17 +0000 (16:51 -0400)
Signed-off-by: Jane Sandberg <sandbergja@gmail.com>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>

Open-ILS/src/perlmods/lib/OpenILS/Application/Courses.pm
Open-ILS/src/perlmods/live_t/31-courses.t

index a95d667..f10c04f 100644 (file)
@@ -265,7 +265,7 @@ sub _resetItemFields {
     if ($acmcm->original_location) {
         $acp->location($acmcm->original_location);
     }
-    $e->update_asset_copy($acmcm);
+    $e->update_asset_copy($acp);
     if ($acmcm->original_callnumber) {
         my $existing_acn = $e->retrieve_asset_call_number($acp->call_number);
         my $orig_acn = $e->retrieve_asset_call_number($acmcm->original_callnumber);
index 8c3c517..eafee30 100644 (file)
@@ -1,7 +1,7 @@
 #!perl
+
 use strict; use warnings;
-use Test::More tests => 5;
+use Test::More tests => 7;
 use OpenILS::Utils::TestUtils;
 use OpenILS::Utils::CStoreEditor qw/:funcs/;
 use OpenILS::Application::AppUtils;
@@ -80,3 +80,58 @@ $results = $e->search_biblio_record_entry({tcn_source=>$temp_tcn_source,deleted=
 is(scalar(@$results), 0, 'Successfully deleted bre');
 
 
+# --------------------------------------------------------------------------
+# 3. Let's attach an existing item record entry to course #1, then detach it
+# --------------------------------------------------------------------------
+
+# Create an item with temporary location, so that we can confirm its fields revert on course material detach
+my $acp = Fieldmapper::asset::copy->new;
+my $item_id = int (rand (1_000_000) );
+my $acmcm_id = int (rand (1_000_000) );
+$acp->deleted(0);
+$acp->call_number(1);
+$acp->creator(1);
+$acp->editor(1);
+$acp->circ_lib(5);
+$acp->age_protect(1);
+$acp->barcode( $bre->id . '-1' );
+$acp->create_date('now');
+$acp->edit_date('now');
+$acp->active_date('now');
+$acp->status_changed_time('now');
+$acp->status(0);
+$acp->location(136);        # temporary value
+$acp->loan_duration(2);
+$acp->fine_level(2);
+$acp->deposit(0);
+$acp->deposit_amount(0.00);
+$acp->ref(0);
+$acp->holdable(1);
+$acp->opac_visible(1);
+$acp->mint_condition(1);
+$acp->id($item_id);
+$e->xact_begin;
+$e->create_asset_copy( $acp );
+$e->commit;
+
+$acmcm = Fieldmapper::asset::course_module_course_materials->new;
+
+$acmcm->course(1);
+$acmcm->id($acmcm_id);
+$acmcm->record(55);
+$acmcm->item($item_id);
+$acmcm->original_status(0);
+$acmcm->original_location(1);
+$acmcm->temporary_record(0);
+$e->xact_begin;
+$e->create_asset_course_module_course_materials( $acmcm ); # associated this bib record with a course
+$e->commit;
+
+$apputils->simplereq('open-ils.courses', 'open-ils.courses.detach_material', $authtoken, $acmcm_id);
+
+$results = $e->search_asset_course_module_course_materials({id => $acmcm_id});
+is(scalar(@$results), 0, 'Successfully deleted acmcm');
+
+# Re-load the acp into memory from the db
+$acp = $e->retrieve_asset_copy($item_id);
+is($acp->location, 1, "Successfully reverted item's shelving location");
\ No newline at end of file