wiki:indb

Migrating from Scripts to INDB Rules

Some circulation actions are controlled by scripts in /openils/var/circ:

circ_duration_CRC.js	     circ_duration_OSM.js      circ_groups.js
circ_duration_HUNTINGTON.js  circ_duration_OSTMA.js    circ_item_config.js
circ_duration.js	     circ_duration_OSUL.js     circ_lib.js
circ_duration_MRC.js	     circ_duration_OWA.js      circ_permit_copy.js
circ_duration_NOSME.js	     circ_duration_OWAL.js     circ_permit_hold.js
circ_duration_NOSMW.js	     circ_duration_SJCG.js     circ_permit_patron.js
circ_duration_OSBO.js	     circ_duration_SUDBURY.js  circ_permit_renew.js

A more manageable approach is to use in-database or INDB rules. This allows rules to be controlled from the staff client and activated/de-activated as needed. We will tackle a simple example first. The circ_permit_renew.js script blocks renewals on items already checked out.

function go() {

/* load the lib script */
load_lib('circ/circ_lib.js');
load_lib('JSON_v1.js');
log_vars('circ_permit_renew');

//from Jason Etheridge's suggestion on OPEN-ILS-GENERAL, Dec. 23, 2009
log_info("permit_renew searching for potential holds for copy " + copy.barcode)
var hold = copy.fetchBestHold();
if( hold ) {
    log_info("hold found for renewal item, checking hold->usr..");
    if( hold && hold.usr != patron.id ) {
        return result.events.push('COPY_NEEDED_FOR_HOLD');
    }
}

} go();

In other words, if someone has placed a hold on an item, a hold should not be allowed. The INDB rules are documented here:

http://open-ils.org/dokuwiki/doku.php?id=evergreen-admin:customization:indb-circ

There is a set of database table columns to calculate match values and another set to determine if the circulation transaction is allowed. The column value that is of interest in this case is available_copy_hold_ratio which is the the ratio of available copies to holds. We want the INDB rule to deny a hold request if the ratio is less than 1, which would mean that a hold is being requested on an item that is not available. The rules can be set from the staff client in Admin->Local Administration->Circulation Policies.

To test this we have Patron1 check out a book so that Patron2 can place a hold on it. In this case, the result started with a network error.

Exception: OpenSRF::EX 2012-08-01T15:20:08 OpenSRF::Application /usr/local/share/perl/5.14.2/OpenSRF/Application.pm:211 : Bad event name:

By setting the log level in /openils/conf/opensrf_core.xml, the error is related to the action.copy_related_hold_stats procedure.

open-ils.cstore 2012-08-01 15:50:11 [ERR :13297:oils_sql.c:5545:] open-ils.cstore: Error with query [SELECT * FROM action.item_user_renew_test( '4', '1', '3' ) AS "action.item_user_renew_test" ;]: 0 ERROR:  function action.copy_related_hold_stats(bigint) does not exist
LINE 1: SELECT                 * FROM action.copy_related_hold_stats...
                                      ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
QUERY:  SELECT                 * FROM action.copy_related_hold_stats(match_item)
CONTEXT:  PL/pgSQL function "item_user_circ_test" line 155 at SQL statement
SQL function "item_user_renew_test" statement 1

As a quick workaround, we add a bigint version of action.copy_related_hold_stats. The circulation action can be tested directly in the database:

SELECT * FROM action.item_user_renew_test( 4, 1, 3 ) AS "action.item_user_renew_test" ;

 success |                     fail_part                     | buildrows | matchpoint | circulate | duration_rule | recurring_fine_rule | max_fine_rule | hard_due_date | renewals | grace_period | limit_groups 
---------+---------------------------------------------------+-----------+------------+-----------+---------------+---------------------+---------------+---------------+----------+--------------+--------------
 f       | config.circ_matrix_test.available_copy_hold_ratio | {3,1}     |          3 | t         |            11 |                   1 |             1 |               |          |              | 
(1 row)

This brings about the desired result in the catalogue when Patron1 tries to place a renew an item that has a hold from Patron2.

Last modified 8 years ago Last modified on Aug 1, 2012, 11:47:14 PM

Attachments (2)

Download all attachments as: .zip