Bug 29283

Summary: Cannot delete basket with cancelled order for deleted biblio
Product: Koha Reporter: Andrew Fuerste-Henry <andrewfh>
Component: AcquisitionsAssignee: Nick Clemens <nick>
Status: CLOSED FIXED QA Contact: Joonas Kylmälä <joonas.kylmala>
Severity: major    
Priority: P5 - low CC: dcook, fridolin.somers, jonathan.druart, joonas.kylmala, kyle, m.de.rooy, victor
Version: master   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29658
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
21.11.00,21.05.05,20.11.12
Bug Depends on: 23166    
Bug Blocks:    
Attachments: Bug 29283: Don't attempt to cancel cancelled orders
Bug 29283: Don't attempt to cancel cancelled orders
Bug 29283: Don't attempt to cancel cancelled orders
Bug 29283: (QA follow-up) Remove code duplication

Description Andrew Fuerste-Henry 2021-10-20 11:49:34 UTC
To recreate:
- have a basket with at least one order
- click "Cancel order and delete catalog record", confirm cancellation of order and deletion of bib
- click "Delete basket", confirm deletion
- get error "Cannot insert order: Mandatory parameter biblionumber is missing at /kohadevbox/koha/acqui/basket.pl line 136.
 at /usr/share/perl/5.28/Carp.pm line 289"
Comment 1 Nick Clemens 2021-10-20 13:10:31 UTC
Created attachment 126585 [details] [review]
Bug 29283: Don't attempt to cancel cancelled orders

When deleting a basket we cancel all the contained orders - when a
basket contains an order that was previously cancelled this can cause
an error if the biblio was deleted

When picking the orders to cancel, we should limit our search
to those not already cancelled.

To test:
- have a basket with at least one order
- click "Cancel order and delete catalog record", confirm cancellation of order and deletion of bib
- click "Delete basket", confirm deletion
- get error "Cannot insert order: Mandatory parameter biblionumber is missing at /kohadevbox/koha/acqui/basket.pl line 136.
 at /usr/share/perl/5.28/Carp.pm line 289"
- apply patch
- restart
- delete the basket
- success!
Comment 2 Andrew Fuerste-Henry 2021-10-20 14:13:11 UTC
Created attachment 126589 [details] [review]
Bug 29283: Don't attempt to cancel cancelled orders

When deleting a basket we cancel all the contained orders - when a
basket contains an order that was previously cancelled this can cause
an error if the biblio was deleted

When picking the orders to cancel, we should limit our search
to those not already cancelled.

To test:
- have a basket with at least one order
- click "Cancel order and delete catalog record", confirm cancellation of order and deletion of bib
- click "Delete basket", confirm deletion
- get error "Cannot insert order: Mandatory parameter biblionumber is missing at /kohadevbox/koha/acqui/basket.pl line 136.
 at /usr/share/perl/5.28/Carp.pm line 289"
- apply patch
- restart
- delete the basket
- success!

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Comment 3 Joonas Kylmälä 2021-10-31 12:26:09 UTC
Created attachment 127134 [details] [review]
Bug 29283: Don't attempt to cancel cancelled orders

When deleting a basket we cancel all the contained orders - when a
basket contains an order that was previously cancelled this can cause
an error if the biblio was deleted

When picking the orders to cancel, we should limit our search
to those not already cancelled.

To test:
- have a basket with at least one order
- click "Cancel order and delete catalog record", confirm cancellation of order and deletion of bib
- click "Delete basket", confirm deletion
- get error "Cannot insert order: Mandatory parameter biblionumber is missing at /kohadevbox/koha/acqui/basket.pl line 136.
 at /usr/share/perl/5.28/Carp.pm line 289"
- apply patch
- restart
- delete the basket
- success!

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi>
Comment 4 Joonas Kylmälä 2021-10-31 12:26:13 UTC
Created attachment 127135 [details] [review]
Bug 29283: (QA follow-up) Remove code duplication

We have already a search filter for active orders.

Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi>
Comment 5 Jonathan Druart 2021-11-02 15:54:07 UTC
Pushed to master for 21.11, thanks to everybody involved!
Comment 6 Kyle M Hall 2021-11-05 12:37:13 UTC
Pushed to 21.05.x for 21.05.05
Comment 7 Fridolin Somers 2021-11-11 00:43:45 UTC
Depends on Bug 23166 which added filter_by_current()
Comment 8 Fridolin Somers 2021-11-11 00:44:30 UTC
Pushed to 20.11.x for 20.11.12
Comment 9 Victor Grousset/tuxayo 2021-11-16 07:32:33 UTC
Missing dependencies for 20.05.x, not affected after testing, no backport.
Comment 10 Marcel de Rooy 2021-12-08 13:26:49 UTC
Found something similar:

Cannot insert order: Mandatory parameter biblionumber is missing at /usr/share/koha/acqui/cancelorder.pl line 60.
 at /usr/share/perl/5.28/Carp.pm line 289
        Carp::croak('Cannot insert order: Mandatory parameter biblionumber is missing') called at /usr/share/koha/Koha/Acquisition/Order.pm line 79
Koha::Acquisition::Order::store('Koha::Acquisition::Order=HASH(0x55f3760e2860)') called at /usr/share/koha/Koha/Acquisition/Order.pm line 189
Koha::Acquisition::Order::cancel('Koha::Acquisition::Order=HASH(0x55f3760e2860)', 'HASH(0x55f375a17ec0)') called at /usr/share/koha/acqui/cancelorder.pl line 60

cancelorder L60 (20.11) shows
my $order  = Koha::Acquisition::Orders->find($ordernumber);
L60 $order->cancel({ reason => $reason, delete_biblio => $delete_biblio });

I am not sure how to recreate this one actually. I found it in the logs.
The only way I found is opening the basket twice. Delete order in the first tab, and now delete it in the second. The second tab will crash.
Comment 11 Marcel de Rooy 2021-12-08 13:46:53 UTC
Opened bug 29658