Bug 20226 - Get rid of CATCODE_MULTI param decision in patron perl scripts
Summary: Get rid of CATCODE_MULTI param decision in patron perl scripts
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Jonathan Druart
QA Contact: Josef Moravec
URL:
Keywords:
: 21072 (view as bug list)
Depends on: 18789 20287
Blocks: 20813 21222 22928
  Show dependency treegraph
 
Reported: 2018-02-16 10:43 UTC by Josef Moravec
Modified: 2020-01-06 20:14 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Medium patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 20226: Centralize update child code (CATCODE_MULTI) (47.19 KB, patch)
2018-07-17 20:48 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 20226: Centralize update child code (CATCODE_MULTI) (46.93 KB, patch)
2018-07-19 12:32 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 20226: Centralize update child code (CATCODE_MULTI) (46.98 KB, patch)
2018-08-01 10:34 UTC, Josef Moravec
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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. ***