Bug 35273 - When editing items on receive, aqorders_items is not updated correctly
Summary: When editing items on receive, aqorders_items is not updated correctly
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Acquisitions (show other bugs)
Version: Main
Hardware: All All
: P5 - low major (vote)
Assignee: Jonathan Druart
QA Contact: Marcel de Rooy
URL:
Keywords:
: 35244 (view as bug list)
Depends on: 8179
Blocks:
  Show dependency treegraph
 
Reported: 2023-11-06 22:24 UTC by Katrin Fischer
Modified: 2023-11-16 15:04 UTC (History)
8 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.11.00,23.05.06


Attachments
Bug 35273: Fix item selection when receiving (1.18 KB, patch)
2023-11-07 10:24 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 35273: Fix item selection when receiving (1.88 KB, patch)
2023-11-09 21:15 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 35273: Fix item selection when receiving (1.97 KB, patch)
2023-11-10 10:33 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Katrin Fischer 2023-11-06 22:24:48 UTC
I see something strange there:

* Create a basket with creating items on order
* Create an order line with 3 items
* Close basked
* Receive shipment
* Edit first item displayed, add barcode
* Check checkbox and receive
* Verify the order line has been split 2:1
* Receive again - notice all 3 items are showing. It should only be the remaining 2.
Comment 1 Katrin Fischer 2023-11-06 22:25:26 UTC
Note: ordernumber in aqorders.items was not updated correctly to the new ordernumber.
Comment 2 Jonathan Druart 2023-11-07 09:43:41 UTC
I don't recreate this on master.

MariaDB [koha_kohadev]> select * from aqorders_items;
+-------------+------------+---------------------+
| ordernumber | itemnumber | timestamp           |
+-------------+------------+---------------------+
|           2 |        973 | 2023-11-07 09:41:56 |
|           1 |        974 | 2023-11-07 09:41:07 |
|           1 |        975 | 2023-11-07 09:41:07 |
+-------------+------------+---------------------+
Comment 3 Katrin Fischer 2023-11-07 09:47:54 UTC
I have tested it multiple times on master last night, with the same and a new order.

I had tested bug 35244 and set up the preferences:

*  AcqItemSetSubfieldsWhenReceiptIsCancelled: 7=-1
*  AcqItemSetSubfieldsWhenReceived: 7=1

Could this be the difference? 

Did you use the "Edit" link from the item table on the receive page?
Comment 4 Katrin Fischer 2023-11-07 10:16:29 UTC
I hope to have narrowed it down some more:

* If you receive/mark an item for receive that you haven't edited, it works ok.
* If you mark an item you have edited, it will fail to properly receive.
Comment 5 Jonathan Druart 2023-11-07 10:24:18 UTC
Created attachment 158587 [details] [review]
Bug 35273: Fix item selection when receiving
Comment 6 Jonathan Druart 2023-11-07 11:04:09 UTC
The problem is coming around this code:

 468         var _build_item = function(item, tr) {
 469             var chb = $('<input type="checkbox" name="items_to_receive" value="'+item.item_id+'" />')
 470                 .prop('checked', item._checked)
 471                 .change(function() {
 472                     item._checked = $(this).prop('checked');
 473                 });


496         function PopupEditPage(biblionumber, itemnumber) {

 509                         success: function(item) {
 510                             var tr = $("#item_"+itemnumber);
 511                             item._checked = $(tr).find('input[type="checkbox"]').prop('checked');
 512                             tr.html('');
 513                             _build_item(item, tr);

When the popup page is opened we lost the on change trigger (because we recreate the tr).

This is ugly but the least intrusive I have found to not introduce regressions...
Comment 7 Katrin Fischer 2023-11-09 21:15:39 UTC
Created attachment 158767 [details] [review]
Bug 35273: Fix item selection when receiving

For partial receives with items created on order, the
aqorders_items table was not correctly updated when only
some of the ordered items were received.

To test:
1) Create a basket with creating items on order
2) Create an order line with 3 items
3) Close basked
4) Receive shipment and create invoice
5) Receive your created order line
6) Edit first item displayed, add barcode
7) Check checkbox and receive
8) Verify the order line has been split 2:1
9) Receive again - notice all 3 items are showing.
  We should only see the remaining 2
10) Undo receive
11) Apply patch
12) Repeat steps 5)-9)
13) Verify that in step 9) only the remaining 2 items display now.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 8 Marcel de Rooy 2023-11-10 10:03:24 UTC
Seeing this crash passing by:
Can't call method "edi_order" on an undefined value at /usr/share/koha/acqui/basket.pl line 381

Seems unrelated.
Comment 9 Marcel de Rooy 2023-11-10 10:18:32 UTC
Just a keyboard thing: Hitting Enter on Add item does not work.
Out of scope here.
Comment 10 Marcel de Rooy 2023-11-10 10:33:23 UTC
Created attachment 158796 [details] [review]
Bug 35273: Fix item selection when receiving

For partial receives with items created on order, the
aqorders_items table was not correctly updated when only
some of the ordered items were received.

To test:
1) Create a basket with creating items on order
2) Create an order line with 3 items
3) Close basked
4) Receive shipment and create invoice
5) Receive your created order line
6) Edit first item displayed, add barcode
7) Check checkbox and receive
8) Verify the order line has been split 2:1
9) Receive again - notice all 3 items are showing.
  We should only see the remaining 2
10) Undo receive
11) Apply patch
12) Repeat steps 5)-9)
13) Verify that in step 9) only the remaining 2 items display now.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 11 Marcel de Rooy 2023-11-10 10:34:15 UTC
Passing QA but noting that this code is kind of unreadable. Need to study a day to see whats going on there..
Comment 12 Tomás Cohen Arazi 2023-11-10 14:02:40 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 13 Fridolin Somers 2023-11-11 08:00:22 UTC
Pushed to 23.05.x for 23.05.06
Comment 14 Klas Blomberg 2023-11-15 14:21:15 UTC
*** Bug 35244 has been marked as a duplicate of this bug. ***
Comment 15 Klas Blomberg 2023-11-16 11:06:16 UTC
We have added this patch on our 23.05.04

It works as long as we choose English as language for the staff client, but not when we change to Swedish
Comment 16 Katrin Fischer 2023-11-16 12:31:00 UTC
(In reply to Klas Blomberg from comment #15)
> We have added this patch on our 23.05.04
> 
> It works as long as we choose English as language for the staff client, but
> not when we change to Swedish

Hi Klas, did you update both the templates for en and Swedish? The patch only edits the English ones. Depending on how you installed and your customizations, you can koha-translate --update or make the changes in the second file manually.
Comment 17 Klas Blomberg 2023-11-16 15:04:39 UTC
Tanks - now it's working in both languages