Bugzilla – Attachment 108301 Details for
Bug 18501
Automatic refunds need protection from failure
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18501: (QA follow-up) Fix regressions highlighted by unit tests
Bug-18501-QA-follow-up-Fix-regressions-highlighted.patch (text/plain), 5.38 KB, created by
Martin Renvoize
on 2020-08-14 16:23:03 UTC
(
hide
)
Description:
Bug 18501: (QA follow-up) Fix regressions highlighted by unit tests
Filename:
MIME Type:
Creator:
Martin Renvoize
Created:
2020-08-14 16:23:03 UTC
Size:
5.38 KB
patch
obsolete
>From ba67cf2601e53c467750060105560bcb7645fef0 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 14 Aug 2020 17:18:12 +0100 >Subject: [PATCH] Bug 18501: (QA follow-up) Fix regressions highlighted by unit > tests > >The migration of unit tests in the preceeding patch highlighted a few >regressions which are dealt with here. > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Item.pm | 83 ++++++++++++++++++++++++++++------------------------ > 1 file changed, 44 insertions(+), 39 deletions(-) > >diff --git a/Koha/Item.pm b/Koha/Item.pm >index 5ad6665673..0260ee4a6e 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -120,38 +120,44 @@ sub store { > > } else { # ModItem > >- { # Update *_on fields if needed >- # Why not for AddItem as well? >- my @fields = qw( itemlost withdrawn damaged ); >- >- # Only retrieve the item if we need to set an "on" date field >- if ( $self->itemlost || $self->withdrawn || $self->damaged ) { >- my $pre_mod_item = $self->get_from_storage; >- for my $field (@fields) { >- if ( $self->$field >- and not $pre_mod_item->$field ) >- { >- my $field_on = "${field}_on"; >- $self->$field_on( >- DateTime::Format::MySQL->format_datetime( dt_from_string() ) >- ); >- } >- } >- } >+ my %updated_columns = $self->_result->get_dirty_columns; >+ return $self->SUPER::store unless %updated_columns; > >- # If the field is defined but empty, we are removing and, >- # and thus need to clear out the 'on' field as well >- for my $field (@fields) { >- if ( defined( $self->$field ) && !$self->$field ) { >- my $field_on = "${field}_on"; >- $self->$field_on(undef); >- } >+ # Retreive the item for comparison if we need to >+ my $pre_mod_item = $self->get_from_storage >+ if ( exists $updated_columns{itemlost} >+ or exists $updated_columns{withdrawn} >+ or exists $updated_columns{damaged} ); >+ >+ # Update *_on fields if needed >+ # FIXME: Why not for AddItem as well? >+ my @fields = qw( itemlost withdrawn damaged ); >+ for my $field (@fields) { >+ >+ # If the field is defined but empty or 0, we are >+ # removing/unsetting and thus need to clear out >+ # the 'on' field >+ if ( exists $updated_columns{$field} >+ && defined( $self->$field ) >+ && !$self->$field ) >+ { >+ my $field_on = "${field}_on"; >+ $self->$field_on(undef); >+ } >+ # If the field has changed otherwise, we much update >+ # the 'on' field >+ elsif ( exists $updated_columns{$field} >+ && $updated_columns{$field} ne $pre_mod_item->$field ) >+ { >+ my $field_on = "${field}_on"; >+ $self->$field_on( >+ DateTime::Format::MySQL->format_datetime( >+ dt_from_string() >+ ) >+ ); > } > } > >- my %updated_columns = $self->_result->get_dirty_columns; >- return $self->SUPER::store unless %updated_columns; >- > if ( exists $updated_columns{itemcallnumber} > or exists $updated_columns{cn_source} ) > { >@@ -168,13 +174,13 @@ sub store { > $self->permanent_location( $self->location ); > } > >- # If item was lost, it has now been found, reverse any list item charges if necessary. >- if ( exists $updated_columns{itemlost} >- and $self->itemlost != $updated_columns{itemlost} >- and $self->itemlost >= 1 >- and $updated_columns{itemlost} <= 0 >- ) { >- $self->_set_found_trigger; >+ # If item was lost and has now been found, >+ # reverse any list item charges if necessary. >+ if ( exists $updated_columns{itemlost} >+ and $updated_columns{itemlost} <= 0 >+ and $pre_mod_item->itemlost > 0 ) >+ { >+ $self->_set_found_trigger($pre_mod_item); > $self->paidfor(''); > } > >@@ -785,16 +791,15 @@ Internal function, not exported, called only by Koha::Item->store. > =cut > > sub _set_found_trigger { >- my ( $self, $params ) = @_; >+ my ( $self, $pre_mod_item ) = @_; > > ## If item was lost, it has now been found, reverse any list item charges if necessary. >- my $refund = 1; > my $no_refund_after_days = > C4::Context->preference('NoRefundOnLostReturnedItemsAge'); > if ($no_refund_after_days) { > my $today = dt_from_string(); > my $lost_age_in_days = >- dt_from_string( $self->itemlost_on )->delta_days($today) >+ dt_from_string( $pre_mod_item->itemlost_on )->delta_days($today) > ->in_units('days'); > > return $self unless $lost_age_in_days < $no_refund_after_days; >@@ -878,7 +883,7 @@ sub _set_found_trigger { > > # Update the account status > $accountline->status('FOUND'); >- $accountline->store; >+ $accountline->store(); > > if ( defined $account and C4::Context->preference('AccountAutoReconcile') ) { > $account->reconcile_balance; >-- >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 18501
:
108004
|
108005
|
108006
|
108121
|
108122
|
108123
|
108167
|
108168
|
108169
|
108170
|
108193
|
108194
|
108195
|
108243
|
108248
|
108249
|
108291
|
108292
|
108293
|
108294
|
108295
|
108296
|
108297
|
108298
|
108299
|
108300
|
108301
|
108482
|
108483
|
108484
|
108485
|
108486
|
108487
|
108488
|
108489
|
108490
|
108491
|
108492
|
108493
|
108494
|
108575
|
108576
|
108577
|
108578
|
108579
|
108580
|
108581
|
108582
|
108583
|
108584
|
108585
|
108586
|
108596
|
108597
|
108598
|
108599
|
108600
|
108601
|
108602
|
108603
|
108604
|
108605
|
108606
|
108607
|
108608
|
108610
|
108611
|
108612
|
108613
|
108614
|
108615
|
108616
|
108617
|
108618
|
108619
|
108620
|
108621
|
108717
|
108732
|
108738
|
108739
|
108740
|
108741
|
108784
|
108785
|
108786
|
108787
|
108788
|
108795
|
111295