Bug 21173 - Add hours as age unit to auto item modifications by age for damaged_on, itemlost_on and withdrawn_on fields
Summary: Add hours as age unit to auto item modifications by age for damaged_on, iteml...
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Tools (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Alex Buckley
QA Contact: Katrin Fischer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-08 00:56 UTC by Alex Buckley
Modified: 2024-03-08 20:25 UTC (History)
5 users (show)

See Also:
Change sponsored?: Sponsored
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
You can now define rules with the age unit of 'Hours' or 'Days' for the fields items.damaged_on, items.itemlost_on, or items.withdrawn_on in the 'Automatic item modification by age' tool. This means you can now automatically modify items based on the number of hours since they were marked damaged, lost, or withdrawn. You may need to ask your system administrator to configure the automatic_item_modification_by_age.pl cronjob to run more than once a day if you create rules with the age unit of 'Hours'.


Attachments
Bug 21173 - Customize age unit and starting point for automatic item modification by age tool and cronjob. (14.23 KB, patch)
2018-08-08 00:59 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173 - Fixed 2 template and SQL typos (2.87 KB, patch)
2018-08-08 03:33 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173 - Customize age unit and starting point for automatic item modification by age tool and cronjob. (17.61 KB, patch)
2018-08-08 22:55 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173 - Customize age unit and starting point for automatic item modification by age tool and cronjob. (17.61 KB, patch)
2018-08-08 23:22 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173 - Customize age unit and starting point for automatic item modification by age tool and cronjob. (18.13 KB, patch)
2018-09-16 00:34 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173: Fixed rebase removal of filters and changed items.dateaccessioned to datetime datatype (12.65 KB, patch)
2018-10-04 04:55 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173: Template and JavaScript changes (8.44 KB, patch)
2022-08-09 04:49 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173: Add Hours as an age unit to auto item modifications by age (5.54 KB, patch)
2022-08-09 04:49 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173: Unit tests (3.27 KB, patch)
2022-08-09 04:50 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173: Template and JavaScript changes (8.20 KB, patch)
2022-08-09 11:14 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173: Add Hours as an age unit to auto item modifications by age (5.35 KB, patch)
2022-08-09 11:14 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173: Unit tests (3.27 KB, patch)
2022-08-09 11:15 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173: Template and JavaScript changes (8.25 KB, patch)
2023-09-25 00:50 UTC, David Nind
Details | Diff | Splinter Review
Bug 21173: Add Hours as an age unit to auto item modifications by age (5.40 KB, patch)
2023-09-25 00:50 UTC, David Nind
Details | Diff | Splinter Review
Bug 21173: Unit tests (3.32 KB, patch)
2023-09-25 00:50 UTC, David Nind
Details | Diff | Splinter Review
Bug 21173: (follow-up) Perltidy (7.70 KB, patch)
2023-11-06 22:15 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173: (follow-up) Re-ordering input fields in item modification by age form (6.09 KB, patch)
2023-11-06 22:15 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 21173: (follow-up) Re-ordering input fields in item modification by age form (6.15 KB, patch)
2024-01-09 18:32 UTC, Matthias Le Gac
Details | Diff | Splinter Review
Bug 21173: (follow-up) Re-ordering input fields in item modification by age form (6.15 KB, patch)
2024-01-09 18:49 UTC, Phan Tung Bui
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Buckley 2018-08-08 00:56:03 UTC
Make auto item modification by age cronjob run more often than once daily. Setting this cronjob to run every hour will be set in the /etc/cron.hourly/koha-common.

However 2 further changes to the automatic item modification tool to make an hourly running cronjob useful. 

1. Be able to set the age of the item in hours not just days. This is so an hourly cronjob has items to alter because items will exceed the age limit more frequently than if the item age is in hours. 

2. Give the user the choice of what the age starting point (time from which the age of the item is calculated) used in the cronjob is. The two possible age starting points that users have to choose between are:

* Item creation (this is the age starting point in master currently)
* Item last altered

This is so items whic have been in the catalogue for a while can still be affected by the automatic item modification by age cronjob.
Comment 1 Alex Buckley 2018-08-08 00:59:08 UTC
Created attachment 77547 [details] [review]
Bug 21173 - Customize age unit and starting point for automatic item modification by age tool and cronjob.

This allows librarians to define either the item creation date or items
last altered timestamp as the starting point for the age of the item so
the autmatic_item_modification_by_age.pl can alter item statuses for
example for items which have been in the catalogue for a while.

A use case for this functionality is:
* When an items shelving location changes from 'In processing' to 'Shelving trolley' after 1 hour the status 'Shelving trolley' is removed for the item. The unit 'Hours' can now be set (extending the functionality of this cronjob from just calculating item age in days) and the age starting point of 'Last altered' can be defined so existing items in the catalogue like this example item will be altered by the cronjob.

Sponsored-By: Toi Ohomai Institute of Technology, New Zealand
Comment 2 Alex Buckley 2018-08-08 03:33:25 UTC
Created attachment 77548 [details] [review]
Bug 21173 - Fixed 2 template and SQL typos
Comment 3 Katrin Fischer 2018-08-08 11:42:18 UTC
I understand this is an enh to the tool, that might be generally helfpul. 

But was wondering because of the given use case, if misc / cronjobs / cart_to_shelf.pl would not already work here? For the cart using the existing feature seems nice, because it will allow you to use location for other things as well, switching back from cart to a permanent_location.
Comment 4 Alex Buckley 2018-08-08 22:55:56 UTC
Created attachment 77604 [details] [review]
Bug 21173 - Customize age unit and starting point for automatic item modification by age tool and cronjob.

This allows librarians to define either the item creation date or items
last altered timestamp as the starting point for the age of the item so
the autmatic_item_modification_by_age.pl can alter item fields for
example for items which have been in the catalogue for a while.

A use case for this functionality is:
* When an items shelving location changes from 'In processing' to 'Shelving trolley' after 1 hour the status 'Shelving trolley' is removed for the item. The unit 'Hours' can now be set (extending the functionality of this cronjob from just calculating item age in days) and the age starting point of 'Last altered' can be defined so existing items in the catalogue like this example item will be altered by the cronjob.

Test plan:
1. Go to Tools->Automatic item modifications by age and create a new rule
by selecting the 'Edit rules' button

2. Notice you can only set the age in the unit of days not hours. Also
alsthough not visible in the interface the rule will calculate the age
of the item based on when it was created (i.e. added to Koha).

3. Apply patch and run ./updatedatabase.pl in the koha-shell

4. Now revisit Tools->Automatic item modifications by age. Notice the
table of existing rules now contains a new column 'Age starting point'
this is the date from which the item age is calculated. This enhancement
offers you two options as the age starting point: Created (displayed in
this table as 'itemcreated') or Last altered (displayed in this table as
'itemaltered').

5. Click 'Edit rules' to create a new rule. Notice in the form for
creating the new rule you can set the unit to either 'Hours' or 'Days'.

When you select 'Days' then the Age starting point selection will appear
where you can specify if you want the rule to work on the number of days
since the item was last altered or number of days since the item was
created.

NOTE: If you select 'Hours' as the unit type when creating a new rule
then the Age starting point selection area is hidden. This is because
the item creation value is saved in the database as a date not a
datetime. Therefore we cannot calculate the number of hours since the
item was created in the Koha catalog.

Therefore if the unit is set to 'Hours' then by default the item will
use the item last altered value (stored as a date time) as the age
starting point.

For existing rules if they have the unit set to 'Hours' then the Age
starting point area is hidden by default when the page loads.

6. In the new rule set the following values: Age: 1, Unit: Hours,
condition items.location = 'CART', items.location = ''

7. Now save the rule and confirm the correct values are dispayed in the
rules table which is loaded

8. Click 'Edit rules' button again.

9. Modify the rule you just created changing Age to 2 and create another new rule with the following values: Age='1', Unit='Days', 'Age starting point'='Created', Condition 'items.homebranch'='<a branchcode of a branch in your Koha instance>', substituions 'items.homebranch'='<another branchcode in your Koha instance>'

10. Now click 'Save' and confirm the data displayed for both rules is
correct.

11. In the database manually set the location field of two items to
'CART' and set their timestamp value to 2 hours before the current time

12. Exit out of the database terminal and manually run the
automatic_item_modification_by_age.pl cronjob from the koha-shell with
this command:
./automatic_item_modification_by_age.pl --confirm

13. Now return to the database and notice the two items you set have a
location of 'CART' now have a blank location field because the manually
run cronjob altered them as they meet the conditions of the rule.

14. Repeat step 11 and enter this text into your /etc/cron.d/koha-common
file:
*/2  * * * * root koha-foreach --enabled
/usr/share/koha/bin/cronjobs/automatic_item_modification_by_age.pl
--confirm

This will make the cronjob run every 2 minutes.

15. Now restart koha-common with this command: sudo
/etc/init.d/koha-common restart

16. Now wait for more than 2 minutes and check the database again and
notice that the two items have blank location fields as the
automatically running cronjob altered the items.

Sponsored-By: Toi Ohomai Institute of Technology, New Zealand
Comment 5 Alex Buckley 2018-08-08 22:56:38 UTC
Hi Katrin

Your right that with the use case outlined by Toi Ohomai they could indeed simply use the misc/cronjobs/cart_to_shelf.pl however that would require them to either ask a member of IT staff or their Koha support vendor to add/modify the number of hours since item last modified.

Whereas this enhancement allows librarians to have control over this and provides scope for library staff to not just change item.location based on the number of hours since the item was modified but also many other conditions and substitutions are available to them. 

i.e. this gives librarians more control and lets them set many values other than items.location based on the number of hours or days since the item was last altered. 

What are your thoughts?
Comment 6 Katrin Fischer 2018-08-08 23:00:55 UTC
Hi Alex, not trying to block this one - as you said, it's a general feature that will allow for other things as well and I was not sure if you were away of the in-built cart feature that allows to return from cart to a former location.
Comment 7 Alex Buckley 2018-08-08 23:06:33 UTC
Hi Katrin

Thanks for bringing the other inbuilt cart feature to my attention as I wasn't previously aware of it before writing this enhancement. 

I have just rebased the commits down to a single commit. I just have to obsolete the commit I just added as I noticed a template typo then it should be pretty close to being ready for being set to 'Needs signoff'. 

This commit and several others I have/am writing at the moment are for Toi Ohomai who you may have seen in the July community newsletter that they have recently gone live with Koha :)
Comment 8 Alex Buckley 2018-08-08 23:22:33 UTC
Created attachment 77605 [details] [review]
Bug 21173 - Customize age unit and starting point for automatic item modification by age tool and cronjob.

This allows librarians to define either the item creation date or items
last altered timestamp as the starting point for the age of the item so
the autmatic_item_modification_by_age.pl can alter item fields for
example for items which have been in the catalogue for a while.

A use case for this functionality is:
* When an items shelving location changes from 'In processing' to 'Shelving trolley' after 1 hour the status 'Shelving trolley' is removed for the item. The unit 'Hours' can now be set (extending the functionality of this cronjob from just calculating item age in days) and the age starting point of 'Last altered' can be defined so existing items in the catalogue like this example item will be altered by the cronjob.

Test plan:
1. Go to Tools->Automatic item modifications by age and create a new rule
by selecting the 'Edit rules' button

2. Notice you can only set the age in the unit of days not hours. Also
alsthough not visible in the interface the rule will calculate the age
of the item based on when it was created (i.e. added to Koha).

3. Apply patch and run ./updatedatabase.pl in the koha-shell

4. Now revisit Tools->Automatic item modifications by age. Notice the
table of existing rules now contains a new column 'Age starting point'
this is the date from which the item age is calculated. This enhancement
offers you two options as the age starting point: Created (displayed in
this table as 'itemcreated') or Last altered (displayed in this table as
'itemaltered').

5. Click 'Edit rules' to create a new rule. Notice in the form for
creating the new rule you can set the unit to either 'Hours' or 'Days'.

When you select 'Days' then the Age starting point selection will appear
where you can specify if you want the rule to work on the number of days
since the item was last altered or number of days since the item was
created.

NOTE: If you select 'Hours' as the unit type when creating a new rule
then the Age starting point selection area is hidden. This is because
the item creation value is saved in the database as a date not a
datetime. Therefore we cannot calculate the number of hours since the
item was created in the Koha catalog.

Therefore if the unit is set to 'Hours' then by default the item will
use the item last altered value (stored as a date time) as the age
starting point.

For existing rules if they have the unit set to 'Hours' then the Age
starting point area is hidden by default when the page loads.

6. In the new rule set the following values: Age: 1, Unit: Hours,
condition items.location = 'CART', items.location = ''

7. Now save the rule and confirm the correct values are dispayed in the
rules table which is loaded

8. Click 'Edit rules' button again.

9. Modify the rule you just created changing Age to 2 and create another new rule with the following values: Age='1', Unit='Days', 'Age starting point'='Created', Condition 'items.homebranch'='<a branchcode of a branch in your Koha instance>', substituions 'items.homebranch'='<another branchcode in your Koha instance>'

10. Now click 'Save' and confirm the data displayed for both rules is
correct.

11. In the database manually set the location field of two items to
'CART' and set their timestamp value to 2 hours before the current time

12. Exit out of the database terminal and manually run the
automatic_item_modification_by_age.pl cronjob from the koha-shell with
this command:
./automatic_item_modification_by_age.pl --confirm

13. Now return to the database and notice the two items you set have a
location of 'CART' now have a blank location field because the manually
run cronjob altered them as they meet the conditions of the rule.

14. Repeat step 11 and enter this text into your /etc/cron.d/koha-common
file:
*/2  * * * * root koha-foreach --enabled
/usr/share/koha/bin/cronjobs/automatic_item_modification_by_age.pl
--confirm

This will make the cronjob run every 2 minutes.

15. Now restart koha-common with this command: sudo
/etc/init.d/koha-common restart

16. Now wait for more than 2 minutes and check the database again and
notice that the two items have blank location fields as the
automatically running cronjob altered the items.

Sponsored-By: Toi Ohomai Institute of Technology, New Zealand
Comment 9 Alex Buckley 2018-09-11 22:14:12 UTC
Can we please move this patch along. It is currently being used in production by Toi Ohomai Institute of Technology of New Zealand.
Comment 10 Alex Buckley 2018-09-16 00:34:58 UTC
Created attachment 78917 [details] [review]
Bug 21173 - Customize age unit and starting point for automatic item modification by age tool and cronjob.

This allows librarians to define either the item creation date or items
last altered timestamp as the starting point for the age of the item so
the autmatic_item_modification_by_age.pl can alter item fields for
example for items which have been in the catalogue for a while.

A use case for this functionality is:
* When an items shelving location changes from 'In processing' to 'Shelving trolley' after 1 hour the status 'Shelving trolley' is removed for the item. The unit 'Hours' can now be set (extending the functionality of this cronjob from just calculating item age in days) and the age starting point of 'Last altered' can be defined so existing items in the catalogue like this example item will be altered by the cronjob.

Test plan:
1. Go to Tools->Automatic item modifications by age and create a new rule
by selecting the 'Edit rules' button

2. Notice you can only set the age in the unit of days not hours. Also
alsthough not visible in the interface the rule will calculate the age
of the item based on when it was created (i.e. added to Koha).

3. Apply patch and run ./updatedatabase.pl in the koha-shell

4. Now revisit Tools->Automatic item modifications by age. Notice the
table of existing rules now contains a new column 'Age starting point'
this is the date from which the item age is calculated. This enhancement
offers you two options as the age starting point: Created (displayed in
this table as 'itemcreated') or Last altered (displayed in this table as
'itemaltered').

5. Click 'Edit rules' to create a new rule. Notice in the form for
creating the new rule you can set the unit to either 'Hours' or 'Days'.

When you select 'Days' then the Age starting point selection will appear
where you can specify if you want the rule to work on the number of days
since the item was last altered or number of days since the item was
created.

NOTE: If you select 'Hours' as the unit type when creating a new rule
then the Age starting point selection area is hidden. This is because
the item creation value is saved in the database as a date not a
datetime. Therefore we cannot calculate the number of hours since the
item was created in the Koha catalog.

Therefore if the unit is set to 'Hours' then by default the item will
use the item last altered value (stored as a date time) as the age
starting point.

For existing rules if they have the unit set to 'Hours' then the Age
starting point area is hidden by default when the page loads.

6. In the new rule set the following values: Age: 1, Unit: Hours,
condition items.location = 'CART', items.location = ''

7. Now save the rule and confirm the correct values are dispayed in the
rules table which is loaded

8. Click 'Edit rules' button again.

9. Modify the rule you just created changing Age to 2 and create another new rule with the following values: Age='1', Unit='Days', 'Age starting point'='Created', Condition 'items.homebranch'='<a branchcode of a branch in your Koha instance>', substituions 'items.homebranch'='<another branchcode in your Koha instance>'

10. Now click 'Save' and confirm the data displayed for both rules is
correct.

11. In the database manually set the location field of two items to
'CART' and set their timestamp value to 2 hours before the current time

12. Exit out of the database terminal and manually run the
automatic_item_modification_by_age.pl cronjob from the koha-shell with
this command:
./automatic_item_modification_by_age.pl --confirm

13. Now return to the database and notice the two items you set have a
location of 'CART' now have a blank location field because the manually
run cronjob altered them as they meet the conditions of the rule.

14. Repeat step 11 and enter this text into your /etc/cron.d/koha-common
file:
*/2  * * * * root koha-foreach --enabled
/usr/share/koha/bin/cronjobs/automatic_item_modification_by_age.pl
--confirm

This will make the cronjob run every 2 minutes.

15. Now restart koha-common with this command: sudo
/etc/init.d/koha-common restart

16. Now wait for more than 2 minutes and check the database again and
notice that the two items have blank location fields as the
automatically running cronjob altered the items.

Sponsored-By: Toi Ohomai Institute of Technology, New Zealand
Comment 11 Alex Buckley 2018-09-16 00:35:31 UTC
Rebased against master on 16th of sept 2018.
Comment 12 Jonathan Druart 2018-10-02 20:39:37 UTC
(In reply to Alex Buckley from comment #11)
> Rebased against master on 16th of sept 2018.

-                          <input type="text" value="[% substitution.value | html %]" name="substitution_value_[% id | html %]" />
+                          <input type="text" value="[% substitution.value %]" name="substitution_value_[% id %]" />

Rebase is wrong, you removed the filters.
Comment 13 Alex Buckley 2018-10-04 04:55:15 UTC
Created attachment 79914 [details] [review]
Bug 21173: Fixed rebase removal of filters and changed items.dateaccessioned to datetime datatype

This means we can make the auto item modification tool work for hours since item was created

Updated test plan:

1. Go to Tools->Automatic item modifications by age and create a new
rule by selecting the 'Edit rules' button

2. Notice you can only set the age in the unit of days not
hours. Also although not visible in the interface the rule will
calculate the age of the item based on when it was created (i.e. added to
Koha).

3. Apply patch and run ./updatedatabase.pl in the
koha-shell

4. Now revisit Tools->Automatic item modifications by age. Notice the
table of existing rules now contains a new column 'Age starting point'
this is the date from which the item age is calculated. This enhancement
offers you two options as the age starting point: Created (displayed in
this table as 'itemcreated') or Last altered (displayed in this table as
'itemaltered').

5. Click 'Edit rules' to create a new rule. Notice in the form
for creating the new rule you can set the unit to either
'Hours' or 'Days'.

6. In the new rule set the following values: Age: 1, Unit: Hours,
condition items.location = 'CART', items.location = ''

7.  Now save the rule and confirm the correct values are
dispayed in the rules table which is loaded

8. Click 'Edit rules' button again.

9. Modify the rule you just created changing Age to
2 and create another new rule with the following
values: Age='1', Unit='Hour', 'Age starting
point'='Created', Condition 'items.homebranch'='<a
branchcode of a branch in your Koha instance>',
substituions 'items.homebranch'='<another
branchcode in your Koha instance>'

10. Now click 'Save' and confirm the data displayed for both rules is
correct.

11. Create two new items and set their location field
to 'CART'. Then in the database set their dateaccessioned value to 2 hours before the
current time

12. Exit out of the database terminal and manually run
the automatic_item_modification_by_age.pl cronjob from
the koha-shell with this command:
./automatic_item_modification_by_age.pl --confirm

13. Now return to the database and notice the two items you set have
a location of 'CART' now have a blank location field because the
manually run cronjob altered them as they meet the conditions of the
rule.

14. Repeat step 11 but this time change the rule in the Auto item modification tool interface to 'Age starting point='Altered'' so we can test the auto item mod tool on items that have been last altered more than 2 hours ago.

15. Enter this text into your /etc/cron.d/koha-common file:
*/2  * * * * root koha-foreach --enabled
/usr/share/koha/bin/cronjobs/automatic_item_modification_by_age.pl
--confirm

This will make the cronjob run every 2 minutes.

16. Now restart koha-common with this command: sudo
/etc/init.d/koha-common restart

17. Now wait for more than 2 minutes and check the
database again and notice that the two items have blank location fields
as the automatically running cronjob altered the items.

18. Repeat steps 9-17 with the new rules in the auto item modification
tool for the following rule conditions:

New rule:
    Age: 2
    Age starting point: Created
    Units: Days
    Condition 'items.homebranch'='<a branchcode of a branch in your Koha instance>',
    Substitutions 'items.homebranch'='<another branchcode in your Koha instance>'

New rule:
    Age: 2
    Age starting point: Altered
    Units: Days
    Condition 'items.homebranch'='<a branchcode of a branch in your Koha instance>',
    Substitutions 'items.homebranch'='<another branchcode in your Koha instance>'

Sponsored-By: Toi Ohomai Institute of Technology, New Zealand
Comment 14 Alex Buckley 2018-10-04 05:02:16 UTC
(In reply to Jonathan Druart in comment 12):

Thanks Jonathan, I have fixed that up in the patch I just applied and added another change to store the items.dateaccessioned field as a datetime so the automatic item modification tool can now work on the number of hours since an item was created as well as since it was last altered. 

This has allowed me to remove some of the JS to prevent users from trying to select the age starting point of 'created' and the unit of 'hours', and it makes the tool more useful. 

Can you please test.
Comment 15 Katrin Fischer 2018-10-04 20:06:35 UTC
>Bug 21173: Fixed rebase removal of filters and changed items.dateaccessioned to >datetime datatype

I am worried by this change. We have a lot of libraries who set the date manually in items, typing it in like: 2010-01-01. It will auto-fill, but for retro-cataloguing they want it to reflect the real date. Maybe it would be better to introduce a completely new column created_on with an automatic timestamp?
Comment 16 Katrin Fischer 2018-10-04 20:08:13 UTC
It's also missing changes to kohastructure and deleteditems.
Comment 17 Katrin Fischer 2018-10-04 20:24:51 UTC
The more I think about it, the more I think this change would likely have many unwanted side effects:

- dateaccesioned is indexed in Zebra and used in several spots like in the labels module for finding new items
- Acq also sets it at some point as a date.
- The value builder/catalouging plugin linked to the field uses a date
- Used in hardcoded reports
- ... (git grep dateaccessioned :) )
Comment 18 Alex Buckley 2022-08-02 21:34:05 UTC
Working on reviving this patchset.
Comment 19 Alex Buckley 2022-08-09 04:49:22 UTC
Created attachment 138870 [details] [review]
Bug 21173: Template and JavaScript changes

Sponsored-by: Toi Ohomai Institute of Technology, New Zealand
Comment 20 Alex Buckley 2022-08-09 04:49:41 UTC
Created attachment 138871 [details] [review]
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
Comment 21 Alex Buckley 2022-08-09 04:50:00 UTC
Created attachment 138872 [details] [review]
Bug 21173: Unit tests

Test plan:
1. sudo koha-shell kohadev
2. prove t/db_dependent/Items/AutomaticItemModificationByAge.t

Sponsored-by: Toi Ohomai Institute of Technology, New Zealand
Comment 22 Alex Buckley 2022-08-09 05:10:54 UTC
Hi all, 

In the interests of upstreaming I have re-written this patchset.

This patchset now adds the ability to set a unit of 'Hours' for automatic item modification by age rules on the three existing item datetime columns: items.damaged_on, items.itemlost_on, items.withdrawn_on.

This is instead of trying to change existing items date columns to the datetime datatype, or adding new datetime columns.

I think adding a new column such as 'created_on' with an automatic timestamp (as Katrin noted in comment #15), could be added in a follow-up bug report, and it's best to get a smaller part of this functionality upstreamed initially. 

Ready for testing again! 

Thanks,
Alex
Comment 23 Alex Buckley 2022-08-09 11:14:29 UTC
Created attachment 138894 [details] [review]
Bug 21173: Template and JavaScript changes

Sponsored-by: Toi Ohomai Institute of Technology, New Zealand
Comment 24 Alex Buckley 2022-08-09 11:14:50 UTC
Created attachment 138895 [details] [review]
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
Comment 25 Alex Buckley 2022-08-09 11:15:14 UTC
Created attachment 138896 [details] [review]
Bug 21173: Unit tests

Test plan:
1. sudo koha-shell kohadev
2. prove t/db_dependent/Items/AutomaticItemModificationByAge.t

Sponsored-by: Toi Ohomai Institute of Technology, New Zealand
Comment 26 Alex Buckley 2022-08-09 11:22:04 UTC
Removed unused JS variable and warn and re-attached patchset. Ready for testing again.
Comment 27 Alex Buckley 2023-02-13 21:04:03 UTC
Still applies cleanly on master/main
Comment 28 David Nind 2023-09-25 00:50:40 UTC
Created attachment 156137 [details] [review]
Bug 21173: Template and JavaScript changes

Sponsored-by: Toi Ohomai Institute of Technology, New Zealand
Signed-off-by: David Nind <david@davidnind.com>
Comment 29 David Nind 2023-09-25 00:50:43 UTC
Created attachment 156138 [details] [review]
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
Signed-off-by: David Nind <david@davidnind.com>
Comment 30 David Nind 2023-09-25 00:50:46 UTC
Created attachment 156139 [details] [review]
Bug 21173: Unit tests

Test plan:
1. sudo koha-shell kohadev
2. prove t/db_dependent/Items/AutomaticItemModificationByAge.t

Sponsored-by: Toi Ohomai Institute of Technology, New Zealand
Signed-off-by: David Nind <david@davidnind.com>
Comment 31 Katrin Fischer 2023-11-01 18:54:53 UTC
1) Needs a bit of perltidy.
2) The GUI is a little confusing. What happens:

* When the form is shown the first time, the 'Hours' value is selected
* Switch the field to items.withdrawn_on and it changes to "Choose an age unit"
* Switch the field back to "items.dateaccessioned"
* The drop down still shows "Choose an age unit", but can no longer be changed.

Suggested behavior:

* When the form is shown the first time, the 'Hours' value is selected
* Switch the field to items.withdrawn_on the field unlocks and is now editable
* Switch to "Hours"
* Switch the field back to "items.dateaccessioned", the field locks with "Hours" set

Alternatively we could also only show the units pull down if one of the 3 fields where it applies is picked?
Comment 32 Alex Buckley 2023-11-05 23:31:50 UTC
Hi (In reply to Katrin Fischer from comment #31)
> 1) Needs a bit of perltidy.
> 2) The GUI is a little confusing. What happens:
> 
> * When the form is shown the first time, the 'Hours' value is selected
> * Switch the field to items.withdrawn_on and it changes to "Choose an age
> unit"
> * Switch the field back to "items.dateaccessioned"
> * The drop down still shows "Choose an age unit", but can no longer be
> changed.
> 
> Suggested behavior:
> 
> * When the form is shown the first time, the 'Hours' value is selected
> * Switch the field to items.withdrawn_on the field unlocks and is now
> editable
> * Switch to "Hours"
> * Switch the field back to "items.dateaccessioned", the field locks with
> "Hours" set
> 
> Alternatively we could also only show the units pull down if one of the 3
> fields where it applies is picked?

Hi Katrin, 

Thank you for doing QA. I will work through each of your points and fix up this enhancement :)

Alex
Comment 33 Owen Leonard 2023-11-06 11:37:29 UTC
What if we change the order of the fields?

1. Age field
2. Age unit
3. Age

Then you're not backtracking in the form if you select a field which offers other unit choices.
Comment 34 Alex Buckley 2023-11-06 22:15:01 UTC
Created attachment 158574 [details] [review]
Bug 21173: (follow-up) Perltidy

Sponsored-by: Toi Ohomai Institute of Technology, New Zealand
Comment 35 Alex Buckley 2023-11-06 22:15:27 UTC
Created attachment 158575 [details] [review]
Bug 21173: (follow-up) Re-ordering input fields in item modification by age form

Sponsored-by: Toi Ohomai Institute of Technology, New Zealand
Comment 36 Alex Buckley 2023-11-06 22:24:49 UTC
Thanks Katrin and Owen! 

Great suggestions, I am just trying them out in those follow-ups. This isn't ready to testing yet, I'll change the status when it is :)
Comment 37 Alex Buckley 2023-12-28 23:01:38 UTC
Hi Katrin and Owen, 

Happy holidays!

I think this one is ready for testing now. I've checked and it does still apply cleanly on master and the order of the fields is as follows:

1. Age field
2. Age unit
3. Age

Please do let me know if there is anything else you would like me to alter?

Thanks so much,
Alex
Comment 38 Phan Tung Bui 2024-01-09 16:57:09 UTC
Please update the test plan to reflect the current location of the 'Automatic Item Modifications by Age' feature. It is no longer found under 'Tools' but has been moved to 'Cataloging'.
Comment 39 Matthias Le Gac 2024-01-09 18:32:31 UTC
Created attachment 160715 [details] [review]
Bug 21173: (follow-up) Re-ordering input fields in item modification by age form

Sponsored-by: Toi Ohomai Institute of Technology, New Zealand
Signed-off-by: matthias le gac <matthias@babel.inlibro.net>
Comment 40 Phan Tung Bui 2024-01-09 18:49:01 UTC
Created attachment 160716 [details] [review]
Bug 21173: (follow-up) Re-ordering input fields in item modification by age form

Sponsored-by: Toi Ohomai Institute of Technology, New Zealand
Signed-off-by: Phan Tung Bui <phan-tung.bui@inlibro.com>
Comment 41 Phan Tung Bui 2024-01-09 18:49:40 UTC
Note: To avoid confusion, when selecting a rule other than 'items.damaged_on',
'items.itemlost_on', or 'items.withdrawn_on', the option 'Hours' should be
disabled since these specific fields are associated with the 'Days' unit.
Enabling 'Hours' for other fields may lead to misinterpretation of the rule's
intended behavior. Disabling 'Hours' ensures consistency in the presentation
of rules and helps users make accurate selections.