Bug 25712

Summary: Add plugin hooks to transform patron and item barcodes
Product: Koha Reporter: Kyle M Hall <kyle>
Component: Plugin architectureAssignee: Kyle M Hall <kyle>
Status: RESOLVED MOVED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: andrewfh, dcook, lucas
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=26351
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on: 24031    
Bug Blocks:    
Attachments: Bug 25712: Add plugin hooks to transform patron and item barcodes
Bug 25712: Add plugin hooks to transform patron and item barcodes
Bug 25712: Add plugin hooks to transform patron and item barcodes
Bug 25712: Add plugin hooks to transform patron and item barcodes
Bug 25712: (QA follow-up) Fix QA script warnings
Bug 25712: Add plugin hooks to transform patron and item barcodes
Bug 25712: (QA follow-up) Fix QA script warnings

Description Kyle M Hall 2020-06-11 12:14:27 UTC
Some of our partners have unusual barcode requirements that have required us to transform scanned barcodes using javascript. This is not the most reliable method. It would make more sense to have Koha transform the barcodes on the backend using a plugin. We should add hooks to transform and generate new item and patron barcodes.
Comment 1 Kyle M Hall 2020-07-06 12:16:48 UTC
Created attachment 106577 [details] [review]
Bug 25712: Add plugin hooks to transform patron and item barcodes

Some of our partners have unusual barcode requirements that have
required us to transform scanned barcodes using javascript. This is not
the most reliable method. It would make more sense to have Koha
transform the barcodes on the backend using a plugin. We should add
hooks to transform and generate new item and patron barcodes.
Comment 2 Kyle M Hall 2020-07-06 12:24:12 UTC
Created attachment 106578 [details] [review]
Bug 25712: Add plugin hooks to transform patron and item barcodes

Some of our partners have unusual barcode requirements that have
required us to transform scanned barcodes using javascript. This is not
the most reliable method. It would make more sense to have Koha
transform the barcodes on the backend using a plugin. We should add
hooks to transform and generate new item and patron barcodes.

Test Plan:
1) Apply this patch
2) Download and install the Barcode Transformer plugin
   https://github.com/bywatersolutions/koha-plugin-barcode-transformer/releases/download/v1.0.1/koha-plugin-barcode-transformer-v1.0.1.kpz
3) Go to the plugin configuration page, set the configuration to the example configuration from the same page
4) In the patron search and anywhere else you can scan a patron
cardnumber, type in some cardnumbers but prefix them with A and postfix
them with A or B, e.g. A12345A, A12345B
5) Note the letters are removed by Koha!
6) Try a cardnumber like X123456Y
7) Note Koha converts it to Z13456Z
8) Try an item barcode now with the same A A|B format from step 4
9) The item barcode should have the letters removed by Koha as well!
Comment 3 Kyle M Hall 2020-07-06 12:41:30 UTC
Created attachment 106579 [details] [review]
Bug 25712: Add plugin hooks to transform patron and item barcodes

Some of our partners have unusual barcode requirements that have
required us to transform scanned barcodes using javascript. This is not
the most reliable method. It would make more sense to have Koha
transform the barcodes on the backend using a plugin. We should add
hooks to transform and generate new item and patron barcodes.

Test Plan:
1) Apply this patch
2) Download and install the Barcode Transformer plugin
   https://github.com/bywatersolutions/koha-plugin-barcode-transformer/releases/
3) Go to the plugin configuration page, set the configuration to the example configuration from the same page
4) In the patron search and anywhere else you can scan a patron
cardnumber, type in some cardnumbers but prefix them with A and postfix
them with A or B, e.g. A12345A, A12345B
5) Note the letters are removed by Koha!
6) Try a cardnumber like X123456Y
7) Note Koha converts it to Z13456Z
8) Try an item barcode now with the same A A|B format from step 4
9) The item barcode should have the letters removed by Koha as well!
Comment 4 Andrew Fuerste-Henry 2020-07-17 18:22:29 UTC
Patch doesn't apply. Thanks!
Comment 5 Katrin Fischer 2020-07-18 17:54:32 UTC
Can you please update https://wiki.koha-community.org/wiki/Koha_Plugin_Hooks too? Thanks!
Comment 6 Kyle M Hall 2020-07-20 18:38:49 UTC
Created attachment 107125 [details] [review]
Bug 25712: Add plugin hooks to transform patron and item barcodes

Some of our partners have unusual barcode requirements that have
required us to transform scanned barcodes using javascript. This is not
the most reliable method. It would make more sense to have Koha
transform the barcodes on the backend using a plugin. We should add
hooks to transform and generate new item and patron barcodes.

Test Plan:
1) Apply this patch
2) Download and install the Barcode Transformer plugin
   https://github.com/bywatersolutions/koha-plugin-barcode-transformer/releases/
3) Go to the plugin configuration page, set the configuration to the example configuration from the same page
4) In the patron search and anywhere else you can scan a patron
cardnumber, type in some cardnumbers but prefix them with A and postfix
them with A or B, e.g. A12345A, A12345B
5) Note the letters are removed by Koha!
6) Try a cardnumber like X123456Y
7) Note Koha converts it to Z13456Z
8) Try an item barcode now with the same A A|B format from step 4
9) The item barcode should have the letters removed by Koha as well!
Comment 7 Lucas Gass 2020-08-18 15:59:54 UTC
Works awesome! The QA tool raised a few issues:

 OK	C4/Circulation.pm
 OK	C4/ILSDI/Services.pm
 OK	C4/Items.pm
 OK	C4/SIP/Sip/MsgType.pm
 OK	Koha/Item.pm
 OK	Koha/Patron.pm
 OK	Koha/Patron/Attribute.pm
 FAIL	cataloguing/additem.pl
   FAIL	  valid
		Global symbol "$addedolditem" requires explicit package name (did you forget to declare "my $addedolditem"?)
		Global symbol "$addedolditem" requires explicit package name (did you forget to declare "my $addedolditem"?)

 OK	circ/circulation.pl
 OK	circ/returns.pl
 OK	members/memberentry.pl
 OK	offline_circ/process_koc.pl
 OK	opac/sco/sco-main.pl
 OK	t/db_dependent/Koha/Plugins/Plugins.t
 FAIL	t/lib/Koha/Plugin/Test.pm
   FAIL	  critic
		# Variables::ProhibitUnusedVariables: Got 1 violation(s).

 FAIL	tools/batchMod.pl
   FAIL	  valid
		Global symbol "$barcode" requires explicit package name (did you forget to declare "my $barcode"?)
		tools/batchMod.pl had compilation errors.

 OK	tools/inventory.pl
Comment 8 Kyle M Hall 2020-08-21 15:05:24 UTC
Created attachment 108831 [details] [review]
Bug 25712: (QA follow-up) Fix QA script warnings
Comment 9 Kyle M Hall 2020-08-21 15:06:31 UTC
(In reply to Lucas Gass from comment #7)
>  FAIL	cataloguing/additem.pl
>    FAIL	  valid
> 		Global symbol "$addedolditem" requires explicit package name (did you
> forget to declare "my $addedolditem"?)
> 		Global symbol "$addedolditem" requires explicit package name (did you
> forget to declare "my $addedolditem"?)

Fixed!

>  FAIL	t/lib/Koha/Plugin/Test.pm
>    FAIL	  critic
> 		# Variables::ProhibitUnusedVariables: Got 1 violation(s).

This one's a false alarm and can be ignored.
 
>  FAIL	tools/batchMod.pl
>    FAIL	  valid
> 		Global symbol "$barcode" requires explicit package name (did you forget to
> declare "my $barcode"?)
> 		tools/batchMod.pl had compilation errors.

Fixed!
Comment 10 Lucas Gass 2020-08-24 23:33:35 UTC
Created attachment 109051 [details] [review]
Bug 25712: Add plugin hooks to transform patron and item barcodes

Some of our partners have unusual barcode requirements that have
required us to transform scanned barcodes using javascript. This is not
the most reliable method. It would make more sense to have Koha
transform the barcodes on the backend using a plugin. We should add
hooks to transform and generate new item and patron barcodes.

Test Plan:
1) Apply this patch
2) Download and install the Barcode Transformer plugin
   https://github.com/bywatersolutions/koha-plugin-barcode-transformer/releases/
3) Go to the plugin configuration page, set the configuration to the example configuration from the same page
4) In the patron search and anywhere else you can scan a patron
cardnumber, type in some cardnumbers but prefix them with A and postfix
them with A or B, e.g. A12345A, A12345B
5) Note the letters are removed by Koha!
6) Try a cardnumber like X123456Y
7) Note Koha converts it to Z13456Z
8) Try an item barcode now with the same A A|B format from step 4
9) The item barcode should have the letters removed by Koha as well!

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 11 Lucas Gass 2020-08-24 23:33:38 UTC
Created attachment 109052 [details] [review]
Bug 25712: (QA follow-up) Fix QA script warnings

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 12 Katrin Fischer 2020-08-29 11:16:47 UTC
I feel like this might have been better as 2 patches - cardnumbers and item barcodes separately. It touches a lot of the code, including SIP2, offline circulation etc.

 With this patch applied, but without any plugin installed:

1) When a barcode is not found, there is no error message, but only a page reload.

2) A patron search with the correct cardnumber (42 for sample data) in the checkout tab no longer brings up the patron.

I think maybe we need to check for a plugin installed?
Comment 13 Kyle M Hall 2020-09-02 13:36:21 UTC
Moved to bugs 26351 and 26352