Bug 33098: Revert suggestion status when orders are cancelled
This enhancement will revert the status of a suggestion from ORDERED to ACCEPTED when an order made from a suggestion is cancelled. To test: 1. Log into the OPAC and go to purchase suggestions 2. Add a new purchase suggestion 3. Log into the staff interface. The suggestion will show on the home page 4. Select the suggestion and mark it as Accepted 5. Go to Acquisitions. Find or create a basket 6. Add an order to the basket from a suggestion 7. You'll be redirected to the suggestions page. Click the order button next to your suggestion 8. Fill out the order details as normal and confirm the order. 9. In a new tab, go to the suggestions management page and confirm the suggestion now shows as ORDERED. 10. In the other tab with your basket, cancel the order you just made from the suggestion. 11. Refresh the suggestions management tab. Confirm the suggestion now shows as ACCEPTED. 12. Confirm tests pass t/db_dependent/Koha/Acquisition/Order.t Sponsored-by: Waikato Institute of Technology Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com> Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
dedbbe6a06
commit
8c663b9df3
2 changed files with 55 additions and 1 deletions
|
@ -21,6 +21,7 @@ use Carp qw( croak );
|
|||
|
||||
use C4::Biblio qw( DelBiblio );
|
||||
use C4::Acquisition;
|
||||
use C4::Suggestions qw( ModSuggestion );
|
||||
|
||||
use Koha::Acquisition::Baskets;
|
||||
use Koha::Acquisition::Funds;
|
||||
|
@ -144,6 +145,18 @@ sub cancel {
|
|||
}
|
||||
}
|
||||
|
||||
# If ordered from a suggestion, revert the suggestion status to ACCEPTED
|
||||
my $suggestion = Koha::Suggestions->find({ biblionumber => $self->biblionumber, status => "ORDERED" });
|
||||
if ( $suggestion and $suggestion->id ) {
|
||||
ModSuggestion(
|
||||
{
|
||||
suggestionid => $suggestion->id,
|
||||
biblionumber => $self->biblionumber,
|
||||
STATUS => 'ACCEPTED',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
my $biblio = $self->biblio;
|
||||
if ( $biblio and $delete_biblio ) {
|
||||
|
||||
|
|
|
@ -655,7 +655,7 @@ subtest 'creator ()' => sub {
|
|||
|
||||
subtest 'cancel() tests' => sub {
|
||||
|
||||
plan tests => 54;
|
||||
plan tests => 56;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
|
@ -891,6 +891,47 @@ subtest 'cancel() tests' => sub {
|
|||
@messages = @{ $order->object_messages };
|
||||
is( scalar @messages, 0, 'No errors' );
|
||||
|
||||
# Scenario:
|
||||
# * order made from a suggestion with same biblionumber
|
||||
# => order is cancelled
|
||||
# => suggestion status is changed to ACCEPTED
|
||||
|
||||
$item = $builder->build_sample_item;
|
||||
$biblio_id = $item->biblionumber;
|
||||
|
||||
# Add the suggestion
|
||||
my $suggestion = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Suggestions',
|
||||
value => {
|
||||
biblionumber => $biblio_id,
|
||||
suggesteddate => dt_from_string,
|
||||
STATUS => 'ORDERED',
|
||||
archived => 0,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$order = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Acquisition::Orders',
|
||||
value => {
|
||||
orderstatus => 'new',
|
||||
biblionumber => $biblio_id,
|
||||
datecancellationprinted => undef,
|
||||
cancellationreason => undef,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$order->cancel({ reason => $reason })
|
||||
->discard_changes;
|
||||
|
||||
$suggestion = Koha::Suggestions->find( $suggestion->id );
|
||||
|
||||
is( $order->orderstatus, 'cancelled', 'Order is marked as cancelled' );
|
||||
is( $suggestion->STATUS, 'ACCEPTED', 'Suggestion status is correctly reverted after order is cancelled' );
|
||||
|
||||
# Scenario:
|
||||
# * order with two items attached
|
||||
# * one of the items is on loan
|
||||
|
|
Loading…
Reference in a new issue