Bug 25020: Preserve time part when batch extending due dates

When selecting a new hard due date, we should keep the time part of the
original checkouts.

Test plan:
1 - Checkout an item specifying a date due
2 - Checkout an item without specifying a date due
3 - Use Tools->Batch extend due date
4 - Select a hard due date
5 - On the confirmation screen you should see that the time part has
been kept
6 - Confirm
7 - Make sure the correct values hava been inserted in DB
8 - Try now using the other option, give a number of days
9 - Repeat 4-7

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Joy Nelson <joy@bywatersolutions.com>
(cherry picked from commit 5550da8a50)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 5d49c80644)

Signed-off-by: Hayley Mapley <hayleymapley@catalyst.net.nz>
This commit is contained in:
Jonathan Druart 2020-03-30 16:11:51 +02:00 committed by Hayley Mapley
parent e41180c459
commit 91faeb16bb
2 changed files with 40 additions and 13 deletions

View File

@ -134,11 +134,7 @@
<td>[% checkout.issuedate | $KohaDates %]</td> <td>[% checkout.issuedate | $KohaDates %]</td>
<td>[% Branches.GetName( checkout.branchcode ) | html %]</td> <td>[% Branches.GetName( checkout.branchcode ) | html %]</td>
<td> <td>
[% IF new_hard_due_date %] [% new_due_dates.shift | $KohaDates as_due_date => 1 %]
[% new_hard_due_date | $KohaDates %]
[% ELSE %]
[% new_due_dates.shift | $KohaDates %]
[% END %]
</td> </td>
</tr> </tr>
[% END %] [% END %]

View File

@ -26,7 +26,7 @@ use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_html_with_http_headers ); use C4::Output qw( output_html_with_http_headers );
use C4::Items qw( ModItem ); use C4::Items qw( ModItem );
use Koha::Checkouts; use Koha::Checkouts;
use Koha::DateUtils qw( dt_from_string ); use Koha::DateUtils qw( dt_from_string output_pref );
my $input = new CGI; my $input = new CGI;
my $op = $input->param('op') // q|form|; my $op = $input->param('op') // q|form|;
@ -53,6 +53,8 @@ elsif ( $op eq 'list' ) {
my $new_hard_due_date = $input->param('new_hard_due_date'); my $new_hard_due_date = $input->param('new_hard_due_date');
my $due_date_days = $input->param('due_date_days'); my $due_date_days = $input->param('due_date_days');
$new_hard_due_date &&= dt_from_string($new_hard_due_date);
my $dtf = Koha::Database->new->schema->storage->datetime_parser; my $dtf = Koha::Database->new->schema->storage->datetime_parser;
my $search_params; my $search_params;
if (@categorycodes) { if (@categorycodes) {
@ -100,12 +102,17 @@ elsif ( $op eq 'list' ) {
); );
my @new_due_dates; my @new_due_dates;
if ( not $new_hard_due_date && $due_date_days ) { while ( my $checkout = $checkouts->next ) {
while ( my $checkout = $checkouts->next ) { push @new_due_dates,
my $due_date = dt_from_string( $checkout->date_due ); output_pref({ dt => calc_new_due_date(
push @new_due_dates, $due_date->add( days => $due_date_days ); {
} due_date => dt_from_string($checkout->date_due),
new_hard_due_date => $new_hard_due_date,
add_days => $due_date_days
}
), dateformat => 'iso' });
} }
$template->param( $template->param(
checkouts => $checkouts, checkouts => $checkouts,
new_hard_due_date => $new_hard_due_date new_hard_due_date => $new_hard_due_date
@ -127,8 +134,13 @@ elsif ( $op eq 'modify' ) {
my $checkouts = my $checkouts =
Koha::Checkouts->search( { issue_id => { -in => \@issue_ids } } ); Koha::Checkouts->search( { issue_id => { -in => \@issue_ids } } );
while ( my $checkout = $checkouts->next ) { while ( my $checkout = $checkouts->next ) {
my $new_due_date = $new_hard_due_date my $new_due_date = calc_new_due_date(
|| dt_from_string( $checkout->date_due )->add( days => $due_date_days ); {
due_date => dt_from_string($checkout->date_due),
new_hard_due_date => $new_hard_due_date,
add_days => $due_date_days
}
);
# Update checkout's due date # Update checkout's due date
$checkout->date_due($new_due_date)->store; $checkout->date_due($new_due_date)->store;
@ -144,4 +156,23 @@ elsif ( $op eq 'modify' ) {
); );
} }
sub calc_new_due_date {
my ($params) = @_;
my $due_date = $params->{due_date};
my $new_hard_due_date = $params->{new_hard_due_date};
my $add_days = $params->{add_days};
my $new;
if ( $new_hard_due_date ) {
$new = $new_hard_due_date->clone->set(
hour => $due_date->hour,
minute => $due_date->minute,
second => $due_date->second,
)
} else {
$new = $due_date->clone->add( days => $add_days );
}
return $new;
}
output_html_with_http_headers $input, $cookie, $template->output; output_html_with_http_headers $input, $cookie, $template->output;