From 40107fcf787d1c7a942de4129c5264bf51ae23cf Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 7 Jun 2016 16:00:03 -0300 Subject: [PATCH] Bug 14048: (QA followup) Rules should be defined for the chosen branch (or all) The original patches pull all defined rules for edition in the "Circulation and fines rules" page. This was not the intended behaviour for smart-rules.pl Instead, the modified rules should be constrained to the chosen branch (or the general default rule). This patch changes the templates and front-end scripts so they behave like that. To test: - Apply the patch - Open smart-rules.pl => SUCCESS: The text and refund rules section correctly refers to default global rules. The policy can be set to Yes and No, and works as expected. - Pick a specific branch => SUCCESS: The rule refers to the specific branch => SUCCESS: It detects the default rule is picked => SUCCESS: On changing the rules values are correctly retrieved if entering again to the page. => SUCCESS: The 'Use default' text is suffixed with the correct value set by the user in the 'All libraries' scenario. => Sign off :-D Sponsored-by: DoverNet Sponsored-by: South-East Kansas Library System ponsored-by: SWITCH Library Consortium --- admin/smart-rules.pl | 49 ++++++----- .../prog/en/modules/admin/smart-rules.tt | 95 ++++++++++++++-------- 2 files changed, 88 insertions(+), 56 deletions(-) diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index ac6efef..9d2d0fd 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -426,28 +426,37 @@ elsif ($op eq "add-branch-item") { } } } -elsif ( $op eq 'add-refund-lost-item-fee-rule' ) { - my $ref_branchcode = $input->param('ref_branchcode'); - my $ref_refund = $input->param('ref_refund'); - # We retrieve the object to update it, or create a new one - my $refundLostItemFeeRule = Koha::RefundLostItemFeeRules->find({ - branchcode => $ref_branchcode - }) // Koha::RefundLostItemFeeRule->new; - $refundLostItemFeeRule->set({ - branchcode => $ref_branchcode, - refund => $ref_refund - })->store(); -} -elsif ( $op eq 'del-refund-lost-item-fee-rule' ) { - my $ref_branchcode = $input->param('ref_branchcode'); - eval { - Koha::RefundLostItemFeeRules->find({ - branchcode => $ref_branchcode - })->delete; - }; +elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { + + my $refund = $input->param('refund'); + + if ( $refund eq '*' ) { + if ( $branch ne '*' ) { + # only do something for $refund eq '*' if branch-specific + eval { + # Delete it so it picks the default + Koha::RefundLostItemFeeRules->find({ + branchcode => $branch + })->delete; + }; + } + } else { + my $refundRule = + Koha::RefundLostItemFeeRules->find({ + branchcode => $branch + }) // Koha::RefundLostItemFeeRule->new; + $refundRule->set({ + branchcode => $branch, + refund => $refund + })->store; + } } -$template->param( refundLostItemFeeRules => scalar Koha::RefundLostItemFeeRules->search ) ; +my $refundLostItemFeeRule = Koha::RefundLostItemFeeRules->find({ branchcode => $branch }); +$template->param( + refundLostItemFeeRule => $refundLostItemFeeRule, + defaultRefundRule => Koha::RefundLostItemFeeRules->_default_rule +); my $branches = GetBranches(); my @branchloop; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index 4a156cd..8d197af 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -560,56 +560,79 @@ for="tobranch">Clone these rules to: -

Lost item fee refund on return policy

+ [% IF current_branch == '*' %] +

Default lost item fee refund on return policy

+ [% ELSE %] +

Lost item fee refund on return policy for [% Branches.GetName(current_branch) %]

+ [% END %]

Specify the default policy for lost item fees on return.

- + + - - [% FOREACH refundLostItemFeeRule IN refundLostItemFeeRules %] - - - [% END %] - - - -
Library Refund lost item fee  
- [% IF refundLostItemFeeRule.branchcode == '*' %] - All - [% ELSE %] - [% Branches.GetName(refundLostItemFeeRule.branchcode) %] - [% END %] - - [% IF refundLostItemFeeRule.refund %] - Yes - [% ELSE %] - No - [% END %] + - [% IF refundLostItemFeeRule.branchcode != '*' %] - Delete - [% END %] -
- + -
-- 2.8.4