Skip to content

Commit

Permalink
Bug 23352: Set default collection code when creating subscription
Browse files Browse the repository at this point in the history
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 <samu.heiskanen@hypernova.fi>

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
  • Loading branch information
alexklbuckley authored and fridobox committed May 11, 2022
1 parent c196a34 commit ad6d126
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 7 deletions.
12 changes: 12 additions & 0 deletions C4/Items.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions C4/Serials.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1364,6 +1364,7 @@ sub ModSubscription {
itemtype => $itemtype,
previousitemtype => $previousitemtype,
mana_id => $mana_id,
ccode => $ccode,
}
)->store;
# FIXME Must be $subscription->serials
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -1444,6 +1445,7 @@ sub NewSubscription {
itemtype => $itemtype,
previousitemtype => $previousitemtype,
mana_id => $mana_id,
ccode => $ccode
}
)->store;
$subscription->discard_changes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ fieldset.rows table { clear: none; margin: 0; }
[% END %]
</select>
</li>
<li>
<label for="ccode">Collection code:</label>
<select name="ccode" id="ccode">
[% FOREACH ccode_loo IN ccodes_loop %]
[% IF (ccode_loo.selected) %]
<option value="[% ccode_loo.authorised_value | html %]" selected="selected">[% ccode_loo.lib | html %]</option>
[% ELSE %]
<option value="[% ccode_loo.authorised_value | html %]">[% ccode_loo.lib | html %]</option>
[% END %]
[% END %]
</select>
</li>
<li>
<label for="itemtype">Item type:</label>
<select name="itemtype" id="itemtype">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
<ol>
[% IF ( location ) %]<li><span class="label">Location:</span> [% location | html %]</li>[% END %]
[% IF ( callnumber ) %]<li><span class="label">Call number:</span> [% callnumber | html %]</li>[% END %]
[% IF ( ccode ) %]<li><span class="label">Collection code:</span> [% ccode | html %]</li>[% END %]
[% IF ( staffdisplaycount ) %]<li><span class="label">Number of issues to display to staff:</span>[% staffdisplaycount | html %]</li>[% END %]
[% IF ( opacdisplaycount ) %]<li><span class="label">Number of issues to display in OPAC:</span>[% opacdisplaycount | html %]</li>[% END %]
[% IF ( letter ) %]
Expand Down
8 changes: 6 additions & 2 deletions serials/subscription-add.pl
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@
}

my $locations_loop = GetAuthorisedValues("LOC");
my $ccodes_loop = GetAuthorisedValues("CCODE");

$template->param(
branchcode => $subs->{branchcode},
locations_loop=>$locations_loop,
ccodes_loop=>$ccodes_loop
);

my @additional_fields = Koha::AdditionalFields->search({ tablename => 'subscription' })->as_list;
Expand Down Expand Up @@ -328,6 +330,7 @@ sub redirect_add_subscription {
my $itemtype = $query->param('itemtype');
my $previousitemtype = $query->param('previousitemtype');
my $skip_serialseq = $query->param('skip_serialseq');
my $ccode = $query->param('ccode');

my $mana_id;
if ( $query->param('mana_id') ne "" ) {
Expand All @@ -354,7 +357,7 @@ sub redirect_add_subscription {
join(";",@irregularity), $numberpattern, $locale, $callnumber,
$manualhistory, $internalnotes, $serialsadditems,
$staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
$skip_serialseq, $itemtype, $previousitemtype, $mana_id
$skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode
);
if ( (C4::Context->preference('Mana') == 1) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){
my $result = Koha::SharedContent::send_entity( $query->param('mana_language') || '', $loggedinuser, $subscriptionid, 'subscription');
Expand Down Expand Up @@ -441,6 +444,7 @@ sub redirect_mod_subscription {
my $itemtype = $query->param('itemtype');
my $previousitemtype = $query->param('previousitemtype');
my $skip_serialseq = $query->param('skip_serialseq');
my $ccode = $query->param('ccode');

my $mana_id;
if ( $query->param('mana_id') ne "" ) {
Expand Down Expand Up @@ -476,7 +480,7 @@ sub redirect_mod_subscription {
$status, $biblionumber, $callnumber, $notes, $letter,
$manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
$opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
$skip_serialseq, $itemtype, $previousitemtype, $mana_id
$skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode
);

my @additional_fields;
Expand Down
2 changes: 2 additions & 0 deletions serials/subscription-detail.pl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
}
my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $subs->{location} });
$subs->{location} = $av->count ? $av->next->lib : '';
$av = Koha::AuthorisedValues->search({ category => 'CCODE', authorised_value => $subs->{ccode} });
$subs->{ccode} = $av->count ? $av->next->lib : '';
$subs->{abouttoexpire} = abouttoexpire($subs->{subscriptionid});
$template->param(%{ $subs });
$template->param(biblionumber_for_new_subscription => $subs->{bibnum});
Expand Down
15 changes: 12 additions & 3 deletions t/db_dependent/Serials.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use Koha::DateUtils qw( dt_from_string output_pref );
use Koha::Acquisition::Booksellers;
use t::lib::Mocks;
use t::lib::TestBuilder;
use Test::More tests => 50;
use Test::More tests => 52;

BEGIN {
use_ok('C4::Serials', qw( updateClaim NewSubscription GetSubscription GetSubscriptionHistoryFromSubscriptionId SearchSubscriptions ModSubscription GetExpirationDate GetSerials GetSerialInformation NewIssue AddItem2Serial DelSubscription GetFullSubscription PrepareSerialsData GetSubscriptionsFromBiblionumber ModSubscriptionHistory GetSerials2 GetLatestSerials GetNextSeq GetSeq CountSubscriptionFromBiblionumber ModSerialStatus findSerialsByStatus HasSubscriptionStrictlyExpired HasSubscriptionExpired GetLateOrMissingIssues check_routing addroutingmember GetNextDate ));
Expand Down Expand Up @@ -74,19 +74,23 @@ my $pattern_id = AddSubscriptionNumberpattern({

my $notes = "a\nnote\non\nseveral\nlines";
my $internalnotes = 'intnotes';
my $ccode = 'FIC';
my $subscriptionid = NewSubscription(
undef, "", undef, undef, $budget_id, $biblionumber,
'2013-01-01', $frequency_id, undef, undef, undef,
undef, undef, undef, undef, undef, undef,
1, $notes, ,undef, '2013-01-01', undef, $pattern_id,
undef, undef, 0, $internalnotes, 0,
undef, undef, 0, undef, '2013-12-31', 0
undef, undef, 0, undef, '2013-12-31', 0,
undef, undef, undef, $ccode

);

my $subscriptioninformation = GetSubscription( $subscriptionid );

is( $subscriptioninformation->{notes}, $notes, 'NewSubscription should set notes' );
is( $subscriptioninformation->{internalnotes}, $internalnotes, 'NewSubscription should set internalnotes' );
is( $subscriptioninformation->{ccode}, $ccode, 'NewSubscription should set ccode' );

my $subscription_history = C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid);
is( $subscription_history->{opacnote}, undef, 'NewSubscription should not set subscriptionhistory opacnotes' );
Expand Down Expand Up @@ -114,6 +118,7 @@ if (not $frequency->{unit}) {
$frequency->{description} = "Frequency created by t/db_dependant/Serials.t";
$subscriptioninformation->{periodicity} = AddSubscriptionFrequency($frequency);
$subscriptioninformation->{serialsadditems} = 1;
$subscriptioninformation->{ccode} = 'NFIC';

ModSubscription( @$subscriptioninformation{qw(
librarian branchcode aqbooksellerid cost aqbudgetid startdate
Expand All @@ -122,12 +127,16 @@ if (not $frequency->{unit}) {
innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
letter manualhistory internalnotes serialsadditems staffdisplaycount
opacdisplaycount graceperiod location enddate subscriptionid
skip_serialseq
skip_serialseq itemtype previousitemtype mana_id ccode
)} );
}
my $expirationdate = GetExpirationDate($subscriptionid) ;
ok( $expirationdate, "expiration date is not NULL" );

# Check ModSubscription has updated the ccode
my $subscriptioninformation2 = GetSubscription($subscriptionid);
is( $subscriptioninformation2->{ccode}, 'NFIC', 'ModSubscription should update ccode' );

ok(C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid), 'test getting history from sub-scription');

my ($serials_count, @serials) = GetSerials($subscriptionid);
Expand Down

0 comments on commit ad6d126

Please sign in to comment.