Bugzilla – Attachment 138895 Details for
Bug 21173
Add hours as age unit to auto item modifications by age for damaged_on, itemlost_on and withdrawn_on fields
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21173: Add Hours as an age unit to auto item modifications by age
Bug-21173-Add-Hours-as-an-age-unit-to-auto-item-mo.patch (text/plain), 5.35 KB, created by
Alex Buckley
on 2022-08-09 11:14:50 UTC
(
hide
)
Description:
Bug 21173: Add Hours as an age unit to auto item modifications by age
Filename:
MIME Type:
Creator:
Alex Buckley
Created:
2022-08-09 11:14:50 UTC
Size:
5.35 KB
patch
obsolete
>From 3794eedddd02c4d6eba2ed587af8bc39c30151de Mon Sep 17 00:00:00 2001 >From: Alex Buckley <alexbuckley@catalyst.net.nz> >Date: Mon, 8 Aug 2022 13:41:40 +0000 >Subject: [PATCH] Bug 21173: Add Hours as an age unit to auto item > modifications by age > >items.damaged_on, items.itemlost_on, and items.withdrawn_on are datetime fields, so it could be >useful to configure rules based on the number of hours since these values. > >All other fields in the automatic item modifications by age tool will >use the days unit. > >Test plan: >1. Go to Tools->Automatic item modifications by age > >2. Create a new rule > >3. Apply patches and restart services > >4. Confirm the rule you created has an 'Age unit' displayed of 'Days' > >5. Edit the existing rule. Notice if your 'Age field' is not set to items.damaged_on, >items.itemlost_on or items.withdrawn_on then the 'Age unit' dropdown is disabled > >6. Confirm if you try to save a rule with age unit = 'Hours' and a field >other than items.damaged_on, items.itemlost_on, or items.withdrawn_on >then the 'List of rules' table shows that rule with the unit of >'Days' > >7. Click 'Add rule'. Observe the 'Age unit' dropdown is initially disabled and set >to 'Days' until you change the 'Age field' dropdown to items.damaged_on, >items.itemlost_on, or items.withdrawn_on > >8. Save the rule: >Age: 1 >Age unit: Hours >Age field: items.itemlost_on >Conditions: items.barcode = TEST >Substitutions: items.barcode = TEST1 > >9. Find an item. Set it's barcode to TEST. In the database change it's >items.itemlost_on to more than 1 hour ago > >10. Restart services > >11. Run the automatic_item_modification_by_age.pl script: >sudo koha-shell kohadev >./misc/cronjobs/automatic_item_modification_by_age.pl -c > >12. Confirm the item's barcode has changed to TEST1 > >Sponsored-by: Toi Ohomai Institute of Technology, New Zealand >--- > C4/Items.pm | 17 ++++++++++++++++- > tools/automatic_item_modification_by_age.pl | 14 ++++++++++++++ > 2 files changed, 30 insertions(+), 1 deletion(-) > >diff --git a/C4/Items.pm b/C4/Items.pm >index 443242be5d9..ae3b7d1d3e5 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -1828,6 +1828,9 @@ sub ToggleNewStatus { > my $report; > for my $rule ( @rules ) { > my $age = $rule->{age}; >+ # Default to using Days if there's an old item modification rule >+ # missing an ageunit value >+ my $unit = $rule->{ageunit} ? $rule->{ageunit} : 'Days'; > # Default to using items.dateaccessioned if there's an old item modification rule > # missing an agefield value > my $agefield = $rule->{agefield} ? $rule->{agefield} : 'items.dateaccessioned'; >@@ -1863,7 +1866,19 @@ sub ToggleNewStatus { > } > } > if ( defined $age ) { >- $query .= qq| AND TO_DAYS(NOW()) - TO_DAYS($agefield) >= ? |; >+ if ( defined $rule >+ && $unit eq "Hours" >+ && ( >+ $agefield eq "items.damaged_on" >+ || $agefield eq "items.itemlost_on" >+ || $agefield eq "items.withdrawn_on" ) >+ ) { >+ # Calculate item age based on hours since damaged_on, itemlost_on, withdrawn_on >+ $query .= qq| AND HOUR(TIMEDIFF(NOW(), $agefield)) >= ? |; >+ } else { >+ # Calculate item age based on days >+ $query .= qq| AND TO_DAYS(NOW()) - TO_DAYS($agefield) >= ? |; >+ } > push @params, $age; > } > my $sth = $dbh->prepare($query); >diff --git a/tools/automatic_item_modification_by_age.pl b/tools/automatic_item_modification_by_age.pl >index a3138091d31..e149d503bac 100755 >--- a/tools/automatic_item_modification_by_age.pl >+++ b/tools/automatic_item_modification_by_age.pl >@@ -67,6 +67,7 @@ if ( $op eq 'update' ) { > 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 @age_units = $cgi->multi_param("ageunit_$unique_id"); > my $rule = { > substitutions => [], > conditions => [], >@@ -90,6 +91,17 @@ if ( $op eq 'update' ) { > for my $age_field ( @age_fields ) { > $rule->{agefield} = $age_field ? $age_field : "items.dateaccessioned"; > } >+ >+ for my $age_unit ( @age_units ) { >+ if ($rule->{agefield} ne 'items.damaged_on' >+ && $rule->{agefield} ne 'items.itemlost_on' >+ && $rule->{agefield} ne 'items.withdrawn_on') { >+ $rule->{ageunit} = "Days"; >+ } else { >+ $rule->{ageunit} = $age_unit ? $age_unit : "Days"; >+ } >+ } >+ > push @rules, $rule; > } > my $syspref_content = to_json( \@rules ); >@@ -116,9 +128,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'); >+my @age_units = ('Hours', 'Days'); > $template->param( > op => $op, > messages => \@messages, >+ ageunits => [ @age_units ], > agefields => [ @age_fields ], > condition_fields => [ @item_fields, @biblioitem_fields ], > substitution_fields => \@item_fields, >-- >2.20.1
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 21173
:
77547
|
77548
|
77604
|
77605
|
78917
|
79914
|
138870
|
138871
|
138872
|
138894
|
138895
|
138896
|
156137
|
156138
|
156139
|
158574
|
158575
|
160715
|
160716