From 6fe356b6e944a97e5db38cd749f5177bf10f4e9d Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 8 Jan 2016 19:41:52 +0000 Subject: [PATCH] Bug 14576 - Allow arbitrary automatic update of location on checkin This patch adds a new syspref "UpdateItemLocationOnCheckin" which accepts pairs of shelving locations. On check-in the items location is compared ot the location on the left and, if it matches, is updated to the location on the left. Test Plan: 1) Apply this patch 2) Run updatedatabase.pl 3) Set the new system preference UpdateitemLocationOnCheckin to the following (assuming sample data): NEW: FIC FIC: GEN 4) Create an item, set its location to NEW 5) Check in the item, note its location is now FIC 6) Check in the item again, note its location is now GEN 7) Check in the item again, note its location remains GEN --- C4/Circulation.pm | 19 +++++++++++++++++++ circ/returns.pl | 3 +++ ..._14576-add_UpdateItemLocationOnCheckin_syspref.sql | 1 + installer/data/mysql/sysprefs.sql | 1 + .../en/modules/admin/preferences/circulation.pref | 7 +++++++ .../intranet-tmpl/prog/en/modules/circ/returns.tt | 13 +++++++++++++ 6 files changed, 44 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_14576-add_UpdateItemLocationOnCheckin_syspref.sql diff --git a/C4/Circulation.pm b/C4/Circulation.pm index ae53366..5a94558 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1852,6 +1852,25 @@ sub AddReturn { my $borrowernumber = $borrower->{'borrowernumber'} || undef; # we don't know if we had a borrower or not + my $yaml = C4::Context->preference('UpdateItemLocationOnCheckin'); + if ($yaml) { + $yaml = "$yaml\n\n"; # YAML is anal on ending \n. Surplus does not hurt + my $rules; + eval { $rules = YAML::Load($yaml); }; + if ($@) { + warn "Unable to parse UpdateItemLocationOnCheckin syspref : $@"; + } + else { + foreach my $key ( keys %$rules ) { + if ( $item->{location} eq $key ) { + $messages->{'ItemLocationUpdated'} = { from => $item->{location}, to => $rules->{$key} }; + ModItem( { location => $rules->{$key} }, undef, $itemnumber ); + last; + } + } + } + } + my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin'); if ($yaml) { $yaml = "$yaml\n\n"; # YAML is anal on ending \n. Surplus does not hurt diff --git a/circ/returns.pl b/circ/returns.pl index f7fb52c..141070b 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -523,6 +523,9 @@ foreach my $code ( keys %$messages ) { elsif ( $code eq 'ForeverDebarred' ) { $err{foreverdebarred} = $messages->{'ForeverDebarred'}; } + elsif ( $code eq 'ItemLocationUpdated' ) { + $err{ItemLocationUpdated} = $messages->{ItemLocationUpdated}; + } elsif ( $code eq 'NotForLoanStatusUpdated' ) { $err{NotForLoanStatusUpdated} = $messages->{NotForLoanStatusUpdated}; } diff --git a/installer/data/mysql/atomicupdate/bug_14576-add_UpdateItemLocationOnCheckin_syspref.sql b/installer/data/mysql/atomicupdate/bug_14576-add_UpdateItemLocationOnCheckin_syspref.sql new file mode 100644 index 0000000..1849702 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_14576-add_UpdateItemLocationOnCheckin_syspref.sql @@ -0,0 +1 @@ +INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES('UpdateItemLocationOnCheckin', '', 'NULL', 'This a list of value pairs. When an item is checked in, if the location value on the left matches the items location value it will be updated to the right-hand value. E.g. ''PROC: FIC'' will cause an item that was set to ''Book Cart'' to now be in the ''Fiction'' shelving location. Each pair of values should be on a separate line.', 'Free'); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index aa53139..11285f0 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -482,6 +482,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('UNIMARCAuthorsFacetsSeparator',', ',NULL,'UNIMARC authors facets separator','short'), ('UNIMARCField100Language','fre',NULL,'UNIMARC field 100 default language','short'), ('UniqueItemFields','barcode','','Space-separated list of fields that should be unique (used in acquisition module for item creation). Fields must be valid SQL column names of items table','Free'), +('UpdateItemLocationOnCheckin', '', 'NULL', 'This is a list of value pairs. When an item is checked in, if the location value on the left matches the items location value it will be updated to the right-hand value. E.g. ''PROC: FIC'' will cause an item that was set to ''Book Cart'' to now be in the ''Fiction'' shelving location. Each pair of values should be on a separate line.', 'Free'), ('UpdateNotForLoanStatusOnCheckin', '', 'NULL', 'This is a list of value pairs. When an item is checked in, if the not for loan value on the left matches the items not for loan value it will be updated to the right-hand value. E.g. ''-1: 0'' will cause an item that was set to ''Ordered'' to now be available for loan. Each pair of values should be on a separate line.', 'Free'), ('UpdateTotalIssuesOnCirc','0',NULL,'Whether to update the totalissues field in the biblio on each circ.','YesNo'), ('uppercasesurnames','0',NULL,'If ON, surnames are converted to upper case in patron entry form','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index d9c7e25..2211dbc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -423,6 +423,13 @@ Circulation: - calculate and update overdue charges when an item is returned. -
NOTE If you are doing hourly loans then you should have this on. - + - pref: UpdateItemLocationOnCheckin + type: textarea + class: code + - This is is a list of value pairs. When an item is checked in, if the location value on the left matches the items location value + - "it will be updated to the right-hand value. E.g. ''PROC: FIC'' will cause an item that was set to ''Book Cart'' to now be in the ''Fiction'' shelving location. " + - Each pair of values should be on a separate line. + - - pref: UpdateNotForLoanStatusOnCheckin type: textarea class: code diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index 5895b60..b4fcdaf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -426,6 +426,19 @@ $(document).ready(function () { [% END %]

[% END %] + [% IF ( errmsgloo.ItemLocationUpdated ) %] +

+ Item location updated + from + [% IF errmsgloo.ItemLocationUpdated.from %] + [% AuthorisedValues.GetByCode( 'LOC', errmsgloo.ItemLocationUpdated.from ) %] + [% END %] + to + [% IF errmsgloo.ItemLocationUpdated.to %] + [% AuthorisedValues.GetByCode( 'LOC', errmsgloo.ItemLocationUpdated.to ) %] + [% END %] +

+ [% END %] [% IF ( errmsgloo.badbarcode ) %]

No item with barcode: [% errmsgloo.msg %]

[% END %] -- 2.1.4