Bugzilla – Attachment 52835 Details for
Bug 14048
Change RefundLostItemFeeOnReturn to be branch specific
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14048: Add RefundLostItemFeeRule table and classes
Bug-14048-Add-RefundLostItemFeeRule-table-and-clas.patch (text/plain), 11.11 KB, created by
Tomás Cohen Arazi (tcohen)
on 2016-06-24 16:18:36 UTC
(
hide
)
Description:
Bug 14048: Add RefundLostItemFeeRule table and classes
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2016-06-24 16:18:36 UTC
Size:
11.11 KB
patch
obsolete
>From a0e3fd1cf98687deeb21f522c34840f5c276e072 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 3 Jun 2016 11:23:20 -0300 >Subject: [PATCH] Bug 14048: Add RefundLostItemFeeRule table and classes > >This patch introduces new classes for handling refund lost item fee >rules. It introduces a new table for storing this rules. > >It is designed so it is possible to define a global rule, and then >branch-specific ones. The specific is prefered if available. > >This behaviour is fully tested by unit tests introduced by the following patches. > >This cannot be tested on its own. > >Sponsored-by: DoverNet >Sponsored-by: South-East Kansas Library System >Sponsored-by: SWITCH Library Consortium > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >Signed-off-by: Jason Robb <jrobb@sekls.org> >Signed-off-by: Jennifer Schmidt <jschmidt@switchinc.org> >Signed-off-by: Margaret Thrasher <p.thrasher@dover.nh.gov> >--- > C4/Installer.pm | 1 + > Koha/Exceptions.pm | 11 +- > Koha/RefundLostItemFeeRule.pm | 63 +++++++++ > Koha/RefundLostItemFeeRules.pm | 145 +++++++++++++++++++++ > Koha/Schema/Result/RefundLostItemFeeRule.pm | 66 ++++++++++ > installer/data/mysql/kohastructure.sql | 11 ++ > .../mysql/mandatory/refund_lost_item_fee_rules.sql | 2 + > 7 files changed, 298 insertions(+), 1 deletion(-) > create mode 100644 Koha/RefundLostItemFeeRule.pm > create mode 100644 Koha/RefundLostItemFeeRules.pm > create mode 100644 Koha/Schema/Result/RefundLostItemFeeRule.pm > create mode 100644 installer/data/mysql/mandatory/refund_lost_item_fee_rules.sql > >diff --git a/C4/Installer.pm b/C4/Installer.pm >index 1e6768e..f5af971 100644 >--- a/C4/Installer.pm >+++ b/C4/Installer.pm >@@ -307,6 +307,7 @@ sub load_sql_in_order { > push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/userflags.sql"; > push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/userpermissions.sql"; > push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/audio_alerts.sql"; >+ push @fnames, C4::Context->config('intranetdir') . "/installer/data/mysql/mandatory/refund_lost_item_fee_rules.sql"; > foreach my $file (@fnames) { > # warn $file; > undef $/; >diff --git a/Koha/Exceptions.pm b/Koha/Exceptions.pm >index beef949..dd8647b 100644 >--- a/Koha/Exceptions.pm >+++ b/Koha/Exceptions.pm >@@ -4,6 +4,7 @@ use Modern::Perl; > > use Exception::Class ( > >+ # General exceptions > 'Koha::Exceptions::Exception' => { > description => 'Something went wrong!', > }, >@@ -12,7 +13,15 @@ use Exception::Class ( > isa => 'Koha::Exceptions::Exception', > description => 'Same object already exists', > }, >- >+ 'Koha::Exceptions::CannotDeleteDefault' => { >+ isa => 'Koha::Exceptions::Exception', >+ description => 'The default value cannot be deleted' >+ }, >+ 'Koha::Exceptions::MissingParameter' => { >+ isa => 'Koha::Exceptions::Exception', >+ description => 'A required parameter is missing' >+ }, >+ # Virtualshelves exceptions > 'Koha::Exceptions::Virtualshelves::DuplicateObject' => { > isa => 'Koha::Exceptions::DuplicateObject', > description => "Duplicate shelf object", >diff --git a/Koha/RefundLostItemFeeRule.pm b/Koha/RefundLostItemFeeRule.pm >new file mode 100644 >index 0000000..2a58c06 >--- /dev/null >+++ b/Koha/RefundLostItemFeeRule.pm >@@ -0,0 +1,63 @@ >+package Koha::RefundLostItemFeeRule; >+ >+# Copyright Theke Solutions 2016 >+# >+# 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 Koha::Exceptions; >+ >+use base qw(Koha::Object); >+ >+=head1 NAME >+ >+Koha::RefundLostItemFeeRule - Koha RefundLostItemFeeRule object class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 type >+ >+=cut >+ >+sub _type { >+ return 'RefundLostItemFeeRule'; >+} >+ >+=head3 delete >+ >+This is an overloaded delete method. It throws an exception if the wildcard >+branch is passed (it can only be modified, but not deleted). >+ >+=cut >+ >+sub delete { >+ my ($self) = @_; >+ >+ if ( $self->branchcode eq '*' ) { >+ Koha::Exceptions::CannotDeleteDefault->throw; >+ } >+ >+ return $self->SUPER::delete($self); >+} >+ >+ >+1; >diff --git a/Koha/RefundLostItemFeeRules.pm b/Koha/RefundLostItemFeeRules.pm >new file mode 100644 >index 0000000..79a334e >--- /dev/null >+++ b/Koha/RefundLostItemFeeRules.pm >@@ -0,0 +1,145 @@ >+package Koha::RefundLostItemFeeRules; >+ >+# Copyright Theke Solutions 2016 >+# >+# 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 Koha::Exceptions; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::RefundLostItemFeeRules - Koha RefundLostItemFeeRules object set class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 type >+ >+=cut >+ >+sub _type { >+ return 'RefundLostItemFeeRule'; >+} >+ >+=head3 object_class >+ >+=cut >+ >+sub object_class { >+ return 'Koha::RefundLostItemFeeRule'; >+} >+ >+=head3 should_refund >+ >+Koha::RefundLostItemFeeRules->should_refund() >+ >+Returns a boolean telling if the fee needs to be refund given the >+passed params, and the current rules/sysprefs configuration. >+ >+=cut >+ >+sub should_refund { >+ >+ my $self = shift; >+ my $params = shift; >+ >+ return $self->_effective_branch_rule( $self->_choose_branch( $params ) ); >+} >+ >+ >+=head3 _effective_branch_rule >+ >+Koha::RefundLostItemFeeRules->_effective_branch_rule >+ >+Given a branch, returns a boolean representing the resulting rule. >+It tries the branch-specific first. Then falls back to the defined default. >+ >+=cut >+ >+sub _effective_branch_rule { >+ >+ my $self = shift; >+ my $branch = shift; >+ >+ my $specific_rule = $self->find({ branchcode => $branch }); >+ >+ return ( defined $specific_rule ) >+ ? $specific_rule->refund >+ : $self->_default_rule; >+} >+ >+=head3 _choose_branch >+ >+my $branch = Koha::RefundLostItemFeeRules->_choose_branch({ >+ current_branch => 'current_branch_code', >+ item_home_branch => 'item_home_branch', >+ item_holding_branch => 'item_holding_branch' >+}); >+ >+Helper function that determines the branch to be used to apply the rule. >+ >+=cut >+ >+sub _choose_branch { >+ >+ my $self = shift; >+ my $param = shift; >+ >+ my $behaviour = Koha::Config::SysPrefs >+ ->find( 'RefundLostOnReturnControl' ) >+ ->value // 'CheckinLibrary'; >+ >+ my $param_mapping = { >+ CheckinLibrary => 'current_branch', >+ ItemHomeBranch => 'item_home_branch', >+ ItemHoldingBranch => 'item_holding_branch' >+ }; >+ >+ my $branch = $param->{ $param_mapping->{ $behaviour } }; >+ >+ if ( !defined $branch ) { >+ Koha::Exceptions::MissingParameter->throw( >+ "$behaviour requires the " . >+ $param_mapping->{ $behaviour } . >+ " param" >+ ); >+ } >+ >+ return $branch; >+} >+ >+=head3 _default_rule (internal) >+ >+This function returns the default rule defined for refunding lost >+item fees on return. >+ >+=cut >+ >+sub _default_rule { >+ my $self = shift; >+ >+ return $self->find({ branchcode => '*' })->refund; >+} >+ >+1; >diff --git a/Koha/Schema/Result/RefundLostItemFeeRule.pm b/Koha/Schema/Result/RefundLostItemFeeRule.pm >new file mode 100644 >index 0000000..30ae580 >--- /dev/null >+++ b/Koha/Schema/Result/RefundLostItemFeeRule.pm >@@ -0,0 +1,66 @@ >+use utf8; >+package Koha::Schema::Result::RefundLostItemFeeRule; >+ >+# Created by DBIx::Class::Schema::Loader >+# DO NOT MODIFY THE FIRST PART OF THIS FILE >+ >+=head1 NAME >+ >+Koha::Schema::Result::RefundLostItemFeeRule >+ >+=cut >+ >+use strict; >+use warnings; >+ >+use base 'DBIx::Class::Core'; >+ >+=head1 TABLE: C<refund_lost_item_fee_rules> >+ >+=cut >+ >+__PACKAGE__->table("refund_lost_item_fee_rules"); >+ >+=head1 ACCESSORS >+ >+=head2 branchcode >+ >+ data_type: 'varchar' >+ default_value: (empty string) >+ is_nullable: 0 >+ size: 10 >+ >+=head2 refund >+ >+ data_type: 'tinyint' >+ default_value: 0 >+ is_nullable: 0 >+ >+=cut >+ >+__PACKAGE__->add_columns( >+ "branchcode", >+ { data_type => "varchar", default_value => "", is_nullable => 0, size => 10 }, >+ "refund", >+ { data_type => "tinyint", default_value => 0, is_nullable => 0 }, >+); >+ >+=head1 PRIMARY KEY >+ >+=over 4 >+ >+=item * L</branchcode> >+ >+=back >+ >+=cut >+ >+__PACKAGE__->set_primary_key("branchcode"); >+ >+ >+# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-05-31 02:45:35 >+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:K+2D3R+JxrovgvjdqA8xdw >+ >+ >+# You can replace this text with custom code or comments, and it will be preserved on regeneration >+1; >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 4612a17..3b9bcc0 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -868,6 +868,17 @@ CREATE TABLE `issuingrules` ( -- circulation and fine rules > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; > > -- >+-- Table structure for table `refund_lost_item_fee_rules` >+-- >+ >+DROP TABLE IF EXISTS `refund_lost_item_fee_rules`; >+CREATE TABLE `refund_lost_item_fee_rules` ( -- refund lost item fee rules tbale >+ `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode) >+ `refund` tinyint(1) NOT NULL default 0, -- control wether to refund lost item fees on return >+ PRIMARY KEY (`branchcode`) >+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; >+ >+-- > -- Table structure for table `items` > -- > >diff --git a/installer/data/mysql/mandatory/refund_lost_item_fee_rules.sql b/installer/data/mysql/mandatory/refund_lost_item_fee_rules.sql >new file mode 100644 >index 0000000..3139805 >--- /dev/null >+++ b/installer/data/mysql/mandatory/refund_lost_item_fee_rules.sql >@@ -0,0 +1,2 @@ >+-- Default refund lost item fee rule >+INSERT INTO refund_lost_item_fee_rules (branchcode,refund) VALUES ( '*', '1' ); >-- >2.9.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14048
:
52016
|
52017
|
52018
|
52019
|
52020
|
52169
|
52170
|
52202
|
52203
|
52286
|
52287
|
52288
|
52289
|
52290
|
52291
|
52292
|
52293
|
52306
|
52444
|
52445
|
52446
|
52447
|
52448
|
52449
|
52450
|
52451
|
52482
|
52658
|
52659
|
52660
|
52661
|
52662
|
52663
|
52664
|
52665
|
52666
|
52667
|
52668
|
52748
|
52749
|
52750
|
52751
|
52752
|
52753
|
52754
|
52755
|
52756
|
52757
|
52835
|
52836
|
52837
|
52838
|
52839
|
52840
|
52841
|
52842
|
52843
|
52844
|
52876
|
52883
|
52894
|
53017
|
53018
|
53019
|
53020
|
53021
|
53022
|
53023
|
53024
|
53025
|
53026
|
53027
|
53028
|
53029