View | Details | Raw Unified | Return to bug 23012
Collapse All | Expand All

(-)a/Koha/CirculationRules.pm (-1 / +47 lines)
Lines 51-57 our $RULE_KINDS = { Link Here
51
    lostreturn => {
51
    lostreturn => {
52
        scope => [ 'branchcode' ],
52
        scope => [ 'branchcode' ],
53
    },
53
    },
54
54
    processingreturn => {
55
        scope => [ 'branchcode' ],
56
    },
55
    patron_maxissueqty => {
57
    patron_maxissueqty => {
56
        scope => [ 'branchcode', 'categorycode' ],
58
        scope => [ 'branchcode', 'categorycode' ],
57
    },
59
    },
Lines 617-622 sub get_lostreturn_policy { Link Here
617
    return $rule ? $rule->rule_value : 'refund';
619
    return $rule ? $rule->rule_value : 'refund';
618
}
620
}
619
621
622
=head3 get_processingreturn_policy
623
624
  my $processingrefund_policy = Koha::CirculationRules->get_processingreturn_policy( { return_branch => $return_branch, item => $item } );
625
626
Return values are:
627
628
=over 2
629
630
=item '0' - Do not refund
631
632
=item 'refund' - Refund the lost item processing charge
633
634
=item 'restore' - Refund the lost item processing charge and restore the original overdue fine
635
636
=item 'charge' - Refund the lost item processing charge and charge a new overdue fine
637
638
=back
639
640
=cut
641
642
sub get_processingreturn_policy {
643
    my ( $class, $params ) = @_;
644
645
    my $item   = $params->{item};
646
647
    my $behaviour = C4::Context->preference( 'RefundLostOnReturnControl' ) // 'CheckinLibrary';
648
    my $behaviour_mapping = {
649
        CheckinLibrary    => $params->{'return_branch'} // $item->homebranch,
650
        ItemHomeBranch    => $item->homebranch,
651
        ItemHoldingBranch => $item->holdingbranch
652
    };
653
654
    my $branch = $behaviour_mapping->{ $behaviour };
655
656
    my $rule = Koha::CirculationRules->get_effective_rule(
657
        {
658
            branchcode => $branch,
659
            rule_name  => 'processingreturn',
660
        }
661
    );
662
663
    return $rule ? $rule->rule_value : 'refund';
664
}
665
620
=head3 article_requestable_rules
666
=head3 article_requestable_rules
621
667
622
    Return rules that allow article requests, optionally filtered by
668
    Return rules that allow article requests, optionally filtered by
(-)a/admin/smart-rules.pl (-1 / +30 lines)
Lines 654-659 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { Link Here
654
            }
654
            }
655
        );
655
        );
656
    }
656
    }
657
658
    my $processingreturn = $input->param('processingreturn');
659
660
    if ( $processingreturn eq '*' ) {
661
        if ( $branch ne '*' ) {
662
            # only do something for $processingreturn eq '*' if branch-specific
663
            Koha::CirculationRules->set_rules(
664
                {
665
                    branchcode   => $branch,
666
                    rules        => {
667
                        processingreturn => undef
668
                    }
669
                }
670
            );
671
        }
672
    } else {
673
        Koha::CirculationRules->set_rules(
674
            {
675
                branchcode   => $branch,
676
                rules        => {
677
                    processingreturn => $processingreturn
678
                }
679
            }
680
        );
681
    }
657
} elsif ( $op eq "set-waiting-hold-cancellation" ) {
682
} elsif ( $op eq "set-waiting-hold-cancellation" ) {
658
683
659
    my $category = $input->param('waiting_hold_cancellation_category');
684
    my $category = $input->param('waiting_hold_cancellation_category');
Lines 691-699 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { Link Here
691
716
692
my $refundLostItemFeeRule = Koha::CirculationRules->find({ branchcode => ($branch eq '*') ? undef : $branch, rule_name => 'lostreturn' });
717
my $refundLostItemFeeRule = Koha::CirculationRules->find({ branchcode => ($branch eq '*') ? undef : $branch, rule_name => 'lostreturn' });
693
my $defaultLostItemFeeRule = Koha::CirculationRules->find({ branchcode => undef, rule_name => 'lostreturn' });
718
my $defaultLostItemFeeRule = Koha::CirculationRules->find({ branchcode => undef, rule_name => 'lostreturn' });
719
my $refundProcessingFeeRule = Koha::CirculationRules->find({ branchcode => ($branch eq '*') ? undef : $branch, rule_name => 'processingreturn' });
720
my $defaultProcessingFeeRule = Koha::CirculationRules->find({ branchcode => undef, rule_name => 'processingreturn' });
694
$template->param(
721
$template->param(
695
    refundLostItemFeeRule => $refundLostItemFeeRule,
722
    refundLostItemFeeRule => $refundLostItemFeeRule,
696
    defaultRefundRule     => $defaultLostItemFeeRule ? $defaultLostItemFeeRule->rule_value : 'refund'
723
    defaultRefundRule     => $defaultLostItemFeeRule ? $defaultLostItemFeeRule->rule_value : 'refund',
724
    refundProcessingFeeRule => $refundProcessingFeeRule,
725
    defaultProcessingRefundRule => $defaultProcessingFeeRule ? $defaultProcessingFeeRule->rule_value : 'refund',
697
);
726
);
698
727
699
my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] });
728
my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] });
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-1 / +60 lines)
Lines 1073-1079 Link Here
1073
            <input type="hidden" name="branch" value="[% current_branch | html %]" />
1073
            <input type="hidden" name="branch" value="[% current_branch | html %]" />
1074
            <table>
1074
            <table>
1075
                <tr>
1075
                <tr>
1076
                    <th>Refund lost item fee</th>
1076
                    <th>Refund lost item replacement fee</th>
1077
                    <th>Refund lost item processing fee</th>
1077
                    <th>&nbsp;</th>
1078
                    <th>&nbsp;</th>
1078
                </tr>
1079
                </tr>
1079
                <tr>
1080
                <tr>
Lines 1179-1184 Link Here
1179
                          [% END %]
1180
                          [% END %]
1180
                        </select>
1181
                        </select>
1181
                    </td>
1182
                    </td>
1183
                    <td>
1184
                        <select name="processingreturn">
1185
                          [%# Default branch %]
1186
                          [% IF ( current_branch == '*' ) %]
1187
                            [% IF ( defaultProcessingRefundRule == 'refund' ) %]
1188
                            <option value="refund" selected="selected">Refund lost item processing charge</option>
1189
                            <option value="refund_unpaid">Refund lost item processing charge (only if unpaid)</option>
1190
                            <option value="0">Leave lost item processing charge</option>
1191
                            [% ELSIF ( defaultProcessingRefundRule == 'refund_unpaid' ) %]
1192
                            <option value="refund">Refund lost item charge</option>
1193
                            <option value="refund_unpaid" selected="selected">Refund lost item processing charge (only if unpaid)</option>
1194
                            <option value="0">Leave lost item processing charge</option>
1195
                            [% ELSIF ( defaultProcessingRefundRule == 0 ) %]
1196
                            <option value="refund">Refund lost item processing charge</option>
1197
                            <option value="refund_unpaid">Refund lost item processing charge (only if unpaid)</option>
1198
                            <option value="0" selected="selected">Leave lost item processing charge</option>
1199
                            [% ELSE %]
1200
                            <option value="refund">Refund lost item processing charge</option>
1201
                            <option value="refund_unpaid">Refund lost item processing charge (only if unpaid)</option>
1202
                            <option value="0">Leave lost item processing charge</option>
1203
                            [% END %]
1204
                          [% ELSE %]
1205
                          [%# Branch-specific %]
1206
                            [% IF ( not refundProcessingFeeRule ) %]
1207
                                <option value="*" selected="selected">
1208
                            [% ELSE %]
1209
                                <option value="*">
1210
                            [% END %]
1211
                              [% IF defaultProcessingRefundRule == 'refund' %]
1212
                                <span>Use default (Refund lost item processing charge)</span>
1213
                              [% ELSIF defaultProcessingRefundRule == 'refund_unpaid' %]
1214
                                Use default (Refund lost item processing charge (only if unpaid))
1215
                              [% ELSE %]
1216
                                <span>Use default (Leave lost item processing charge)</span>
1217
                              [% END %]
1218
                                </option>
1219
                            [% IF ( not refundProcessingFeeRule ) %]
1220
                                <option value="refund">Refund lost item processing charge</option>
1221
                                <option value="refund_unpaid">Refund lost item processing charge (only if unpaid)</option>
1222
                                <option value="0">Leave lost item processing charge</option>
1223
                            [% ELSE %]
1224
                                [% IF ( refundProcessingFeeRule.rule_value == 'refund' ) %]
1225
                                <option value="refund" selected="selected">Refund lost item processing charge</option>
1226
                                <option value="refund_unpaid">Refund lost item processing charge (only if unpaid)</option>
1227
                                <option value="0">Leave lost item processing charge</option>
1228
                                [% ELSIF ( refundProcessingFeeRule.rule_value == 'refund_unpaid' ) %]
1229
                                <option value="refund">Refund lost item processing charge</option>
1230
                                <option value="refund_unpaid" selected="selected">Refund lost item processing charge (only if unpaid)</option>
1231
                                <option value="0">Leave lost item processing charge</option>
1232
                                [% ELSIF ( refundProcessingFeeRule.rule_value == 0 ) %]
1233
                                <option value="refund">Refund lost item processing charge</option>
1234
                                <option value="refund_unpaid">Refund lost item processing charge (only if unpaid)</option>
1235
                                <option value="0" selected="selected">Leave lost item processing charge</option>
1236
                                [% END %]
1237
                            [% END %]
1238
                          [% END %]
1239
                        </select>
1240
                    </td>
1182
                    <td class="actions">
1241
                    <td class="actions">
1183
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
1242
                        <button type="submit" class="btn btn-default btn-xs"><i class="fa fa-save"></i> Save</button>
1184
                    </td>
1243
                    </td>
(-)a/t/db_dependent/Koha/CirculationRules.t (-5 / +173 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Benchmark;
22
use Benchmark;
23
use Test::More tests => 7;
23
use Test::More tests => 8;
24
use Test::Deep qw( cmp_methods );
24
use Test::Deep qw( cmp_methods );
25
use Test::Exception;
25
use Test::Exception;
26
26
Lines 161-167 subtest 'set_rule' => sub { Link Here
161
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
161
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
162
162
163
    subtest 'Correct call' => sub {
163
    subtest 'Correct call' => sub {
164
        plan tests => 4;
164
        plan tests => 5;
165
165
166
        Koha::CirculationRules->delete;
166
        Koha::CirculationRules->delete;
167
167
Lines 173-178 subtest 'set_rule' => sub { Link Here
173
            } );
173
            } );
174
        }, 'setting lostreturn with branch' );
174
        }, 'setting lostreturn with branch' );
175
175
176
        lives_ok( sub {
177
            Koha::CirculationRules->set_rule( {
178
                branchcode => $branchcode,
179
                rule_name => 'processingreturn',
180
                rule_value => '',
181
            } );
182
        }, 'setting processingreturn with branch' );
183
176
        lives_ok( sub {
184
        lives_ok( sub {
177
            Koha::CirculationRules->set_rule( {
185
            Koha::CirculationRules->set_rule( {
178
                branchcode => $branchcode,
186
                branchcode => $branchcode,
Lines 203-209 subtest 'set_rule' => sub { Link Here
203
    };
211
    };
204
212
205
    subtest 'Call with missing params' => sub {
213
    subtest 'Call with missing params' => sub {
206
        plan tests => 4;
214
        plan tests => 5;
207
215
208
        Koha::CirculationRules->delete;
216
        Koha::CirculationRules->delete;
209
217
Lines 214-219 subtest 'set_rule' => sub { Link Here
214
            } );
222
            } );
215
        }, qr/branchcode/, 'setting lostreturn without branch fails' );
223
        }, qr/branchcode/, 'setting lostreturn without branch fails' );
216
224
225
        throws_ok( sub {
226
            Koha::CirculationRules->set_rule( {
227
                rule_name => 'processingreturn',
228
                rule_value => '',
229
            } );
230
        }, qr/branchcode/, 'setting processingreturn without branch fails' );
231
217
        throws_ok( sub {
232
        throws_ok( sub {
218
            Koha::CirculationRules->set_rule( {
233
            Koha::CirculationRules->set_rule( {
219
                branchcode => $branchcode,
234
                branchcode => $branchcode,
Lines 241-247 subtest 'set_rule' => sub { Link Here
241
    };
256
    };
242
257
243
    subtest 'Call with extra params' => sub {
258
    subtest 'Call with extra params' => sub {
244
        plan tests => 3;
259
        plan tests => 4;
245
260
246
        Koha::CirculationRules->delete;
261
        Koha::CirculationRules->delete;
247
262
Lines 254-259 subtest 'set_rule' => sub { Link Here
254
            } );
269
            } );
255
        }, qr/categorycode/, 'setting lostreturn with categorycode fails' );
270
        }, qr/categorycode/, 'setting lostreturn with categorycode fails' );
256
271
272
        throws_ok( sub {
273
            Koha::CirculationRules->set_rule( {
274
                branchcode => $branchcode,
275
                categorycode => $categorycode,
276
                rule_name => 'processingreturn',
277
                rule_value => '',
278
            } );
279
        }, qr/categorycode/, 'setting processingreturn with categorycode fails' );
280
257
        throws_ok( sub {
281
        throws_ok( sub {
258
            Koha::CirculationRules->set_rule( {
282
            Koha::CirculationRules->set_rule( {
259
                branchcode => $branchcode,
283
                branchcode => $branchcode,
Lines 801-806 subtest 'get_lostreturn_policy() tests' => sub { Link Here
801
    $schema->storage->txn_rollback;
825
    $schema->storage->txn_rollback;
802
};
826
};
803
827
828
subtest 'get_processingreturn_policy() tests' => sub {
829
    plan tests => 7;
830
831
    $schema->storage->txn_begin;
832
833
    $schema->resultset('CirculationRule')->search()->delete;
834
835
    my $default_rule_charge = $builder->build(
836
        {
837
            source => 'CirculationRule',
838
            value  => {
839
                branchcode   => undef,
840
                categorycode => undef,
841
                itemtype     => undef,
842
                rule_name    => 'processingreturn',
843
                rule_value   => 'charge'
844
            }
845
        }
846
    );
847
    my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
848
    my $specific_rule_false = $builder->build(
849
        {
850
            source => 'CirculationRule',
851
            value  => {
852
                branchcode   => $branchcode,
853
                categorycode => undef,
854
                itemtype     => undef,
855
                rule_name    => 'processingreturn',
856
                rule_value   => 0
857
            }
858
        }
859
    );
860
    my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
861
    my $specific_rule_refund = $builder->build(
862
        {
863
            source => 'CirculationRule',
864
            value  => {
865
                branchcode   => $branchcode2,
866
                categorycode => undef,
867
                itemtype     => undef,
868
                rule_name    => 'processingreturn',
869
                rule_value   => 'refund'
870
            }
871
        }
872
    );
873
    my $branchcode3 = $builder->build( { source => 'Branch' } )->{branchcode};
874
    my $specific_rule_restore = $builder->build(
875
        {
876
            source => 'CirculationRule',
877
            value  => {
878
                branchcode   => $branchcode3,
879
                categorycode => undef,
880
                itemtype     => undef,
881
                rule_name    => 'processingreturn',
882
                rule_value   => 'restore'
883
            }
884
        }
885
    );
886
887
    # Make sure we have an unused branchcode
888
    my $branchcode4 = $builder->build( { source => 'Branch' } )->{branchcode};
889
    my $specific_rule_dummy = $builder->build(
890
        {
891
            source => 'CirculationRule',
892
            value  => {
893
                branchcode   => $branchcode4,
894
                categorycode => undef,
895
                itemtype     => undef,
896
                rule_name    => 'processingreturn',
897
                rule_value   => 'refund'
898
            }
899
        }
900
    );
901
    my $branch_without_rule = $specific_rule_dummy->{ branchcode };
902
    Koha::CirculationRules
903
        ->search(
904
            {
905
                branchcode   => $branch_without_rule,
906
                categorycode => undef,
907
                itemtype     => undef,
908
                rule_name    => 'processingreturn',
909
                rule_value   => 'refund'
910
            }
911
          )
912
        ->next
913
        ->delete;
914
915
    my $item = $builder->build_sample_item(
916
        {
917
            homebranch    => $specific_rule_restore->{branchcode},
918
            holdingbranch => $specific_rule_false->{branchcode}
919
        }
920
    );
921
    my $params = {
922
        return_branch => $specific_rule_refund->{ branchcode },
923
        item          => $item
924
    };
925
926
    # Specific rules
927
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
928
    is( Koha::CirculationRules->get_processingreturn_policy( $params ),
929
        'refund','Specific rule for checkin branch is applied (refund)');
930
931
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHomeBranch' );
932
    is( Koha::CirculationRules->get_processingreturn_policy( $params ),
933
         'restore','Specific rule for home branch is applied (restore)');
934
935
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' );
936
    is( Koha::CirculationRules->get_processingreturn_policy( $params ),
937
         0,'Specific rule for holding branch is applied (false)');
938
939
    # Default rule check
940
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'CheckinLibrary' );
941
    $params->{return_branch} = $branch_without_rule;
942
    is( Koha::CirculationRules->get_processingreturn_policy( $params ),
943
         'charge','No rule for branch, global rule applied (charge)');
944
945
    # Change the default value just to try
946
    Koha::CirculationRules->search({ branchcode => undef, rule_name => 'processingreturn' })->next->rule_value(0)->store;
947
    is( Koha::CirculationRules->get_processingreturn_policy( $params ),
948
         0,'No rule for branch, global rule applied (false)');
949
950
    # No default rule defined check
951
    Koha::CirculationRules
952
        ->search(
953
            {
954
                branchcode   => undef,
955
                categorycode => undef,
956
                itemtype     => undef,
957
                rule_name    => 'processingreturn'
958
            }
959
          )
960
        ->next
961
        ->delete;
962
    is( Koha::CirculationRules->get_processingreturn_policy( $params ),
963
         'refund','No rule for branch, no default rule, fallback default (refund)');
964
965
    # Fallback to ItemHoldBranch if CheckinLibrary is undefined
966
    $params->{return_branch} = undef;
967
    is( Koha::CirculationRules->get_processingreturn_policy( $params ),
968
         'restore','return_branch undefined, fallback to ItemHomeBranch rule (restore)');
969
970
    $schema->storage->txn_rollback;
971
};
972
804
sub _is_row_match {
973
sub _is_row_match {
805
    my ( $rule, $expected, $message ) = @_;
974
    my ( $rule, $expected, $message ) = @_;
806
975
807
- 

Return to bug 23012