From: Thomas Berezansky Date: Mon, 6 Jun 2011 21:30:35 +0000 (-0400) Subject: INDB Circ Matrix + Checkout Overrides Fix X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=faef6e09d28913d2311a73062695f181f83c6ea3;p=contrib%2FConifer.git INDB Circ Matrix + Checkout Overrides Fix Move most failures to after matchpoint lookup. This prevents "no duration rule" errors on overridable errors. Signed-off-by: Thomas Berezansky Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/src/sql/Pg/100.circ_matrix.sql b/Open-ILS/src/sql/Pg/100.circ_matrix.sql index 77e975e0f4..79fc705a21 100644 --- a/Open-ILS/src/sql/Pg/100.circ_matrix.sql +++ b/Open-ILS/src/sql/Pg/100.circ_matrix.sql @@ -377,10 +377,10 @@ BEGIN -- Assume success unless we hit a failure condition result.success := TRUE; - -- Fail if the user is BARRED - SELECT INTO user_object * FROM actor.usr WHERE id = match_user; + -- Need user info to look up matchpoints + SELECT INTO user_object * FROM actor.usr WHERE id = match_user AND NOT deleted; - -- Fail if we couldn't find the user + -- (Insta)Fail if we couldn't find the user IF user_object.id IS NULL THEN result.fail_part := 'no_user'; result.success := FALSE; @@ -389,9 +389,10 @@ BEGIN RETURN; END IF; - SELECT INTO item_object * FROM asset.copy WHERE id = match_item; + -- Need item info to look up matchpoints + SELECT INTO item_object * FROM asset.copy WHERE id = match_item AND NOT deleted; - -- Fail if we couldn't find the item + -- (Insta)Fail if we couldn't find the item IF item_object.id IS NULL THEN result.fail_part := 'no_item'; result.success := FALSE; @@ -400,6 +401,32 @@ BEGIN RETURN; END IF; + SELECT INTO circ_test * FROM action.find_circ_matrix_matchpoint(circ_ou, item_object, user_object, renewal); + + circ_matchpoint := circ_test.matchpoint; + result.matchpoint := circ_matchpoint.id; + result.circulate := circ_matchpoint.circulate; + result.duration_rule := circ_matchpoint.duration_rule; + result.recurring_fine_rule := circ_matchpoint.recurring_fine_rule; + result.max_fine_rule := circ_matchpoint.max_fine_rule; + result.hard_due_date := circ_matchpoint.hard_due_date; + result.renewals := circ_matchpoint.renewals; + result.grace_period := circ_matchpoint.grace_period; + result.buildrows := circ_test.buildrows; + + -- (Insta)Fail if we couldn't find a matchpoint + IF circ_test.success = false THEN + result.fail_part := 'no_matchpoint'; + result.success := FALSE; + done := TRUE; + RETURN NEXT result; + RETURN; + END IF; + + -- All failures before this point are non-recoverable + -- Below this point are possibly overridable failures + + -- Fail if the user is barred IF user_object.barred IS TRUE THEN result.fail_part := 'actor.usr.barred'; result.success := FALSE; @@ -421,6 +448,7 @@ BEGIN result.success := FALSE; done := TRUE; RETURN NEXT result; + -- Alternately, fail if the item isn't checked out on a renewal ELSIF renewal AND item_object.status <> 1 THEN result.fail_part := 'asset.copy.status'; result.success := FALSE; @@ -437,28 +465,6 @@ BEGIN RETURN NEXT result; END IF; - SELECT INTO circ_test * FROM action.find_circ_matrix_matchpoint(circ_ou, item_object, user_object, renewal); - - circ_matchpoint := circ_test.matchpoint; - result.matchpoint := circ_matchpoint.id; - result.circulate := circ_matchpoint.circulate; - result.duration_rule := circ_matchpoint.duration_rule; - result.recurring_fine_rule := circ_matchpoint.recurring_fine_rule; - result.max_fine_rule := circ_matchpoint.max_fine_rule; - result.hard_due_date := circ_matchpoint.hard_due_date; - result.renewals := circ_matchpoint.renewals; - result.grace_period := circ_matchpoint.grace_period; - result.buildrows := circ_test.buildrows; - - -- Fail if we couldn't find a matchpoint - IF circ_test.success = false THEN - result.fail_part := 'no_matchpoint'; - result.success := FALSE; - done := TRUE; - RETURN NEXT result; - RETURN; -- All tests after this point require a matchpoint. No sense in running on an incomplete or missing one. - END IF; - -- Apparently....use the circ matchpoint org unit to determine what org units are valid. SELECT INTO context_org_list ARRAY_ACCUM(id) FROM actor.org_unit_full_path( circ_matchpoint.org_unit ); @@ -533,7 +539,7 @@ BEGIN END IF; END LOOP; - -- If we passed everything, return the successful matchpoint id + -- If we passed everything, return the successful matchpoint IF NOT done THEN RETURN NEXT result; END IF;