Bug 28224 - Make date range for order search configurable
Summary: Make date range for order search configurable
Status: Patch doesn't apply
Alias: None
Product: Koha
Classification: Unclassified
Component: Acquisitions (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Katrin Fischer
QA Contact: Testopia
URL:
Keywords: Academy
Depends on:
Blocks:
 
Reported: 2021-04-26 12:52 UTC by Katrin Fischer
Modified: 2024-04-19 21:58 UTC (History)
8 users (show)

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


Attachments
Bug 28224: Make date range for order search configurable (6.94 KB, patch)
2023-09-15 16:13 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 28224: Make date range for order search configurable (6.99 KB, patch)
2023-09-16 01:37 UTC, David Nind
Details | Diff | Splinter Review
Bug 28224: (follow-up) New system preference description (1.44 KB, patch)
2023-09-16 01:37 UTC, David Nind
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Katrin Fischer 2021-04-26 12:52:09 UTC
When searching orders in the acquisitions module the search is automatically limited to orders created in the last year. In some circumstances, like when testng migration data, this can get quite annoying very fast adding a lots of extra clicks and typing.

It would be great if the date range or at least the start date was configurable here.

/cgi-bin/koha/acqui/histsearch.pl

When changed using jQuery this will only work once you have reached the form. But using the search options on top also limit on the date range already.
Comment 1 Katrin Fischer 2023-09-15 16:13:33 UTC
Created attachment 155697 [details] [review]
Bug 28224: Make date range for order search configurable

When searching orders in the acquisitions module the search
is automatically limited to orders created within the last year.

In some circumstances, like when testing migration data or
when working with standing orders, this can get annoying and
is not very useful.

This patch adds the OrderSearchFromDate system preference to
make this date configurable.

To test:
* Go to acquisitions > order search > config icon > advanced search
* Verify the From date is from one year ago
* Apply patch and run database update
* Verify the date is still the same
* Update the OrderSearchFromDate system preference to x days ago
  Example: 3
* Verify the date on the search form changes accordingly
* Add a basket with an order line
* Add another basket, add an order line using "From existing orders (copy)"
* Verify the date on the form is calculated correctly to the pref setting
* Copy your existing order
* Use the order search and send it empty - your 2 order lines should be shown

To test the search itself, you need baskets with different creation dates,
as the search searches aqbasket.creationdate.
  UPDATE aqbasket SET creationdate = "YYYY-MM-DD" WHERE basketno = X;

* Verify the search form and the top bar search respect the new from setting.

Sponsored by: The Research University in the Helmholtz Association (KIT)
Comment 2 David Nind 2023-09-16 01:37:28 UTC
Created attachment 155727 [details] [review]
Bug 28224: Make date range for order search configurable

When searching orders in the acquisitions module the search
is automatically limited to orders created within the last year.

In some circumstances, like when testing migration data or
when working with standing orders, this can get annoying and
is not very useful.

This patch adds the OrderSearchFromDate system preference to
make this date configurable.

To test:
* Go to acquisitions > order search > config icon > advanced search
* Verify the From date is from one year ago
* Apply patch and run database update
* Verify the date is still the same
* Update the OrderSearchFromDate system preference to x days ago
  Example: 3
* Verify the date on the search form changes accordingly
* Add a basket with an order line
* Add another basket, add an order line using "From existing orders (copy)"
* Verify the date on the form is calculated correctly to the pref setting
* Copy your existing order
* Use the order search and send it empty - your 2 order lines should be shown

To test the search itself, you need baskets with different creation dates,
as the search searches aqbasket.creationdate.
  UPDATE aqbasket SET creationdate = "YYYY-MM-DD" WHERE basketno = X;

* Verify the search form and the top bar search respect the new from setting.

Sponsored by: The Research University in the Helmholtz Association (KIT)

Signed-off-by: David Nind <david@davidnind.com>
Comment 3 David Nind 2023-09-16 01:37:31 UTC
Created attachment 155728 [details] [review]
Bug 28224: (follow-up) New system preference description

Update the description for OrderSearchFromDate:
- Fix spelling
- Use active voice

Signed-off-by: David Nind <david@davidnind.com>
Comment 4 Jonathan Druart 2023-10-04 13:32:48 UTC
Why don't you make the value sticky and store it into a cookie instead?
Comment 5 Jonathan Druart 2023-10-04 13:33:43 UTC
(In reply to Jonathan Druart from comment #4)
> Why don't you make the value sticky and store it into a cookie instead?

Well, you will need a separate field on the form of course.
Comment 6 Jonathan Druart 2023-10-04 13:37:46 UTC
Having a syspref for that purpose feels wrong to me.

You could even do it using some JS code.
Comment 7 Katrin Fischer 2023-10-04 19:31:24 UTC
(In reply to Jonathan Druart from comment #6)
> Having a syspref for that purpose feels wrong to me.
> 
> You could even do it using some JS code.

Not really, because that won't work for the simple search on top. It's what we did in the past, this is a more complete fix.

Usually it's not a setting that every person will want to change, it depends on your workflow and the data - like if you have standing orders you will want to have it set to a date further in the past. But it's not so much something you'd need individually per person.

And it probably be a bit annoying to have to reset it with every session for that reason.

We have a similar setting for the holds to pull page.
Comment 8 Jonathan Druart 2023-10-13 07:24:15 UTC
With the following lines in IntranetUserJS, whoever can set the values they want in whichever date inputs:

const OrderSearchFromDate = 3;
if ( $("body").attr("id") == "acq_histsearch" ) {
  let now = dayjs();
  let from = now.subtract(OrderSearchFromDate, 'day').format("YYYY-MM-DD");
  $("#from").val(from);
}

Don't you think it's preferable to advertise this solution instead of creating one pref per need?

Switching to in discussion.
Comment 9 Katrin Fischer 2023-10-13 17:00:11 UTC
(In reply to Jonathan Druart from comment #8)
> With the following lines in IntranetUserJS, whoever can set the values they
> want in whichever date inputs:
> 
> const OrderSearchFromDate = 3;
> if ( $("body").attr("id") == "acq_histsearch" ) {
>   let now = dayjs();
>   let from = now.subtract(OrderSearchFromDate, 'day').format("YYYY-MM-DD");
>   $("#from").val(from);
> }
> 
> Don't you think it's preferable to advertise this solution instead of
> creating one pref per need?
> 
> Switching to in discussion.

Have you tested it works for the 'simple' search from the top search bar? Because I believe we tried that, but it didn't work.
Comment 10 Katrin Fischer 2024-04-01 11:54:52 UTC
I'd like to get some more eyes on this. 

One big caveat of the JS solution as I understand it is that it will not work with the search options on top of the acq module, only when searching from the acq advanced search page.

Maybe we can split this into 2 parts:

* Would people like to have this configurable? Like is there a need for this patch or should it be dropped?

* Is the proposed implementation OK or does it require changes? 

I think the cookie solution is also not the best as it would require additional clicks every day to set it to "your date range". But maybe it could be a separate bug for allowing to change the range for a session when needed.
Comment 11 Sarah Cornell 2024-04-15 17:42:54 UTC
I lost my patience with the invisible order search limit back in 2021, right before this bug was filed!  If I recall correctly, it would limit to the past year even though it didn't display that limit. That drove me bonkers. I'm pretty sure we have JQuery that sets the range to 2020-current.  

When we search the biblio database we expect to see all results, so why would orders be any different? When I want to know if we placed an order for a title, that's all I want to know. "When" doesn't come into it.  If there are too many results, THEN I want to limit the search. 

The behavior that seems most like other search behavior is that there be no default date limit.  If I were using the simple search at the top, I would expect it to use default settings, which means no default date limit.  I do appreciate it if a form remembers the last dates I entered, however.  Then I would use the form for the rest of my session.  

Regarding a syspref:  Some staff want to see everything, some staff want to search just this FY.  None of them have access to sysprefs.  If a library wants to customize the date range using JS, that seems like a good local solution.  

I'm probably suggesting a different bugfix, aren't I?  :)
Comment 12 Katrin Fischer 2024-04-15 20:34:59 UTC
> I'm probably suggesting a different bugfix, aren't I?  :)

I think so, but still very valueable feedback :) I think you are saying: remove the date limit from the acq "simple search" and let libraries set their own using jQuery for advanced search. That about correct?
Comment 13 Sarah Cornell 2024-04-15 20:37:32 UTC
Yep, that's it!
Comment 14 Caroline Cyr La Rose 2024-04-15 21:03:59 UTC
I'm not sure I like JQuery as the only option. Library staff are not well versed in JQuery (at least not in my area) and we try to avoid such customizations as they tend to break when we update Koha. I don't really have an idea for an alternate solution and I realize my comment is in complete opposition to Sarah's (sorry!!). Could we maybe leave the syspref, and if a library wants to and is able to, then they can use JQuery?
Comment 15 Katrin Fischer 2024-04-15 21:22:19 UTC
I believe that should still work with this solution for the advanced search. The simple one is a bit of a different beast.
Comment 16 Lucas Gass 2024-04-19 21:58:34 UTC
We already have other system preferences like this. For example, HoldsToPullStartDate. 

IMO, a system preference is much better than making librarians add JS. 

This doesn't apply to current main.