From ad6d1265e03cd1dc057e363f40c044d924382230 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 Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Owen Leonard Signed-off-by: Katrin Fischer Signed-off-by: Fridolin Somers --- 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 ddd2fff096..2a84d5f3e6 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1694,6 +1694,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 4b0f84d97a..93c8a759d9 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1321,7 +1321,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); @@ -1364,6 +1364,7 @@ sub ModSubscription { itemtype => $itemtype, previousitemtype => $previousitemtype, mana_id => $mana_id, + ccode => $ccode, } )->store; # FIXME Must be $subscription->serials @@ -1401,7 +1402,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; @@ -1444,6 +1445,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 23c0a851a8..688fb9a370 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 %] +
  • + + +