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

(-)a/Koha/Acquisition/Order.pm (-4 / +18 lines)
Lines 131-147 sub cancel { Link Here
131
        my $biblio = $self->biblio;
131
        my $biblio = $self->biblio;
132
        if ( $biblio and $delete_biblio ) {
132
        if ( $biblio and $delete_biblio ) {
133
133
134
            if (    $biblio->active_orders->count - 1 == 0 # minus ourself
134
            if (
135
                $biblio->active_orders->search(
136
                    { ordernumber => { '!=' => $self->ordernumber } }
137
                )->count == 0
135
                and $biblio->subscriptions->count == 0
138
                and $biblio->subscriptions->count == 0
136
                and $biblio->items->count == 0 )
139
                and $biblio->items->count == 0
140
              )
137
            {
141
            {
138
142
139
                my $error = DelBiblio( $biblio->id );
143
                my $error = DelBiblio( $biblio->id );
140
                $self->add_message({ message => 'error_delbiblio', error => $error })
144
                $self->add_message( { message => 'error_delbiblio'} )
141
                  if $error;
145
                  if $error;
142
            }
146
            }
143
            else {
147
            else {
144
                $self->add_message({ message => 'error_delbiblio' });
148
                if ( $biblio->active_orders->search(
149
                    { ordernumber => { '!=' => $self->ordernumber } }
150
                )->count > 0 ) {
151
                    $self->add_message( { message => 'error_delbiblio_active_orders' } );
152
                }
153
                elsif ( $biblio->subscriptions->count > 0 ) {
154
                    $self->add_message( { message => 'error_delbiblio_subscriptions' } );
155
                }
156
                else { # $biblio->items->count > 0
157
                    $self->add_message( { message => 'error_delbiblio_items' } );
158
                }
145
            }
159
            }
146
        }
160
        }
147
    }
161
    }
(-)a/t/db_dependent/Koha/Acquisition/Order.t (-12 / +10 lines)
Lines 619-625 subtest 'cancel() tests' => sub { Link Here
619
                cancellationreason      => undef,
619
                cancellationreason      => undef,
620
            }
620
            }
621
        }
621
        }
622
    )->reset_messages; # reset them as TestBuilder doesn't call new
622
    );
623
    $order->add_item( $item->id );
623
    $order->add_item( $item->id );
624
624
625
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
625
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
Lines 651-657 subtest 'cancel() tests' => sub { Link Here
651
651
652
    C4::Circulation::AddReturn( $item->barcode );
652
    C4::Circulation::AddReturn( $item->barcode );
653
653
654
    $order->reset_messages;
654
    $order = Koha::Acquisition::Orders->find($order->ordernumber);
655
    $order->cancel({ reason => $reason })
655
    $order->cancel({ reason => $reason })
656
          ->discard_changes;
656
          ->discard_changes;
657
657
Lines 684-690 subtest 'cancel() tests' => sub { Link Here
684
                cancellationreason      => undef,
684
                cancellationreason      => undef,
685
            }
685
            }
686
        }
686
        }
687
    )->reset_messages;
687
    );
688
    $order->add_item( $item_1->id );
688
    $order->add_item( $item_1->id );
689
689
690
    $order->cancel({ reason => $reason, delete_biblio => 1 })
690
    $order->cancel({ reason => $reason, delete_biblio => 1 })
Lines 697-703 subtest 'cancel() tests' => sub { Link Here
697
    is( ref(Koha::Items->find($item_2->id)), 'Koha::Item', 'The item is still present' );
697
    is( ref(Koha::Items->find($item_2->id)), 'Koha::Item', 'The item is still present' );
698
    is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' );
698
    is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' );
699
    @messages = @{ $order->messages };
699
    @messages = @{ $order->messages };
700
    is( $messages[0]->message, 'error_delbiblio', 'Cannot delete biblio and it gets notified' );
700
    is( $messages[0]->message, 'error_delbiblio_items', 'Cannot delete biblio and it gets notified' );
701
701
702
    # Scenario:
702
    # Scenario:
703
    # * order with one item attached
703
    # * order with one item attached
Lines 719-725 subtest 'cancel() tests' => sub { Link Here
719
                cancellationreason      => undef,
719
                cancellationreason      => undef,
720
            }
720
            }
721
        }
721
        }
722
    )->reset_messages;
722
    );
723
    $order->add_item( $item->id );
723
    $order->add_item( $item->id );
724
724
725
    # Add another order
725
    # Add another order
Lines 744-750 subtest 'cancel() tests' => sub { Link Here
744
    is( Koha::Items->find($item->id), undef, 'The item is no longer present' );
744
    is( Koha::Items->find($item->id), undef, 'The item is no longer present' );
745
    is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' );
745
    is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' );
746
    @messages = @{ $order->messages };
746
    @messages = @{ $order->messages };
747
    is( $messages[0]->message, 'error_delbiblio', 'Cannot delete biblio and it gets notified' );
747
    is( $messages[0]->message, 'error_delbiblio_active_orders', 'Cannot delete biblio and it gets notified' );
748
748
749
    # Scenario:
749
    # Scenario:
750
    # * order with one item attached
750
    # * order with one item attached
Lines 766-772 subtest 'cancel() tests' => sub { Link Here
766
                cancellationreason      => undef,
766
                cancellationreason      => undef,
767
            }
767
            }
768
        }
768
        }
769
    )->reset_messages;
769
    );
770
    $order->add_item( $item->id );
770
    $order->add_item( $item->id );
771
771
772
    # Add a subscription
772
    # Add a subscription
Lines 788-794 subtest 'cancel() tests' => sub { Link Here
788
    is( Koha::Items->find($item->id), undef, 'The item is no longer present' );
788
    is( Koha::Items->find($item->id), undef, 'The item is no longer present' );
789
    is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' );
789
    is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' );
790
    @messages = @{ $order->messages };
790
    @messages = @{ $order->messages };
791
    is( $messages[0]->message, 'error_delbiblio', 'Cannot delete biblio and it gets notified' );
791
    is( $messages[0]->message, 'error_delbiblio_subscriptions', 'Cannot delete biblio and it gets notified' );
792
792
793
    # Scenario:
793
    # Scenario:
794
    # * order with one item attached
794
    # * order with one item attached
Lines 812-820 subtest 'cancel() tests' => sub { Link Here
812
    );
812
    );
813
    $order->add_item( $item->id );
813
    $order->add_item( $item->id );
814
814
815
    $order->cancel({ reason => $reason, delete_biblio => 1 });
815
    $order->cancel({ reason => $reason, delete_biblio => 1 })
816
    # refresh the order object
816
          ->discard_changes;
817
    $order->discard_changes;
818
817
819
    is( $order->orderstatus, 'cancelled', 'Order is not marked as cancelled' );
818
    is( $order->orderstatus, 'cancelled', 'Order is not marked as cancelled' );
820
    isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is not undef' );
819
    isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is not undef' );
821
- 

Return to bug 26515