Bug 10190: Update GetBranchcodesWithOverdueRules to use CirculationRules
This patch updates the C4::Overdues method GetBranchecodesWithOverdueRules to refer to the new location of these rules in the circulation rules table. We also update the unit tests to move the mocked data into the right location. We could perhaps migrate this method in Koha::CirculationRules at a later date? Sponsored-by: Glasgow Colleges Library Group <https://library.cityofglasgowcollege.ac.uk> Signed-off-by: George Harkins <George.Harkins@cityofglasgowcollege.ac.uk> Signed-off-by: Michaela <michaela.sieber@kit.edu> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
40478e1871
commit
d4e951b3d8
|
|
@ -720,21 +720,19 @@ returns a list of branch codes for branches with overdue rules defined.
|
|||
=cut
|
||||
|
||||
sub GetBranchcodesWithOverdueRules {
|
||||
my $dbh = C4::Context->dbh;
|
||||
my $branchcodes = $dbh->selectcol_arrayref(
|
||||
q|
|
||||
SELECT DISTINCT(branchcode)
|
||||
FROM overduerules
|
||||
WHERE delay1 IS NOT NULL
|
||||
ORDER BY branchcode
|
||||
|
|
||||
);
|
||||
if ( defined $branchcodes->[0] && $branchcodes->[0] eq '' ) {
|
||||
|
||||
# If a default rule exists, all branches should be returned
|
||||
return Koha::Libraries->search( {}, { order_by => 'branchname' } )->get_column('branchcode');
|
||||
my @branchcodes = Koha::CirculationRules->search(
|
||||
{ rule_name => 'overdue_1_delay' },
|
||||
{
|
||||
order_by => 'branchcode',
|
||||
columns => ['branchcode'],
|
||||
distinct => 1,
|
||||
}
|
||||
)->get_column('branchcode');
|
||||
if ( !$branchcodes[0] ) {
|
||||
@branchcodes = Koha::Libraries->search( {}, { order_by => 'branchname' } )->get_column('branchcode');
|
||||
}
|
||||
return @$branchcodes;
|
||||
|
||||
return @branchcodes;
|
||||
}
|
||||
|
||||
=head2 GetOverduesForBranch
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ is_deeply(
|
|||
);
|
||||
|
||||
# Test GetBranchcodesWithOverdueRules
|
||||
$dbh->do(q|DELETE FROM overduerules|);
|
||||
$dbh->do(q|DELETE FROM circulation_rules WHERE rule_name LIKE 'overdue_%' |);
|
||||
|
||||
my @overdue_branches;
|
||||
warnings_are { @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules(); } [],
|
||||
|
|
@ -104,10 +104,10 @@ warnings_are { @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules(
|
|||
|
||||
$dbh->do(
|
||||
q|
|
||||
INSERT INTO overduerules
|
||||
( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
|
||||
INSERT INTO circulation_rules
|
||||
( branchcode, categorycode, itemtype, rule_name, rule_value )
|
||||
VALUES
|
||||
( '', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
|
||||
( NULL, NULL, NULL, 'overdue_1_delay', 1 )
|
||||
|
|
||||
);
|
||||
|
||||
|
|
@ -121,10 +121,10 @@ is_deeply(
|
|||
|
||||
$dbh->do(
|
||||
q|
|
||||
INSERT INTO overduerules
|
||||
( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
|
||||
INSERT INTO circulation_rules
|
||||
( branchcode, categorycode, itemtype, rule_name, rule_value )
|
||||
VALUES
|
||||
( 'CPL', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
|
||||
( 'CPL', NULL, NULL, 'overdue_1_delay', 1 )
|
||||
|
|
||||
);
|
||||
|
||||
|
|
@ -134,27 +134,27 @@ is_deeply(
|
|||
'If a default rule exists and a specific rule exists, all branches should be returned'
|
||||
);
|
||||
|
||||
$dbh->do(q|DELETE FROM overduerules|);
|
||||
$dbh->do(q|DELETE FROM circulation_rules WHERE rule_name LIKE 'overdue_%' |);
|
||||
$dbh->do(
|
||||
q|
|
||||
INSERT INTO overduerules
|
||||
( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
|
||||
INSERT INTO circulation_rules
|
||||
( branchcode, categorycode, itemtype, rule_name, rule_value )
|
||||
VALUES
|
||||
( 'CPL', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
|
||||
( 'CPL', NULL, NULL, 'overdue_1_delay', 1 )
|
||||
|
|
||||
);
|
||||
|
||||
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules();
|
||||
is_deeply( \@overdue_branches, ['CPL'], 'If only a specific rule exist, only 1 branch should be returned' );
|
||||
|
||||
$dbh->do(q|DELETE FROM overduerules|);
|
||||
$dbh->do(q|DELETE FROM circulation_rules WHERE rule_name LIKE 'overdue_%' |);
|
||||
$dbh->do(
|
||||
q|
|
||||
INSERT INTO overduerules
|
||||
( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
|
||||
INSERT INTO circulation_rules
|
||||
( branchcode, categorycode, itemtype, rule_name, rule_value )
|
||||
VALUES
|
||||
( 'CPL', '', 1, 'LETTER_CODE1_CPL', 1, 5, 'LETTER_CODE2_CPL', 1, 10, 'LETTER_CODE3_CPL', 1 ),
|
||||
( 'MPL', '', 1, 'LETTER_CODE1_MPL', 1, 5, 'LETTER_CODE2_MPL', 1, 10, 'LETTER_CODE3_MPL', 1 )
|
||||
( 'CPL', NULL, NULL, 'overdue_1_delay', 1 ),
|
||||
( 'MPL', NULL, NULL, 'overdue_1_delay', 1 )
|
||||
|
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue