Bugzilla – Attachment 129371 Details for
Bug 22827
Automatic item modifications by age: add age depencency on other field(s) than dateaccessioned
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22827: Add age dependency on other fields than dateaccessioned
Bug-22827-Add-age-dependency-on-other-fields-than-.patch (text/plain), 11.16 KB, created by
Alex Buckley
on 2022-01-13 05:42:50 UTC
(
hide
)
Description:
Bug 22827: Add age dependency on other fields than dateaccessioned
Filename:
MIME Type:
Creator:
Alex Buckley
Created:
2022-01-13 05:42:50 UTC
Size:
11.16 KB
patch
obsolete
>From 3a5ea0d4406aa5080cb8b9260c8d8a16afdce388 Mon Sep 17 00:00:00 2001 >From: Alex Buckley <alexbuckley@catalyst.net.nz> >Date: Tue, 11 Jan 2022 15:11:37 +0000 >Subject: [PATCH] Bug 22827: Add age dependency on other fields than > dateaccessioned > >A new agefield has been added to the 'Automatic item modifications by >age' tool. The options for the agefield are: replacementpricedate, datelastborrowed, >datelastseen, damaged_on, itemlost_on, withdrawn_on > >If no option is selected then Koha will default to using >dateaccessioned. > >Test plan: > >1. Go to: Tools > Catalog > Automatic item modifications by age >2. Observe there is a new 'Age field' dropdown in the rule form. >3. Create a rule, set the values: >- 'Age in days' = 20 >- 'Substitutions': 'items.barcode' = 'test' >fields >- 'Age field' = 'items.datelastseen' >- Save the rule >4. Confirm the 'List of rules' page displays 'items.datelastseen' in the 'Age field' column >5. Add another rule: >- 'Age in days' = 1 >- 'Substitutions': 'items.barcode' = 'test2' >- Leave 'Age field' = 'Choose an age field' >- Save the rule >6. Confirm the 'List of rules' page displays 'items.dateaccesioned' in >the 'Age field' column for that second rule >7. Confirm you can delete rules >8. Edit a record: >- Make the items.dateaccessioned less than 20 days ago (so rule 1 is false) >- Make the items.datelastseen more than 1 day ago (so rule 2 is true) >9. Run the automatic_items_modification_by_age.pl: >- sudo koha-shell <instance> >- cd misc/cronjobs >- ./automatic_item_modification_by_age.pl -v >10. Confirm the item has it's barcode set to 'test2' >11. Run unit tests: >- sudo koha-shell <instance> >- cd t >- prove db_dependent/Item/AutomaticItemModificationByAge.t -v > >Sponsored-By: Catalyst IT >--- > C4/Items.pm | 3 +- > .../tools/automatic_item_modification_by_age.tt | 32 +++++++++++++++++++ > .../prog/js/automatic_item_modification_by_age.js | 1 + > .../Items/AutomaticItemModificationByAge.t | 36 +++++++++++++++++++++- > tools/automatic_item_modification_by_age.pl | 8 +++++ > 5 files changed, 78 insertions(+), 2 deletions(-) > >diff --git a/C4/Items.pm b/C4/Items.pm >index ce285577bd..144b874f12 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -1820,6 +1820,7 @@ sub ToggleNewStatus { > my $report; > for my $rule ( @rules ) { > my $age = $rule->{age}; >+ my $agefield = $rule->{agefield} ? $rule->{agefield} : 'items.dateaccessioned'; > my $conditions = $rule->{conditions}; > my $substitutions = $rule->{substitutions}; > foreach ( @$substitutions ) { >@@ -1851,7 +1852,7 @@ sub ToggleNewStatus { > } > } > if ( defined $age ) { >- $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |; >+ $query .= qq| AND TO_DAYS(NOW()) - TO_DAYS($agefield) >= ? |; > push @params, $age; > } > my $sth = $dbh->prepare($query); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt >index a6711c15af..35dbe2c6f6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/automatic_item_modification_by_age.tt >@@ -91,6 +91,20 @@ > <div class="age"> > <h5>Age in days</h5> > <input class="age" type="text" inputmode="numeric" pattern="[0-9]*" value="[% rule.age | html %]" name="age_[% id | html %]" /> >+ <h5>Age field</h5> >+ <div class="blocks"> >+ <select name="agefield_[% id | html %]"> >+ <option value="">Choose an age field</option> >+ [% FOR field IN agefields %] >+ [% IF rule.agefield == field %] >+ <option value="[% field | html %]" selected="selected">[% field | html %]</option> >+ [% ELSE %] >+ <option value="[% field | html %]">[% field | html %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ <span class="hint">If not set then items.dateaccessioned will be used</span> >+ </div> > </div> > <div class="blocks"> > <h5>Conditions</h5> >@@ -152,6 +166,16 @@ > <div class="age"> > <h5>Age in days</h5> > <input class="age" type="text" inputmode="numeric" pattern="[0-9]*" value="" name="age" /> >+ <h5>Age field</h5> >+ <div class="block"> >+ <select name="agefield"> >+ <option value="">Choose an age field</option> >+ [% FOR field IN agefields %] >+ <option value="[% field | html %]">[% field | html %]</option> >+ [% END %] >+ </select> >+ <span class="hint">If not set then items.dateaccessioned will be used</span> >+ </div> > </div> > <div class="blocks"> > <h5>Conditions</h5> >@@ -192,6 +216,7 @@ > <thead> > <tr> > <th>Age</th> >+ <th>Age field</th> > <th>Conditions</th> > <th>Substitutions</th> > </tr> >@@ -207,6 +232,13 @@ > [% END %] > </td> > <td> >+ [% IF rule.agefield %] >+ [% rule.agefield | html %] >+ [% ELSE %] >+ There is no age field for this rule. >+ [% END %] >+ </td> >+ <td> > [% FOR condition IN rule.conditions %] > [% IF condition.field %] > <div class="block"> >diff --git a/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js b/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js >index 6c37d9b210..09c4da1fc8 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/automatic_item_modification_by_age.js >@@ -75,6 +75,7 @@ $(document).ready(function() { > new_rule.find("input[name='condition_value']").attr('name', 'condition_value_' + unique_id); > new_rule.find("input[name='substitution_value']").attr('name', 'substitution_value_' + unique_id); > new_rule.find("input[name='age']").attr('name', 'age_' + unique_id); >+ new_rule.find("select[name='agefield']").attr('name', 'agefield_' + unique_id); > new_rule.find("input[name='unique_id']").val(unique_id); > > $("#rules").append(new_rule); >diff --git a/t/db_dependent/Items/AutomaticItemModificationByAge.t b/t/db_dependent/Items/AutomaticItemModificationByAge.t >index db162d6964..d21bcec8a4 100755 >--- a/t/db_dependent/Items/AutomaticItemModificationByAge.t >+++ b/t/db_dependent/Items/AutomaticItemModificationByAge.t >@@ -1,7 +1,7 @@ > #!/usr/bin/perl > > use Modern::Perl; >-use Test::More tests => 17; >+use Test::More tests => 19; > use MARC::Record; > use MARC::Field; > use DateTime; >@@ -296,6 +296,40 @@ C4::Items::ToggleNewStatus( { rules => \@rules } ); > $modified_item = Koha::Items->find( $itemnumber ); > is( $modified_item->new_status, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|); > >+# Play with the 'Age field' >+my $days2ago = $dt_today->add_duration( DateTime::Duration->new( days => -10 ) ); >+my $days20ago = $dt_today->add_duration( DateTime::Duration->new( days => -20 ) ); >+$modified_item->datelastseen($days2ago)->store; >+$modified_item->dateaccessioned($days20ago)->store; >+ >+# When agefield='items.datelastseen' >+@rules = ( >+ { >+ conditions => [ >+ { >+ field => 'biblioitems.itemtype', >+ value => 'ITEMTYPE_T', >+ }, >+ ], >+ substitutions => [ >+ { >+ field => 'items.new_status', >+ value => 'agefield_new_value', >+ }, >+ ], >+ age => '5', >+ agefield => 'items.datelastseen' >+ }, >+); >+C4::Items::ToggleNewStatus( { rules => \@rules } ); >+$modified_item = Koha::Items->find( $itemnumber ); >+is( $modified_item->new_status, 'agefield_new_value', q|ToggleNewStatus: Age = 5, agefield = 'items.datelastseen' : The new_status value is not updated|); >+ >+$rules[0]->{age} = 2; >+C4::Items::ToggleNewStatus( { rules => \@rules } ); >+$modified_item = Koha::Items->find( $itemnumber ); >+is( $modified_item->new_status, 'agefield_new_value', q|ToggleNewStatus: Age = 2, agefield = 'items.datelastseen' : The new_status value is updated|); >+ > # Run twice > t::lib::Mocks::mock_preference('CataloguingLog', 1); > my $actions_nb = $schema->resultset('ActionLog')->count(); >diff --git a/tools/automatic_item_modification_by_age.pl b/tools/automatic_item_modification_by_age.pl >index 3693f318f4..a3138091d3 100755 >--- a/tools/automatic_item_modification_by_age.pl >+++ b/tools/automatic_item_modification_by_age.pl >@@ -3,6 +3,7 @@ > # This file is part of Koha. > # > # Copyright 2013 BibLibre >+# Copyright 2021 Catalyst IT > # > # Koha is free software; you can redistribute it and/or modify it > # under the terms of the GNU General Public License as published by >@@ -65,6 +66,7 @@ if ( $op eq 'update' ) { > my @substitution_values = $cgi->multi_param("substitution_value_$unique_id"); > my @condition_fields = $cgi->multi_param("condition_field_$unique_id"); > my @condition_values = $cgi->multi_param("condition_value_$unique_id"); >+ my @age_fields = $cgi->multi_param("agefield_$unique_id"); > my $rule = { > substitutions => [], > conditions => [], >@@ -84,6 +86,10 @@ if ( $op eq 'update' ) { > push @{ $rule->{conditions} }, {} > unless @{ $rule->{conditions} }; > $rule->{age} = $cgi->param("age_$unique_id"); >+ >+ for my $age_field ( @age_fields ) { >+ $rule->{agefield} = $age_field ? $age_field : "items.dateaccessioned"; >+ } > push @rules, $rule; > } > my $syspref_content = to_json( \@rules ); >@@ -109,9 +115,11 @@ if ( $@ ) { > > my @item_fields = map { "items.$_" } Koha::Items->columns; > my @biblioitem_fields = map { "biblioitems.$_" } Koha::Biblioitems->columns; >+my @age_fields = ('items.dateaccessioned', 'items.replacementpricedate', 'items.datelastborrowed', 'items.datelastseen', 'items.damaged_on', 'items.itemlost_on', 'items.withdrawn_on'); > $template->param( > op => $op, > messages => \@messages, >+ agefields => [ @age_fields ], > condition_fields => [ @item_fields, @biblioitem_fields ], > substitution_fields => \@item_fields, > rules => $rules, >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22827
:
129371
|
129460
|
129481
|
132265