Bug 20226

Summary: Get rid of CATCODE_MULTI param decision in patron perl scripts
Product: Koha Reporter: Josef Moravec <josef.moravec>
Component: Architecture, internals, and plumbingAssignee: Jonathan Druart <jonathan.druart>
Status: CLOSED FIXED QA Contact: Josef Moravec <josef.moravec>
Severity: enhancement    
Priority: P5 - low CC: jonathan.druart, martin.renvoize, nick
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20805
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=21072
Change sponsored?: --- Patch complexity: Medium patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 18789, 20287    
Bug Blocks: 20813, 21222, 22928    
Attachments: Bug 20226: Centralize update child code (CATCODE_MULTI)
Bug 20226: Centralize update child code (CATCODE_MULTI)
Bug 20226: Centralize update child code (CATCODE_MULTI)

Description Josef Moravec 2018-02-16 10:43:20 UTC
In all scripts for patrons management are this few lines of code:

if ( $patron->is_child) {
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
    $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
}

This is needed only in members-toolbar.inc for updating child to adult.

I don't think it is good idea to have these 5 lines of code repeated 10 times in our code. Should be refactored and centralized.
Comment 1 Jonathan Druart 2018-07-17 20:48:09 UTC Comment hidden (obsolete)
Comment 2 Owen Leonard 2018-07-19 12:32:18 UTC
Created attachment 77103 [details] [review]
Bug 20226: Centralize update child code (CATCODE_MULTI)

Code and variables to deal with the update child feature are not
centralized but copied/pasted in several scripts. Which leads to issues
obsviously (bug 20805 for instance).

Moreover the strings used by the templates are also in several template
files (or .inc)

To deal with that this patch introduces the idea to create 1 .inc file
per .js file
Here we have members-menu.inc for members-menu.js

Test plan:
- Remove all your adult categories (categories.category_type='A')
- Create a patron with a child category
- Try to update to adult category
=> The entry does no longer appears! (This is a change in the behaviour)
- Create one adult category
- Update to adult category
=> There is a JS confirmation message, if you accept the patron will
be updated to the adult category
- Create (at least) another adult category
- Create another child
- Update to adult category
=> No more confirmation message but a popup to select the adult category
- Pick one
=> The patron has been updated to the adult category

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 3 Josef Moravec 2018-08-01 10:34:45 UTC
Created attachment 77359 [details] [review]
Bug 20226: Centralize update child code (CATCODE_MULTI)

Code and variables to deal with the update child feature are not
centralized but copied/pasted in several scripts. Which leads to issues
obsviously (bug 20805 for instance).

Moreover the strings used by the templates are also in several template
files (or .inc)

To deal with that this patch introduces the idea to create 1 .inc file
per .js file
Here we have members-menu.inc for members-menu.js

Test plan:
- Remove all your adult categories (categories.category_type='A')
- Create a patron with a child category
- Try to update to adult category
=> The entry does no longer appears! (This is a change in the behaviour)
- Create one adult category
- Update to adult category
=> There is a JS confirmation message, if you accept the patron will
be updated to the adult category
- Create (at least) another adult category
- Create another child
- Update to adult category
=> No more confirmation message but a popup to select the adult category
- Pick one
=> The patron has been updated to the adult category

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 4 Nick Clemens (kidclamp) 2018-08-14 12:54:35 UTC
Awesome work all!

Pushed to master for 18.11
Comment 5 Jonathan Druart 2018-08-14 19:02:00 UTC
Patron's creation is broken!

Template process failed: undef error - DBIC result _type  isn't of the _type Category at /home/vagrant/kohaclone/koha-tmpl/intranet-tmpl/prog/en/includes/str/members-menu.inc line 22.
Comment 6 Martin Renvoize (ashimema) 2018-08-16 10:36:36 UTC
Enhancement, will not be backported to 18.05.x series.
Comment 7 Jonathan Druart 2019-05-16 14:37:15 UTC
*** Bug 21072 has been marked as a duplicate of this bug. ***