Bug 23207

Summary: Allow automatic checkin/return at end of circulation period
Product: Koha Reporter: Donna <bwsdonna>
Component: CirculationAssignee: Agustín Moyano <agustinmoyano>
Status: CLOSED FIXED QA Contact: Martin Renvoize (ashimema) <martin.renvoize>
Severity: enhancement    
Priority: P5 - low CC: andrew, caroline.cyr-la-rose, dcook, fridolin.somers, gmcharlt, jonathan.druart, kyle.m.hall, martin.renvoize, mjr, tomascohen
Version: MainKeywords: Manual-updated
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34071
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
This adds a new configuration option to the itemtype administration page: Automatic checkin. With automatic checkin enabled the item will be automatically checked in at its due date. In order for this feature to work correctly, the automatic_checkin.pl cronjob needs to be set up on your installation.
Version(s) released in:
21.05.00
Circulation function:
Bug Depends on: 28190    
Bug Blocks: 28913, 33887    
Attachments: Bug 23207: Add test
Bug 23207: Add automatic_checkin column to itemtypes table
Bug 23207: Set automatic_checkin column as boolean in Itemtype schema
Bug 23207: Add automatic checkin feature
Bug 23207: Add test
Bug 23207: Add automatic_checkin column to itemtypes table
Bug 23207: Set automatic_checkin column as boolean in Itemtype schema
Bug 23207: Add automatic checkin feature
Bug 23207: Add test
Bug 23207: Add automatic_checkin column to itemtypes table
Bug 23207: Set automatic_checkin column as boolean in Itemtype schema
Bug 23207: Add automatic checkin feature
Bug 23207: Add test
Bug 23207: Add automatic_checkin column to itemtypes table
Bug 23207: Set automatic_checkin column as boolean in Itemtype schema
Bug 23207: Add automatic checkin feature
Bug 23207: Add test
Bug 23207: Add automatic_checkin column to itemtypes table
Bug 23207: Set automatic_checkin column as boolean in Itemtype schema
Bug 23207: Add automatic checkin feature
Bug 23207: (QA follow-up) Move option
Bug 23207: (QA follow-up) Add COMMENT to new column
Bug 23207: (QA follow-up) Add new column on item types UI table
Bug 23207: (QA follow-up) Add to cron files
Bug 23207: (QA follow-up) Add COMMENT to new column
Bug 23207: Regression tests
Bug 23207: Automatic checkin items should never be overdue

Description Donna 2019-06-25 16:49:09 UTC
Libraries with materials like Museum Passes, Seed Libraries, and so forth, would like the option have have certain materials checked in/returned from a patron's account on the due date.  For example, a library checks out a Museum pass to a patron - it is not a physical item that needs to be returned, but they only want the patron to be able to have one of them during a seven-day period.  Right now these items have to be manually checked in at the end of the circ period to remove it from the patron account.  An automatic return option via cron job would be helpful.
Comment 1 Agustín Moyano 2020-12-04 23:29:35 UTC
Created attachment 114212 [details] [review]
Bug 23207: Add test
Comment 2 Agustín Moyano 2020-12-04 23:29:38 UTC
Created attachment 114213 [details] [review]
Bug 23207: Add automatic_checkin column to itemtypes table

installer/data/mysql/kohastructure.sql
Comment 3 Agustín Moyano 2020-12-04 23:29:42 UTC
Created attachment 114214 [details] [review]
Bug 23207: Set automatic_checkin column as boolean in Itemtype schema
Comment 4 Agustín Moyano 2020-12-04 23:29:46 UTC
Created attachment 114215 [details] [review]
Bug 23207: Add automatic checkin feature

This patch adds the posibility to set an itemtype with automatic
checkin. It means that when the checkout is due, it will
automatically check in.

To test:
1. apply patches
2. updatedatabase
3. go to koha administration -> item types and edin an item type (from
   now on called itemtype1)
CHECK => there is a checkbox almost at the end called automatic checkin
4. check that checkbox and save
5. checkout 2 items from itemtype1 and one item from another itemtype
   (from now on called itemtype2)
6. go to mysql database console (koha-mysql) and manually set date_due = current_timestamp
   in issues table for the item of itemtype2 and only one of the items of
itemtype1
7. run cronjob at misc/cronjobs/automatic_checkin.pl
8. go to mysql database console again and select * from issues
SUCCESS => All issues are present except for the issue of itemtype1
which had it's date_due set to current_timestamp. That one was
automatically checked in.
9. prove t/db_dependent/Koha/Checkouts.t
Comment 5 Katrin Fischer 2021-03-05 13:10:38 UTC
This sounds like a really interesting feature to handle our ILL copies. Could you please rebase?
Comment 6 Katrin Fischer 2021-03-05 13:14:45 UTC
*** Bug 7716 has been marked as a duplicate of this bug. ***
Comment 7 Nick Clemens (kidclamp) 2021-03-09 14:33:45 UTC
Created attachment 117970 [details] [review]
Bug 23207: Add test
Comment 8 Nick Clemens (kidclamp) 2021-03-09 14:33:48 UTC
Created attachment 117971 [details] [review]
Bug 23207: Add automatic_checkin column to itemtypes table

installer/data/mysql/kohastructure.sql
Comment 9 Nick Clemens (kidclamp) 2021-03-09 14:33:51 UTC
Created attachment 117972 [details] [review]
Bug 23207: Set automatic_checkin column as boolean in Itemtype schema
Comment 10 Nick Clemens (kidclamp) 2021-03-09 14:33:54 UTC
Created attachment 117973 [details] [review]
Bug 23207: Add automatic checkin feature

This patch adds the posibility to set an itemtype with automatic
checkin. It means that when the checkout is due, it will
automatically check in.

To test:
1. apply patches
2. updatedatabase
3. go to koha administration -> item types and edin an item type (from
   now on called itemtype1)
CHECK => there is a checkbox almost at the end called automatic checkin
4. check that checkbox and save
5. checkout 2 items from itemtype1 and one item from another itemtype
   (from now on called itemtype2)
6. go to mysql database console (koha-mysql) and manually set date_due = current_timestamp
   in issues table for the item of itemtype2 and only one of the items of
itemtype1
7. run cronjob at misc/cronjobs/automatic_checkin.pl
8. go to mysql database console again and select * from issues
SUCCESS => All issues are present except for the issue of itemtype1
which had it's date_due set to current_timestamp. That one was
automatically checked in.
9. prove t/db_dependent/Koha/Checkouts.t
Comment 11 Andrew Fuerste-Henry 2021-03-09 15:47:08 UTC
Created attachment 117984 [details] [review]
Bug 23207: Add test

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Comment 12 Andrew Fuerste-Henry 2021-03-09 15:47:12 UTC
Created attachment 117985 [details] [review]
Bug 23207: Add automatic_checkin column to itemtypes table

installer/data/mysql/kohastructure.sql

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Comment 13 Andrew Fuerste-Henry 2021-03-09 15:47:15 UTC
Created attachment 117986 [details] [review]
Bug 23207: Set automatic_checkin column as boolean in Itemtype schema

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Comment 14 Andrew Fuerste-Henry 2021-03-09 15:47:18 UTC
Created attachment 117987 [details] [review]
Bug 23207: Add automatic checkin feature

This patch adds the posibility to set an itemtype with automatic
checkin. It means that when the checkout is due, it will
automatically check in.

To test:
1. apply patches
2. updatedatabase
3. go to koha administration -> item types and edin an item type (from
   now on called itemtype1)
CHECK => there is a checkbox almost at the end called automatic checkin
4. check that checkbox and save
5. checkout 2 items from itemtype1 and one item from another itemtype
   (from now on called itemtype2)
6. go to mysql database console (koha-mysql) and manually set date_due = current_timestamp
   in issues table for the item of itemtype2 and only one of the items of
itemtype1
7. run cronjob at misc/cronjobs/automatic_checkin.pl
8. go to mysql database console again and select * from issues
SUCCESS => All issues are present except for the issue of itemtype1
which had it's date_due set to current_timestamp. That one was
automatically checked in.
9. prove t/db_dependent/Koha/Checkouts.t

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Comment 15 Andrew Fuerste-Henry 2021-03-09 16:29:00 UTC
Two tiny bits of feedback. On the item type setup page, I'd like to see the checkbox for automatic checkin moved up just underneath the checkbox for Not for Loan. That groups things a bit more thematically. Additionally, the text there currently reads: "If checked, items will be checked in automatically after a period of time. Useful for materials where you really don't care for fisical return, like museum passes, etc."
I would suggest:
"If checked, items will be automatically checked in once they've reached their due date."
This clarifies how the checkin time is specified. I don't think we need a note here suggesting possible usage, that could go in the release notes and manual. If we want to retain that note, however, I 'd reword it as "This is useful for materials that do not require a physical checkin, such as museum passes, etc."
Comment 16 Andrew Fuerste-Henry 2021-03-09 16:49:33 UTC
Created attachment 117991 [details] [review]
Bug 23207: Add test

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Hasina Akhter <HasinaA@pascolibraries.org>
Comment 17 Andrew Fuerste-Henry 2021-03-09 16:49:36 UTC
Created attachment 117992 [details] [review]
Bug 23207: Add automatic_checkin column to itemtypes table

installer/data/mysql/kohastructure.sql

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Hasina Akhter <HasinaA@pascolibraries.org>
Comment 18 Andrew Fuerste-Henry 2021-03-09 16:49:40 UTC
Created attachment 117993 [details] [review]
Bug 23207: Set automatic_checkin column as boolean in Itemtype schema

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Hasina Akhter <HasinaA@pascolibraries.org>
Comment 19 Andrew Fuerste-Henry 2021-03-09 16:49:43 UTC
Created attachment 117994 [details] [review]
Bug 23207: Add automatic checkin feature

This patch adds the posibility to set an itemtype with automatic
checkin. It means that when the checkout is due, it will
automatically check in.

To test:
1. apply patches
2. updatedatabase
3. go to koha administration -> item types and edin an item type (from
   now on called itemtype1)
CHECK => there is a checkbox almost at the end called automatic checkin
4. check that checkbox and save
5. checkout 2 items from itemtype1 and one item from another itemtype
   (from now on called itemtype2)
6. go to mysql database console (koha-mysql) and manually set date_due = current_timestamp
   in issues table for the item of itemtype2 and only one of the items of
itemtype1
7. run cronjob at misc/cronjobs/automatic_checkin.pl
8. go to mysql database console again and select * from issues
SUCCESS => All issues are present except for the issue of itemtype1
which had it's date_due set to current_timestamp. That one was
automatically checked in.
9. prove t/db_dependent/Koha/Checkouts.t

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Hasina Akhter <HasinaA@pascolibraries.org>
Comment 20 Martin Renvoize (ashimema) 2021-04-16 12:44:21 UTC
Created attachment 119726 [details] [review]
Bug 23207: Add test

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Hasina Akhter <HasinaA@pascolibraries.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 21 Martin Renvoize (ashimema) 2021-04-16 12:44:25 UTC
Created attachment 119727 [details] [review]
Bug 23207: Add automatic_checkin column to itemtypes table

installer/data/mysql/kohastructure.sql

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Hasina Akhter <HasinaA@pascolibraries.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 22 Martin Renvoize (ashimema) 2021-04-16 12:44:29 UTC
Created attachment 119728 [details] [review]
Bug 23207: Set automatic_checkin column as boolean in Itemtype schema

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Hasina Akhter <HasinaA@pascolibraries.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 23 Martin Renvoize (ashimema) 2021-04-16 12:44:34 UTC
Created attachment 119729 [details] [review]
Bug 23207: Add automatic checkin feature

This patch adds the posibility to set an itemtype with automatic
checkin. It means that when the checkout is due, it will
automatically check in.

To test:
1. apply patches
2. updatedatabase
3. go to koha administration -> item types and edin an item type (from
   now on called itemtype1)
CHECK => there is a checkbox almost at the end called automatic checkin
4. check that checkbox and save
5. checkout 2 items from itemtype1 and one item from another itemtype
   (from now on called itemtype2)
6. go to mysql database console (koha-mysql) and manually set date_due = current_timestamp
   in issues table for the item of itemtype2 and only one of the items of
itemtype1
7. run cronjob at misc/cronjobs/automatic_checkin.pl
8. go to mysql database console again and select * from issues
SUCCESS => All issues are present except for the issue of itemtype1
which had it's date_due set to current_timestamp. That one was
automatically checked in.
9. prove t/db_dependent/Koha/Checkouts.t

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Hasina Akhter <HasinaA@pascolibraries.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 24 Martin Renvoize (ashimema) 2021-04-16 12:44:38 UTC
Created attachment 119730 [details] [review]
Bug 23207: (QA follow-up) Move option

This patch impliment the changes as suggested by Andrew on the bug
report. I agree that the suggested location fits better in the page and
the updated description is clearer.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 25 Martin Renvoize (ashimema) 2021-04-16 12:46:08 UTC
Interesting feature.. works as described and contains tests and passes QA scripts.

Passing QA

I can see lots of use cases for this, it'll be interesting to see how it plays out..

Electronic resources, Inter-library loans etc..

I liked Andrews suggestions, so I went ahead an implemented them as a QA follow-up.
Comment 26 Katrin Fischer 2021-04-17 13:58:54 UTC
Happy to see this in PQA, trying to provide the release notes note.
Comment 27 Jonathan Druart 2021-04-21 10:25:26 UTC
1. Entry missing in misc/cronjobs/crontab.example

2. Any good reasons to not add the info in a new column of the itemtypes table?

3. (just grumbling) we really need to remove the item type at biblio level (item-level_itypes syspref) and have a FK on items.itemtype. Not having the ability to join here is terrible, we have to loop over all the checkouts...
Not considering blocker but we may want to improve perf here in the future using the usual (ugly) condition for the join.

4. Thinking about the edge cases, date handling: don't we want to pass the due date for the return date, in order to not flag the checkin as overdue in the checkout history list?
Comment 28 Tomás Cohen Arazi (tcohen) 2021-04-21 11:40:57 UTC
(In reply to Jonathan Druart from comment #27)
> 1. Entry missing in misc/cronjobs/crontab.example

Good catch.

> 2. Any good reasons to not add the info in a new column of the itemtypes
> table?

You mean is missing the COMMENT?

> 3. (just grumbling) we really need to remove the item type at biblio level
> (item-level_itypes syspref) and have a FK on items.itemtype. Not having the
> ability to join here is terrible, we have to loop over all the checkouts...
> Not considering blocker but we may want to improve perf here in the future
> using the usual (ugly) condition for the join.

This is a broader discussion, but biblio-level itype is really a thing, because it is used for filtering and facets as well.

> 4. Thinking about the edge cases, date handling: don't we want to pass the
> due date for the return date, in order to not flag the checkin as overdue in
> the checkout history list?
Comment 29 Katrin Fischer 2021-04-21 12:32:18 UTC
(In reply to Tomás Cohen Arazi from comment #28)
> (In reply to Jonathan Druart from comment #27)
> > 1. Entry missing in misc/cronjobs/crontab.example
> 
> Good catch.
> 
> > 2. Any good reasons to not add the info in a new column of the itemtypes
> > table?
> 
> You mean is missing the COMMENT?

Not sure if it#s there already, but I think waht's meant was administration > itemtypes - showing the setting there in column, so you can filter etc.

> 
> > 3. (just grumbling) we really need to remove the item type at biblio level
> > (item-level_itypes syspref) and have a FK on items.itemtype. Not having the
> > ability to join here is terrible, we have to loop over all the checkouts...
> > Not considering blocker but we may want to improve perf here in the future
> > using the usual (ugly) condition for the join.
> 
> This is a broader discussion, but biblio-level itype is really a thing,
> because it is used for filtering and facets as well.

I agree, we cannot remove the itemtype on biblio-level, it's tied to varioud features and checks (max reserves check for biblio level holds, article requests without items etc.) We could maybe remove it from MARC/only add it for indexing maybe?
Comment 30 Jonathan Druart 2021-04-21 12:54:48 UTC
(In reply to Tomás Cohen Arazi from comment #28)
> (In reply to Jonathan Druart from comment #27)
> > 1. Entry missing in misc/cronjobs/crontab.example
> 
> Good catch.
> 
> > 2. Any good reasons to not add the info in a new column of the itemtypes
> > table?
> 
> You mean is missing the COMMENT?

admin/itemtypes.pl => The info is not in the table.

(In reply to Katrin Fischer from comment #29)
> (In reply to Tomás Cohen Arazi from comment #28)
> > (In reply to Jonathan Druart from comment #27)
> > > 1. Entry missing in misc/cronjobs/crontab.example
> > 
> > Good catch.
> > 
> > > 2. Any good reasons to not add the info in a new column of the itemtypes
> > > table?
> > 
> > You mean is missing the COMMENT?
> 
> Not sure if it#s there already, but I think waht's meant was administration
> > itemtypes - showing the setting there in column, so you can filter etc.
> 
> > 
> > > 3. (just grumbling) we really need to remove the item type at biblio level
> > > (item-level_itypes syspref) and have a FK on items.itemtype. Not having the
> > > ability to join here is terrible, we have to loop over all the checkouts...
> > > Not considering blocker but we may want to improve perf here in the future
> > > using the usual (ugly) condition for the join.
> > 
> > This is a broader discussion, but biblio-level itype is really a thing,
> > because it is used for filtering and facets as well.
> I agree, we cannot remove the itemtype on biblio-level, it's tied to varioud
> features and checks (max reserves check for biblio level holds, article
> requests without items etc.) We could maybe remove it from MARC/only add it
> for indexing maybe?

Definitely not the place to have the discussion, but we discussed it already several times and mostly agreed on removing it...
Comment 31 Tomás Cohen Arazi (tcohen) 2021-04-21 19:22:47 UTC
Created attachment 119966 [details] [review]
Bug 23207: (QA follow-up) Add COMMENT to new column

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 32 Tomás Cohen Arazi (tcohen) 2021-04-21 19:23:02 UTC
Created attachment 119967 [details] [review]
Bug 23207: (QA follow-up) Add new column on item types UI table

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 33 Tomás Cohen Arazi (tcohen) 2021-04-21 19:42:43 UTC
Created attachment 119973 [details] [review]
Bug 23207: (QA follow-up) Add to cron files

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 34 Jonathan Druart 2021-04-22 08:14:45 UTC
(In reply to Jonathan Druart from comment #27)
> 4. Thinking about the edge cases, date handling: don't we want to pass the
> due date for the return date, in order to not flag the checkin as overdue in
> the checkout history list?

No answer provided.
Comment 35 Jonathan Druart 2021-04-22 08:32:14 UTC
Created attachment 119985 [details] [review]
Bug 23207: (QA follow-up) Add COMMENT to new column

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

JD amended patch: FIX syntax error.(swap COMMENT and AFTER)
Comment 36 Tomás Cohen Arazi (tcohen) 2021-04-22 12:11:18 UTC
Created attachment 119999 [details] [review]
Bug 23207: Regression tests

This patch introduces a regression test for the case the automatic
checkin happens after the date due. In that case the item souldn't
really be overdue, and the checkin should be recorded with the date due
as return date.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Checkouts.t
=> FAIL: The feature doesn't behave correctly

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 37 Tomás Cohen Arazi (tcohen) 2021-04-22 12:11:24 UTC
Created attachment 120000 [details] [review]
Bug 23207: Automatic checkin items should never be overdue

This patch makes Koha::Checkouts->automatic_checkin pass the date_due as
return date to AddReturn.

To test:
1. Apply the regression tests
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Checkouts.t
=> FAIL: The feature is not working properly
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 38 Jonathan Druart 2021-04-22 12:36:53 UTC
One last thing, shouldn't we display the "auto checkin" info in the checkout list (current checkouts at circulation.pl and circulation history)?

Pushing as it, feel free to follow-up here or open a separate bug report if you think it is a good one to have for 21.05.
Comment 39 Tomás Cohen Arazi (tcohen) 2021-04-22 12:38:42 UTC
(In reply to Jonathan Druart from comment #38)
> One last thing, shouldn't we display the "auto checkin" info in the checkout
> list (current checkouts at circulation.pl and circulation history)?
> 
> Pushing as it, feel free to follow-up here or open a separate bug report if
> you think it is a good one to have for 21.05.

I will ask the sponsors, but it makes sense.
Comment 40 Jonathan Druart 2021-04-22 12:39:26 UTC
Pushed to master for 21.05, thanks to everybody involved!
Comment 41 Fridolin Somers 2021-04-29 13:47:13 UTC
Enhancement not pushed to 20.11.x