Bug 15129: Add Koha::Object for issuing rules and let smart-rules.pl use it

Test plan:
1. Make sure that in koha/admin/smart-rules.pl you can still create
   new rules and that the new rules have all their values remained
   after saving the rule (so put to every field something).
2. Make sure you can edit that rule
3. Make sure you can delete that rule

Sponsored-by: Vaara-kirjastot

Followed test plan, works as expected
Signed-off-by: Marc Véron <veron@veron.ch>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
This commit is contained in:
Joonas Kylmälä 2015-11-04 15:15:04 +00:00 committed by Brendan Gallagher
parent 8b171223a6
commit e3f81857d8
3 changed files with 100 additions and 4 deletions

42
Koha/IssuingRule.pm Normal file
View file

@ -0,0 +1,42 @@
package Koha::IssuingRule;
# Copyright Vaara-kirjastot 2015
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use Koha::Database;
use base qw(Koha::Object);
=head1 NAME
Koha::Hold - Koha Hold object class
=head1 API
=head2 Class Methods
=cut
=head3 type
=cut
sub type {
return 'Issuingrule';
}
1;

50
Koha/IssuingRules.pm Normal file
View file

@ -0,0 +1,50 @@
package Koha::IssuingRules;
# Copyright Vaara-kirjastot 2015
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use Koha::Database;
use base qw(Koha::Objects);
=head1 NAME
Koha::IssuingRules - Koha IssuingRules object set class
=head1 API
=head2 Class Methods
=cut
=head3 type
=cut
sub type {
return 'Issuingrule';
}
=head3 object_class
=cut
sub object_class {
return 'Koha::IssuingRule';
}
1;

View file

@ -28,6 +28,8 @@ use C4::Debug;
use C4::Branch; # GetBranches
use Koha::DateUtils;
use Koha::Database;
use Koha::IssuingRule;
use Koha::IssuingRules;
my $input = CGI->new;
my $dbh = C4::Context->dbh;
@ -146,9 +148,6 @@ elsif ($op eq 'add') {
my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
$debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
my $schema = Koha::Database->new()->schema();
my $rs = $schema->resultset('Issuingrule');
my $params = {
branchcode => $br,
categorycode => $bor,
@ -177,7 +176,12 @@ elsif ($op eq 'add') {
cap_fine_to_replacement_price => $cap_fine_to_replacement_price,
};
$rs->update_or_create($params);
my $issuingrule = Koha::IssuingRules->find({categorycode => $bor, itemtype => $itemtype, branchcode => $br});
if ($issuingrule) {
$issuingrule->set($params)->store();
} else {
Koha::IssuingRule->new()->set($params)->store();
}
}
elsif ($op eq "set-branch-defaults") {