View | Details | Raw Unified | Return to bug 26515
Collapse All | Expand All

(-)a/Koha/Acquisition/Order.pm (-1 / +57 lines)
Lines 18-23 package Koha::Acquisition::Order; Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Carp qw( croak );
20
use Carp qw( croak );
21
use Try::Tiny;
22
23
use C4::Biblio qw(DelBiblio);
21
24
22
use Koha::Acquisition::Baskets;
25
use Koha::Acquisition::Baskets;
23
use Koha::Acquisition::Funds;
26
use Koha::Acquisition::Funds;
Lines 25-30 use Koha::Acquisition::Invoices; Link Here
25
use Koha::Acquisition::Order::Claims;
28
use Koha::Acquisition::Order::Claims;
26
use Koha::Database;
29
use Koha::Database;
27
use Koha::DateUtils qw( dt_from_string output_pref );
30
use Koha::DateUtils qw( dt_from_string output_pref );
31
use Koha::Exceptions::Object;
28
use Koha::Biblios;
32
use Koha::Biblios;
29
use Koha::Holds;
33
use Koha::Holds;
30
use Koha::Items;
34
use Koha::Items;
Lines 97-102 sub store { Link Here
97
    return $self;
101
    return $self;
98
}
102
}
99
103
104
=head3 cancel
105
106
    $order->cancel(
107
        { [ reason        => $reason,
108
            delete_biblio => $delete_biblio ]
109
        }
110
    );
111
112
=cut
113
114
sub cancel {
115
    my ($self, $params) = @_;
116
117
    my $delete_biblio = $params->{delete_biblio};
118
    my $reason        = $params->{reason};
119
120
    try {
121
        $self->_result->result_source->schema->txn_do(
122
            sub {
123
                # Delete the related items
124
                $self->items->safe_delete;
125
126
                if ( $delete_biblio ) {
127
                    my $biblio = $self->biblio;
128
                    if ( $biblio and $biblio->items->count == 0 ) {
129
                        my $delcheck = DelBiblio( $biblio->id );
130
                        if ( $delcheck ) {
131
                            Koha::Exceptions::Object::CannotBeDeleted->throw(
132
                                object => $biblio,
133
                                reason => $delcheck
134
                            );
135
                        }
136
                    }
137
                }
138
139
                # Update order status
140
                $self->set(
141
                    {
142
                        cancellationreason      => $reason,
143
                        datecancellationprinted => \'NOW()',
144
                        orderstatus             => 'cancelled',
145
                    }
146
                )->store;
147
            }
148
        );
149
    }
150
    catch {
151
        $_->rethrow;
152
    };
153
154
    return $self;
155
}
156
100
=head3 add_item
157
=head3 add_item
101
158
102
  $order->add_item( $itemnumber );
159
  $order->add_item( $itemnumber );
103
- 

Return to bug 26515