From 8b2e57dc0a7831e99340dbbab921d9a17e3de2c4 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Mon, 13 Dec 2021 15:28:36 +0000 Subject: [PATCH] Bug 23352: Set default collection code when creating subscription The default collection code set in the subscription will be applied if item records are created when receiving the serial. Test plan: 1. Apply 3 patches 2. Run updatedatabase.pl and restart services 3. Create a subscription: - Tick the 'Create an item record when receiving this serial' radio button - Select values in the Location, Collection code and Item type dropdowns - Save the subscription 4. Confirm the Location, and Collection code default values you choose in #3 are displaying in the 'Information' tab of page that's loaded 5. Receive the serial: - Click 'Receive' - Change the status dropdown from 'Expected' to 'Arrived' - Confirm the 'Collection Code', 'Shelving location' and 'Koha item type' dropdowns are pre-filled with the values you defined in #3 6. Run unit test t/db_dependent/Serials.t Sponsored-By: Brimbank Library, Australia Signed-off-by: Samu Heiskanen --- C4/Items.pm | 12 ++++++++++++ C4/Serials.pm | 6 ++++-- .../prog/en/modules/serials/subscription-add.tt | 12 ++++++++++++ .../en/modules/serials/subscription-detail.tt | 1 + serials/subscription-add.pl | 8 ++++++-- serials/subscription-detail.pl | 2 ++ t/db_dependent/Serials.t | 15 ++++++++++++--- 7 files changed, 49 insertions(+), 7 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index ce285577bd..3fb78840ee 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1673,6 +1673,18 @@ sub PrepareItemrecordDisplay { $defaultvalue = $defaultvalues->{location}; } } + if ( ( $subfield->{kohafield} eq 'items.ccode' ) + && $defaultvalues + && $defaultvalues->{'ccode'} ) { + + if ( $itemrecord and $defaultvalues and not $itemrecord->subfield($tag,$subfield->{subfield}) ) { + # if the item record exists, only use default value if the item has no ccode + $defaultvalue = $defaultvalues->{ccode}; + } elsif ( !$itemrecord and $defaultvalues ) { + # if the item record *doesn't* exists, always use the default value + $defaultvalue = $defaultvalues->{ccode}; + } + } if ( $subfield->{authorised_value} ) { my @authorised_values; my %authorised_lib; diff --git a/C4/Serials.pm b/C4/Serials.pm index d840bf24b7..d3b81673e2 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1318,7 +1318,7 @@ sub ModSubscription { $biblionumber, $callnumber, $notes, $letter, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq, - $itemtype, $previousitemtype, $mana_id + $itemtype, $previousitemtype, $mana_id, $ccode ) = @_; my $subscription = Koha::Subscriptions->find($subscriptionid); @@ -1361,6 +1361,7 @@ sub ModSubscription { itemtype => $itemtype, previousitemtype => $previousitemtype, mana_id => $mana_id, + ccode => $ccode, } )->store; # FIXME Must be $subscription->serials @@ -1398,7 +1399,7 @@ sub NewSubscription { $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, - $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id + $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode ) = @_; my $dbh = C4::Context->dbh; @@ -1441,6 +1442,7 @@ sub NewSubscription { itemtype => $itemtype, previousitemtype => $previousitemtype, mana_id => $mana_id, + ccode => $ccode } )->store; $subscription->discard_changes; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt index 6c22b7cdd1..bd739325f9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt @@ -199,6 +199,18 @@ fieldset.rows table { clear: none; margin: 0; } [% END %] +
  • + + +