From ba25ec329b1bce3db42ee69d97f6c5dacdacd743 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 ++++++++++++ .../prog/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 502ccb6793..cb09a87d4f 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 ad772fecac..60ea311874 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1319,7 +1319,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); @@ -1362,6 +1362,7 @@ sub ModSubscription { itemtype => $itemtype, previousitemtype => $previousitemtype, mana_id => $mana_id, + ccode => $ccode, } )->store; # FIXME Must be $subscription->serials @@ -1399,7 +1400,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; @@ -1442,6 +1443,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 @@ -200,6 +200,18 @@ fieldset.rows table { clear: none; margin: 0; }
  • + + +
  • +