Bugzilla – Attachment 110971 Details for
Bug 26515
Add Koha::Acquisition::Order->cancel
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26515: Add Koha::Acquisition::Order->cancel
Bug-26515-Add-KohaAcquisitionOrder-cancel.patch (text/plain), 3.39 KB, created by
Martin Renvoize (ashimema)
on 2020-09-30 08:54:22 UTC
(
hide
)
Description:
Bug 26515: Add Koha::Acquisition::Order->cancel
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-09-30 08:54:22 UTC
Size:
3.39 KB
patch
obsolete
>From f5d0d6dd04d7a435be296d3fd25f1f694986226d Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 23 Sep 2020 11:36:21 -0300 >Subject: [PATCH] Bug 26515: Add Koha::Acquisition::Order->cancel > >This patch introduces an OO replacement for DelOrder. It does the same >thing. It doesn't die when trying to delete items or biblio. It sets an >error message on the order object so the caller knows what happened. > >To test: >1. Apply this patches >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Acquisition/Order.t >=> SUCCESS: Tests pass! >3. Read the tests carefully to understand how they cover all use cases. >4- Sign off :-D > >Sponsored-by: ByWater Solutions >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Acquisition/Order.pm | 70 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 70 insertions(+) > >diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm >index 2747a78fc5..dbb04f9afc 100644 >--- a/Koha/Acquisition/Order.pm >+++ b/Koha/Acquisition/Order.pm >@@ -18,6 +18,9 @@ package Koha::Acquisition::Order; > use Modern::Perl; > > use Carp qw( croak ); >+use Try::Tiny; >+ >+use C4::Biblio qw(DelBiblio); > > use Koha::Acquisition::Baskets; > use Koha::Acquisition::Funds; >@@ -25,6 +28,7 @@ use Koha::Acquisition::Invoices; > use Koha::Acquisition::Order::Claims; > use Koha::Database; > use Koha::DateUtils qw( dt_from_string output_pref ); >+use Koha::Exceptions::Object; > use Koha::Biblios; > use Koha::Holds; > use Koha::Items; >@@ -97,6 +101,72 @@ sub store { > return $self; > } > >+=head3 cancel >+ >+ $order->cancel( >+ { [ reason => $reason, >+ delete_biblio => $delete_biblio ] >+ } >+ ); >+ >+This method marks an order as cancelled, optionally using the I<reason> parameter. >+As the order is cancelled, the (eventual) items linked to it are removed. >+If I<delete_biblio> is passed, it will try to remove the linked biblio. >+ >+If either the items or biblio removal fails, an error message is added to the object >+so the caller can take appropriate actions. >+ >+=cut >+ >+sub cancel { >+ my ($self, $params) = @_; >+ >+ my $delete_biblio = $params->{delete_biblio}; >+ my $reason = $params->{reason}; >+ >+ try { >+ # Delete the related items >+ $self->items->safe_delete; >+ >+ my $biblio = $self->biblio; >+ if ( $biblio and $delete_biblio ) { >+ >+ if ( $biblio->active_orders->count == 0 >+ and $biblio->subscriptions->count == 0 >+ and $biblio->items->count == 0 ) >+ { >+ >+ my $error = DelBiblio( $biblio->id ); >+ $self->add_message({ message => 'error_delbiblio', error => $error }) >+ if $error; >+ } >+ else { >+ >+ $self->add_message({ message => 'error_delbiblio' }); >+ } >+ } >+ } >+ catch { >+ if ( ref($_) eq 'Koha::Exceptions::Object::CannotBeDeleted' ) { >+ my $object = $_->object; >+ if ( ref($object) eq 'Koha::Item' ) { >+ $self->add_message({ message => 'error_delitem' }); >+ } >+ } >+ }; >+ >+ # Update order status >+ $self->set( >+ { >+ cancellationreason => $reason, >+ datecancellationprinted => \'NOW()', >+ orderstatus => 'cancelled', >+ } >+ )->store; >+ >+ return $self; >+} >+ > =head3 add_item > > $order->add_item( $itemnumber ); >-- >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 26515
:
110603
|
110604
|
110641
|
110642
|
110751
|
110752
|
110939
|
110940
|
110970
|
110971
|
110992
|
111031
|
111170
|
111172
|
111173
|
111372
|
111430
|
111724