diff --git a/C4/Circulation.pm b/C4/Circulation.pm index db72340305..992eaf997c 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3271,7 +3271,9 @@ sub CanBookBeRenewed { my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); my $restricted = $patron->is_debarred; my $hasoverdues = $patron->has_overdues; - my $balance = $patron->account->balance; + my $account = $patron->account; + my $balance = $account->balance; + my $non_issues_charges = $account->non_issues_charges; if ( $restricted and $restrictionblockrenewing ) { return ( 0, 'restriction' ); @@ -3279,7 +3281,7 @@ sub CanBookBeRenewed { || ( $issue->is_overdue and $overduesblockrenewing eq 'blockitem' ) ) { return ( 0, 'overdue' ); - } elsif ( $finesblockrenewing && $balance > $finesblockrenewing ) { + } elsif ( $finesblockrenewing && $non_issues_charges > $finesblockrenewing ) { return ( 0, 'too_much_owing' ); } @@ -5047,12 +5049,10 @@ sub _CanBookBeAutoRenewed { } if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) { - my $fine_no_renewals = C4::Context->preference("FineNoRenewals"); - my $amountoutstanding = - C4::Context->preference("OPACFineNoRenewalsIncludeCredits") - ? $patron->account->balance - : $patron->account->outstanding_debits->total_outstanding; - if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) { + my $fine_no_renewals = C4::Context->preference("FineNoRenewals"); + my $account = $patron->account; + my $non_issues_charges = $account->non_issues_charges; + if ( $non_issues_charges and $non_issues_charges > $fine_no_renewals ) { return "auto_too_much_owing"; } } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt index a91b72c958..70d262284e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt @@ -36,7 +36,7 @@ [% SET aside = Koha.Preference('CircSidebar') ? 'circ-nav' : '' %] [% WRAPPER 'main-container.inc' aside=aside %] [% IF error %] -
+

Cannot renew:

[% IF error == "no_item" %] @@ -128,26 +128,44 @@ [% END %] [% ELSIF error == "auto_renew" or error == "auto_too_much_owing" %]

[% INCLUDE 'biblio-title.inc' biblio=item.biblio link = 1 %] ( [% item.barcode | html %] ) has been scheduled for automatic renewal.

- [% SET override_limit = error == "auto_renew" ? "AUTO_RENEW" : "TOO_MUCH" %] - - [% IF Koha.Preference('AllowRenewalLimitOverride') %] -
- [% INCLUDE 'csrf-token.inc' %] - - - - -
+ [% IF error == "auto_too_much_owing" %] + [% IF balance %] + + [% END %] + [% IF Koha.Preference('AllowFineOverrideRenewing') %] +
+ [% INCLUDE 'csrf-token.inc' %] + + + + +
+ [% END %] + [% ELSE %] + [% SET override_limit = "AUTO_RENEW" %] + [% IF Koha.Preference('AllowRenewalLimitOverride') %] +
+ [% INCLUDE 'csrf-token.inc' %] + + + + +
+ [% END %] [% END %] [% ELSIF error == "too_much_owing" %] -
  • The patron has a debt of [% balance | $Price %].
  • + [% IF Koha.Preference('AllowFineOverrideRenewing') %]
    [% INCLUDE 'csrf-token.inc' %] - +
    [% END %] [% ELSIF error == "on_reserve" %] @@ -189,7 +207,7 @@ [% END %] [% IF date_due %] -
    +

    Item renewed:

    [% INCLUDE 'biblio-title.inc' biblio=item.biblio link = 1 %] ( @@ -219,7 +237,7 @@

    [% ELSE %] - + [% END %]
    diff --git a/t/cypress/integration/Circulation/FineNoRenewals_spec.ts b/t/cypress/integration/Circulation/FineNoRenewals_spec.ts index 8f49d3979a..7d28d2b7c1 100644 --- a/t/cypress/integration/Circulation/FineNoRenewals_spec.ts +++ b/t/cypress/integration/Circulation/FineNoRenewals_spec.ts @@ -13,12 +13,15 @@ describe("Circulation - FineNoRenewals and AllowFineOverrideRenewing", () => { patron = objects.patron; checkout = objects.checkout; - // Set FineNoRenewals to 5 + // Disable auto_renew on the checkout to get too_much_owing error instead of auto_too_much_owing cy.task("query", { - sql: "UPDATE systempreferences SET value = ? WHERE variable = ?", - values: ["5", "FineNoRenewals"], + sql: "UPDATE issues SET auto_renew = 0 WHERE issue_id = ?", + values: [checkout.checkout_id], }); + // Set FineNoRenewals to 5 + cy.set_syspref("FineNoRenewals", "5"); + // Add a fine of 10 to the patron (exceeds limit) fine_amount = 10; cy.task("query", { @@ -27,7 +30,7 @@ describe("Circulation - FineNoRenewals and AllowFineOverrideRenewing", () => { values: [ patron.patron_id, fine_amount, - objects.item.item_id, + objects.items[0].item_id, ], }); @@ -40,23 +43,19 @@ describe("Circulation - FineNoRenewals and AllowFineOverrideRenewing", () => { cy.task("deleteSampleObjects", [this.testObjects]); // Reset system preferences - cy.task("query", { - sql: "UPDATE systempreferences SET value = '100' WHERE variable = 'FineNoRenewals'", - }); - cy.task("query", { - sql: "UPDATE systempreferences SET value = '0' WHERE variable = 'AllowFineOverrideRenewing'", - }); + cy.set_syspref("FineNoRenewals", "100"); + cy.set_syspref("AllowFineOverrideRenewing", "0"); }); it("should block renewal when patron has fines over FineNoRenewals limit", function () { - const barcode = this.testObjects.item.barcode; + const barcode = this.testObjects.items[0].external_id; // Visit renewal page cy.visit("/cgi-bin/koha/circ/renew.pl"); // Enter barcode cy.get("#barcode").type(barcode); - cy.get("form").submit(); + cy.get("#barcode").closest("form").submit(); // Should see error message about patron debt cy.get(".dialog.alert").should("be.visible"); @@ -68,21 +67,20 @@ describe("Circulation - FineNoRenewals and AllowFineOverrideRenewing", () => { it("should show override button when AllowFineOverrideRenewing is enabled", function () { // Enable AllowFineOverrideRenewing - cy.task("query", { - sql: "UPDATE systempreferences SET value = '1' WHERE variable = 'AllowFineOverrideRenewing'", - }); + cy.set_syspref("AllowFineOverrideRenewing", "1"); - const barcode = this.testObjects.item.barcode; + const barcode = this.testObjects.items[0].external_id; // Visit renewal page cy.visit("/cgi-bin/koha/circ/renew.pl"); // Enter barcode cy.get("#barcode").type(barcode); - cy.get("form").submit(); + cy.get("#barcode").closest("form").submit(); // Should see error message about patron debt cy.get(".dialog.alert").should("be.visible"); + cy.get(".dialog.alert li").should( "contain", `The patron has a debt of` @@ -94,24 +92,22 @@ describe("Circulation - FineNoRenewals and AllowFineOverrideRenewing", () => { ); cy.get('.dialog.alert form button[type="submit"].approve').should( "contain", - "Renew checkout(s)" + "Override and renew" ); }); it("should NOT show override button when AllowFineOverrideRenewing is disabled", function () { // Ensure AllowFineOverrideRenewing is disabled - cy.task("query", { - sql: "UPDATE systempreferences SET value = '0' WHERE variable = 'AllowFineOverrideRenewing'", - }); + cy.set_syspref("AllowFineOverrideRenewing", "0"); - const barcode = this.testObjects.item.barcode; + const barcode = this.testObjects.items[0].external_id; // Visit renewal page cy.visit("/cgi-bin/koha/circ/renew.pl"); // Enter barcode cy.get("#barcode").type(barcode); - cy.get("form").submit(); + cy.get("#barcode").closest("form").submit(); // Should see error message about patron debt cy.get(".dialog.alert").should("be.visible"); @@ -128,18 +124,16 @@ describe("Circulation - FineNoRenewals and AllowFineOverrideRenewing", () => { it("should allow renewal after override when AllowFineOverrideRenewing is enabled", function () { // Enable AllowFineOverrideRenewing - cy.task("query", { - sql: "UPDATE systempreferences SET value = '1' WHERE variable = 'AllowFineOverrideRenewing'", - }); + cy.set_syspref("AllowFineOverrideRenewing", "1"); - const barcode = this.testObjects.item.barcode; + const barcode = this.testObjects.items[0].external_id; // Visit renewal page cy.visit("/cgi-bin/koha/circ/renew.pl"); // Enter barcode cy.get("#barcode").type(barcode); - cy.get("form").submit(); + cy.get("#barcode").closest("form").submit(); // Click override button cy.get('.dialog.alert form button[type="submit"].approve').click(); @@ -160,17 +154,17 @@ describe("Circulation - FineNoRenewals and AllowFineOverrideRenewing", () => { cy.task("query", { sql: `INSERT INTO accountlines (borrowernumber, amountoutstanding, debit_type_code, status, interface, itemnumber) VALUES (?, 3.00, 'OVERDUE', 'UNRETURNED', 'test', ?)`, - values: [patron.patron_id, this.testObjects.item.item_id], + values: [patron.patron_id, this.testObjects.items[0].item_id], }); - const barcode = this.testObjects.item.barcode; + const barcode = this.testObjects.items[0].external_id; // Visit renewal page cy.visit("/cgi-bin/koha/circ/renew.pl"); // Enter barcode cy.get("#barcode").type(barcode); - cy.get("form").submit(); + cy.get("#barcode").closest("form").submit(); // Should see success message (no error about fines) cy.get(".dialog.message").should("be.visible");