Skip to content

Commit ad6d126

Browse files
alexklbuckleyfridobox
authored andcommitted
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 <[email protected]> Signed-off-by: Andrew Fuerste-Henry <[email protected]> Signed-off-by: Owen Leonard <[email protected]> Signed-off-by: Katrin Fischer <[email protected]> Signed-off-by: Fridolin Somers <[email protected]>
1 parent c196a34 commit ad6d126

File tree

7 files changed

+49
-7
lines changed

7 files changed

+49
-7
lines changed

C4/Items.pm

+12
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,18 @@ sub PrepareItemrecordDisplay {
16941694
$defaultvalue = $defaultvalues->{location};
16951695
}
16961696
}
1697+
if ( ( $subfield->{kohafield} eq 'items.ccode' )
1698+
&& $defaultvalues
1699+
&& $defaultvalues->{'ccode'} ) {
1700+
1701+
if ( $itemrecord and $defaultvalues and not $itemrecord->subfield($tag,$subfield->{subfield}) ) {
1702+
# if the item record exists, only use default value if the item has no ccode
1703+
$defaultvalue = $defaultvalues->{ccode};
1704+
} elsif ( !$itemrecord and $defaultvalues ) {
1705+
# if the item record *doesn't* exists, always use the default value
1706+
$defaultvalue = $defaultvalues->{ccode};
1707+
}
1708+
}
16971709
if ( $subfield->{authorised_value} ) {
16981710
my @authorised_values;
16991711
my %authorised_lib;

C4/Serials.pm

+4-2
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ sub ModSubscription {
13211321
$biblionumber, $callnumber, $notes, $letter, $manualhistory,
13221322
$internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
13231323
$graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq,
1324-
$itemtype, $previousitemtype, $mana_id
1324+
$itemtype, $previousitemtype, $mana_id, $ccode
13251325
) = @_;
13261326

13271327
my $subscription = Koha::Subscriptions->find($subscriptionid);
@@ -1364,6 +1364,7 @@ sub ModSubscription {
13641364
itemtype => $itemtype,
13651365
previousitemtype => $previousitemtype,
13661366
mana_id => $mana_id,
1367+
ccode => $ccode,
13671368
}
13681369
)->store;
13691370
# FIXME Must be $subscription->serials
@@ -1401,7 +1402,7 @@ sub NewSubscription {
14011402
$innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
14021403
$numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
14031404
$serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1404-
$location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id
1405+
$location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode
14051406
) = @_;
14061407
my $dbh = C4::Context->dbh;
14071408

@@ -1444,6 +1445,7 @@ sub NewSubscription {
14441445
itemtype => $itemtype,
14451446
previousitemtype => $previousitemtype,
14461447
mana_id => $mana_id,
1448+
ccode => $ccode
14471449
}
14481450
)->store;
14491451
$subscription->discard_changes;

koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt

+12
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,18 @@ fieldset.rows table { clear: none; margin: 0; }
199199
[% END %]
200200
</select>
201201
</li>
202+
<li>
203+
<label for="ccode">Collection code:</label>
204+
<select name="ccode" id="ccode">
205+
[% FOREACH ccode_loo IN ccodes_loop %]
206+
[% IF (ccode_loo.selected) %]
207+
<option value="[% ccode_loo.authorised_value | html %]" selected="selected">[% ccode_loo.lib | html %]</option>
208+
[% ELSE %]
209+
<option value="[% ccode_loo.authorised_value | html %]">[% ccode_loo.lib | html %]</option>
210+
[% END %]
211+
[% END %]
212+
</select>
213+
</li>
202214
<li>
203215
<label for="itemtype">Item type:</label>
204216
<select name="itemtype" id="itemtype">

koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
<ol>
152152
[% IF ( location ) %]<li><span class="label">Location:</span> [% location | html %]</li>[% END %]
153153
[% IF ( callnumber ) %]<li><span class="label">Call number:</span> [% callnumber | html %]</li>[% END %]
154+
[% IF ( ccode ) %]<li><span class="label">Collection code:</span> [% ccode | html %]</li>[% END %]
154155
[% IF ( staffdisplaycount ) %]<li><span class="label">Number of issues to display to staff:</span>[% staffdisplaycount | html %]</li>[% END %]
155156
[% IF ( opacdisplaycount ) %]<li><span class="label">Number of issues to display in OPAC:</span>[% opacdisplaycount | html %]</li>[% END %]
156157
[% IF ( letter ) %]

serials/subscription-add.pl

+6-2
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@
124124
}
125125

126126
my $locations_loop = GetAuthorisedValues("LOC");
127+
my $ccodes_loop = GetAuthorisedValues("CCODE");
127128

128129
$template->param(
129130
branchcode => $subs->{branchcode},
130131
locations_loop=>$locations_loop,
132+
ccodes_loop=>$ccodes_loop
131133
);
132134

133135
my @additional_fields = Koha::AdditionalFields->search({ tablename => 'subscription' })->as_list;
@@ -328,6 +330,7 @@ sub redirect_add_subscription {
328330
my $itemtype = $query->param('itemtype');
329331
my $previousitemtype = $query->param('previousitemtype');
330332
my $skip_serialseq = $query->param('skip_serialseq');
333+
my $ccode = $query->param('ccode');
331334

332335
my $mana_id;
333336
if ( $query->param('mana_id') ne "" ) {
@@ -354,7 +357,7 @@ sub redirect_add_subscription {
354357
join(";",@irregularity), $numberpattern, $locale, $callnumber,
355358
$manualhistory, $internalnotes, $serialsadditems,
356359
$staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
357-
$skip_serialseq, $itemtype, $previousitemtype, $mana_id
360+
$skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode
358361
);
359362
if ( (C4::Context->preference('Mana') == 1) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){
360363
my $result = Koha::SharedContent::send_entity( $query->param('mana_language') || '', $loggedinuser, $subscriptionid, 'subscription');
@@ -441,6 +444,7 @@ sub redirect_mod_subscription {
441444
my $itemtype = $query->param('itemtype');
442445
my $previousitemtype = $query->param('previousitemtype');
443446
my $skip_serialseq = $query->param('skip_serialseq');
447+
my $ccode = $query->param('ccode');
444448

445449
my $mana_id;
446450
if ( $query->param('mana_id') ne "" ) {
@@ -476,7 +480,7 @@ sub redirect_mod_subscription {
476480
$status, $biblionumber, $callnumber, $notes, $letter,
477481
$manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
478482
$opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
479-
$skip_serialseq, $itemtype, $previousitemtype, $mana_id
483+
$skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode
480484
);
481485

482486
my @additional_fields;

serials/subscription-detail.pl

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@
114114
}
115115
my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $subs->{location} });
116116
$subs->{location} = $av->count ? $av->next->lib : '';
117+
$av = Koha::AuthorisedValues->search({ category => 'CCODE', authorised_value => $subs->{ccode} });
118+
$subs->{ccode} = $av->count ? $av->next->lib : '';
117119
$subs->{abouttoexpire} = abouttoexpire($subs->{subscriptionid});
118120
$template->param(%{ $subs });
119121
$template->param(biblionumber_for_new_subscription => $subs->{bibnum});

t/db_dependent/Serials.t

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use Koha::DateUtils qw( dt_from_string output_pref );
1616
use Koha::Acquisition::Booksellers;
1717
use t::lib::Mocks;
1818
use t::lib::TestBuilder;
19-
use Test::More tests => 50;
19+
use Test::More tests => 52;
2020

2121
BEGIN {
2222
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 ));
@@ -74,19 +74,23 @@ my $pattern_id = AddSubscriptionNumberpattern({
7474

7575
my $notes = "a\nnote\non\nseveral\nlines";
7676
my $internalnotes = 'intnotes';
77+
my $ccode = 'FIC';
7778
my $subscriptionid = NewSubscription(
7879
undef, "", undef, undef, $budget_id, $biblionumber,
7980
'2013-01-01', $frequency_id, undef, undef, undef,
8081
undef, undef, undef, undef, undef, undef,
8182
1, $notes, ,undef, '2013-01-01', undef, $pattern_id,
8283
undef, undef, 0, $internalnotes, 0,
83-
undef, undef, 0, undef, '2013-12-31', 0
84+
undef, undef, 0, undef, '2013-12-31', 0,
85+
undef, undef, undef, $ccode
86+
8487
);
8588

8689
my $subscriptioninformation = GetSubscription( $subscriptionid );
8790

8891
is( $subscriptioninformation->{notes}, $notes, 'NewSubscription should set notes' );
8992
is( $subscriptioninformation->{internalnotes}, $internalnotes, 'NewSubscription should set internalnotes' );
93+
is( $subscriptioninformation->{ccode}, $ccode, 'NewSubscription should set ccode' );
9094

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

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

136+
# Check ModSubscription has updated the ccode
137+
my $subscriptioninformation2 = GetSubscription($subscriptionid);
138+
is( $subscriptioninformation2->{ccode}, 'NFIC', 'ModSubscription should update ccode' );
139+
131140
ok(C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid), 'test getting history from sub-scription');
132141

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

0 commit comments

Comments
 (0)