Lines 592-598
subtest 'filter_by_current & filter_by_cancelled' => sub {
Link Here
|
592 |
|
592 |
|
593 |
subtest 'cancel() tests' => sub { |
593 |
subtest 'cancel() tests' => sub { |
594 |
|
594 |
|
595 |
plan tests => 38; |
595 |
plan tests => 52; |
596 |
|
596 |
|
597 |
$schema->storage->txn_begin; |
597 |
$schema->storage->txn_begin; |
598 |
|
598 |
|
Lines 608-620
subtest 'cancel() tests' => sub {
Link Here
|
608 |
# => message about not being able to delete |
608 |
# => message about not being able to delete |
609 |
|
609 |
|
610 |
my $item = $builder->build_sample_item; |
610 |
my $item = $builder->build_sample_item; |
611 |
my $biblio_id = $item->biblio->id; |
611 |
my $biblio_id = $item->biblionumber; |
612 |
my $order = $builder->build_object( |
612 |
my $order = $builder->build_object( |
613 |
{ |
613 |
{ |
614 |
class => 'Koha::Acquisition::Orders', |
614 |
class => 'Koha::Acquisition::Orders', |
615 |
value => { |
615 |
value => { |
616 |
orderstatus => 'new', |
616 |
orderstatus => 'new', |
617 |
biblionumber => $item->biblio->id, |
617 |
biblionumber => $item->biblionumber, |
618 |
datecancellationprinted => undef, |
618 |
datecancellationprinted => undef, |
619 |
cancellationreason => undef, |
619 |
cancellationreason => undef, |
620 |
} |
620 |
} |
Lines 625-631
subtest 'cancel() tests' => sub {
Link Here
|
625 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
625 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
626 |
t::lib::Mocks::mock_userenv({ patron => $patron }); |
626 |
t::lib::Mocks::mock_userenv({ patron => $patron }); |
627 |
|
627 |
|
628 |
# Add a checkout so cancelling fails because od 'book_on_loan' |
628 |
# Add a checkout so deleting the item fails because od 'book_on_loan' |
629 |
C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); |
629 |
C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); |
630 |
|
630 |
|
631 |
my $result = $order->cancel({ reason => $reason }); |
631 |
my $result = $order->cancel({ reason => $reason }); |
Lines 672-678
subtest 'cancel() tests' => sub {
Link Here
|
672 |
# => biblio remains untouched |
672 |
# => biblio remains untouched |
673 |
|
673 |
|
674 |
my $item_1 = $builder->build_sample_item; |
674 |
my $item_1 = $builder->build_sample_item; |
675 |
$biblio_id = $item_1->biblio->id; |
675 |
$biblio_id = $item_1->biblionumber; |
676 |
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio_id }); |
676 |
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio_id }); |
677 |
$order = $builder->build_object( |
677 |
$order = $builder->build_object( |
678 |
{ |
678 |
{ |
Lines 708-714
subtest 'cancel() tests' => sub {
Link Here
|
708 |
# => biblio delete error notified |
708 |
# => biblio delete error notified |
709 |
|
709 |
|
710 |
$item = $builder->build_sample_item; |
710 |
$item = $builder->build_sample_item; |
711 |
$biblio_id = $item->biblio->id; |
711 |
$biblio_id = $item->biblionumber; |
712 |
$order = $builder->build_object( |
712 |
$order = $builder->build_object( |
713 |
{ |
713 |
{ |
714 |
class => 'Koha::Acquisition::Orders', |
714 |
class => 'Koha::Acquisition::Orders', |
Lines 755-761
subtest 'cancel() tests' => sub {
Link Here
|
755 |
# => biblio delete error notified |
755 |
# => biblio delete error notified |
756 |
|
756 |
|
757 |
$item = $builder->build_sample_item; |
757 |
$item = $builder->build_sample_item; |
758 |
$biblio_id = $item->biblio->id; |
758 |
$biblio_id = $item->biblionumber; |
759 |
$order = $builder->build_object( |
759 |
$order = $builder->build_object( |
760 |
{ |
760 |
{ |
761 |
class => 'Koha::Acquisition::Orders', |
761 |
class => 'Koha::Acquisition::Orders', |
Lines 798-810
subtest 'cancel() tests' => sub {
Link Here
|
798 |
# => biblio in order is removed |
798 |
# => biblio in order is removed |
799 |
|
799 |
|
800 |
$item = $builder->build_sample_item; |
800 |
$item = $builder->build_sample_item; |
801 |
$biblio_id = $item->biblio->id; |
801 |
$biblio_id = $item->biblionumber; |
802 |
$order = $builder->build_object( |
802 |
$order = $builder->build_object( |
803 |
{ |
803 |
{ |
804 |
class => 'Koha::Acquisition::Orders', |
804 |
class => 'Koha::Acquisition::Orders', |
805 |
value => { |
805 |
value => { |
806 |
orderstatus => 'new', |
806 |
orderstatus => 'new', |
807 |
biblionumber => $item->biblio->id, |
807 |
biblionumber => $item->biblionumber, |
808 |
datecancellationprinted => undef, |
808 |
datecancellationprinted => undef, |
809 |
cancellationreason => undef, |
809 |
cancellationreason => undef, |
810 |
} |
810 |
} |
Lines 823-827
subtest 'cancel() tests' => sub {
Link Here
|
823 |
@messages = @{ $order->messages }; |
823 |
@messages = @{ $order->messages }; |
824 |
is( scalar @messages, 0, 'No errors' ); |
824 |
is( scalar @messages, 0, 'No errors' ); |
825 |
|
825 |
|
|
|
826 |
# Scenario: |
827 |
# * order with two items attached |
828 |
# * one of the items is on loan |
829 |
# => order is cancelled |
830 |
# => item on loan is kept |
831 |
# => the other item is removed |
832 |
# => biblio remains untouched |
833 |
# => biblio delete error notified |
834 |
# => item delete error notified |
835 |
|
836 |
$item_1 = $builder->build_sample_item; |
837 |
$item_2 = $builder->build_sample_item({ biblionumber => $item_1->biblionumber }); |
838 |
my $item_3 = $builder->build_sample_item({ biblionumber => $item_1->biblionumber }); |
839 |
$biblio_id = $item_1->biblionumber; |
840 |
$order = $builder->build_object( |
841 |
{ |
842 |
class => 'Koha::Acquisition::Orders', |
843 |
value => { |
844 |
orderstatus => 'new', |
845 |
biblionumber => $biblio_id, |
846 |
datecancellationprinted => undef, |
847 |
cancellationreason => undef, |
848 |
} |
849 |
} |
850 |
); |
851 |
$order->add_item( $item_1->id ); |
852 |
$order->add_item( $item_2->id ); |
853 |
$order->add_item( $item_3->id ); |
854 |
|
855 |
# Add a checkout so deleting the item fails because od 'book_on_loan' |
856 |
C4::Circulation::AddIssue( $patron->unblessed, $item_2->barcode ); |
857 |
C4::Reserves::AddReserve( |
858 |
{ |
859 |
branchcode => $item_3->holdingbranch, |
860 |
borrowernumber => $patron->borrowernumber, |
861 |
biblionumber => $biblio_id, |
862 |
itemnumber => $item_3->id, |
863 |
found => 'W', |
864 |
} |
865 |
); |
866 |
|
867 |
$order->cancel({ reason => $reason, delete_biblio => 1 }) |
868 |
->discard_changes; |
869 |
|
870 |
is( $order->orderstatus, 'cancelled', 'Order is marked as cancelled' ); |
871 |
isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is set' ); |
872 |
is( $order->cancellationreason, $reason, 'cancellationreason is undef' ); |
873 |
is( Koha::Items->find($item_1->id), undef, 'The item is no longer present' ); |
874 |
is( ref(Koha::Items->find($item_2->id)), 'Koha::Item', 'The on loan item is still present' ); |
875 |
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' ); |
876 |
@messages = @{ $order->messages }; |
877 |
is( $messages[0]->message, 'error_delitem', 'Cannot delete on loan item' ); |
878 |
is( $messages[0]->payload->{item}->id, $item_2->id, 'Cannot delete on loan item' ); |
879 |
is( $messages[0]->payload->{reason}, 'book_on_loan', 'Item on loan notified' ); |
880 |
is( $messages[1]->message, 'error_delitem', 'Cannot delete reserved and found item' ); |
881 |
is( $messages[1]->payload->{item}->id, $item_3->id, 'Cannot delete reserved and found item' ); |
882 |
is( $messages[1]->payload->{reason}, 'book_reserved', 'Item reserved notified' ); |
883 |
is( $messages[2]->message, 'error_delbiblio_items', 'Cannot delete on loan item' ); |
884 |
is( $messages[2]->payload->{biblio}->id, $biblio_id, 'The right biblio is attached' ); |
885 |
|
826 |
$schema->storage->txn_rollback; |
886 |
$schema->storage->txn_rollback; |
827 |
}; |
887 |
}; |
828 |
- |
|
|