Bug 36182

Summary: Add vendor column to holdings table
Product: Koha Reporter: Pedro Amorim <pedro.amorim>
Component: Staff interfaceAssignee: Pedro Amorim <pedro.amorim>
Status: Pushed to main --- QA Contact: Testopia <testopia>
Severity: minor    
Priority: P5 - low CC: bernard.scaife, esther.melander, gmcharlt, jonathan.druart, kyle, lucas, m.de.rooy, martin.renvoize, pedro.amorim
Version: MainKeywords: release-notes-needed
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.11.00
Circulation function:
Attachments: Bug 36182: Add booksellerid column to holdings table
[23.11] Bug 36182: Add booksellerid column to holdings table
Bug 36182: Add booksellerid columns to holdings table
Bug 36182: Add booksellerid columns to holdings table
Bug 36182: Show vendor name if acquisition_source is a vendor_id
Receive orderline with item
Bug 36182: Add booksellerid columns to holdings table
Bug 36182: Show vendor name if acquisition_source is a vendor_id

Description Pedro Amorim 2024-02-27 17:15:17 UTC

    
Comment 1 Pedro Amorim 2024-02-27 17:19:13 UTC
Created attachment 162515 [details] [review]
Bug 36182: Add booksellerid column to holdings table

1) Apply patch, reset_all
2) Configure holdings_table, visit:
<staff_url>/cgi-bin/koha/admin/columns_settings.pl?module=catalogue&page=detail&table=holdings_table
3) Confirm holdings_booksellerid is there and is hidden by default
4) Visit a record:
<staff_url>/cgi-bin/koha/catalogue/detail.pl?biblionumber=76
5) Edit one of the items and add a value to field 'e' Source of acquisition
6) Go back to the record and click on the 'Columns' above the table
7) Click 'Source of acquisition'. Confirm it shows as expected
Comment 2 Lucas Gass (lukeg) 2024-02-27 21:42:43 UTC
Created attachment 162519 [details] [review]
[23.11] Bug 36182: Add booksellerid column to holdings table

1) Apply patch, reset_all
2) Configure holdings_table, visit:
<staff_url>/cgi-bin/koha/admin/columns_settings.pl?module=catalogue&page=detail&table=holdings_table
3) Confirm holdings_booksellerid is there and is hidden by default
4) Visit a record:
<staff_url>/cgi-bin/koha/catalogue/detail.pl?biblionumber=76
5) Edit one of the items and add a value to field 'e' Source of acquisition
6) Go back to the record and click on the 'Columns' above the table
7) Click 'Source of acquisition'. Confirm it shows as expected

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 3 Katrin Fischer 2024-02-27 22:14:26 UTC
[comment not intended as a blocker]

Hi Pedro, 

I wonder if it would make sense to resolve the ID to the vendor's name. Could be a separate bug.

To explain:
Libraries not using the acq module like to write a vendor name in the field in the cataloguing editor as there is no plugin or similar to search for a vendor to create a proper link (there is a bug for that somewhere...)
For libraries using the acq module, Koha adds the booksellerid of the vendor automatically in the acquisition process. 
Some libraries will have a mix of both (retro-cataloguing, migrated data, donations, etc.)

If we have the ID, we won't resolve to the vendor name with this patch and there is no easy way for the library to figure out the actual vendor. We neither allow searching by booksellerid, nor do we display the ID on the vendor's detail page. You can only see it in the URL.

I see that the items tab in the staff interface (moredetails.pl) uses this code:

    if ($item_info->{'basketno'}){
        my $basket = GetBasket($item_info->{'basketno'});
        my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
        $item_info->{'vendor'} = $bookseller->name;
    }

So if an order for the item exists, it gets resolved to the name, otherwise it remains as is. 

Also something that could probably be improved on. But re-using the logic would give us a consistent display/behavior between items tab and holdings table.
Comment 4 Pedro Amorim 2024-02-28 09:12:24 UTC
Hi Katrin, thanks for the insight, definitely something to add as a follow-up.
I'll take a look at adding it soon.
Comment 5 Pedro Amorim 2024-02-28 09:26:41 UTC
(In reply to Katrin Fischer from comment #3)
> For libraries using the acq module, Koha adds the booksellerid of the vendor
> automatically in the acquisition process. 

I'm trying to go through with this use case but failing. Are you able to provide simple instructions on how to do it?
I'm currently creating an order from a suggestion, it creates a biblio record but no item(s), and not with the vendor id in booksellerid. Thanks!
Comment 6 Katrin Fischer 2024-02-28 18:52:58 UTC
I can't do a full run now, but when you create the basket, you need to select either "create on order" or "create on receive" I believe. I can try to test soon, but no guarantees for this week I am afraid :(
Comment 7 Jonathan Druart 2024-02-29 09:04:45 UTC
On top of bug 33568 please.
Comment 8 Marcel de Rooy 2024-04-05 08:26:40 UTC
(In reply to Jonathan Druart from comment #7)
> On top of bug 33568 please.

Ping Pedro
Comment 9 Pedro Amorim 2024-04-22 11:23:58 UTC
Created attachment 165265 [details] [review]
Bug 36182: Add booksellerid columns to holdings table

1) Apply patch, reset_all
2) Configure holdings_table, visit:
<staff_url>/cgi-bin/koha/admin/columns_settings.pl?module=catalogue&page=detail&table=holdings_table
3) Confirm holdings_booksellerid is there and is hidden by default
4) Visit a record:
<staff_url>/cgi-bin/koha/catalogue/detail.pl?biblionumber=76
5) Edit one of the items and add a value to field 'e' Source of acquisition
5.5) You may need to click the 'show filters' link in order to have the 'Columns' table button show up
6) Go back to the record and click on the 'Columns' above the table
7) Click 'Source of acquisition'. Confirm it shows as expected
Comment 10 Pedro Amorim 2024-04-22 11:31:03 UTC
Hi guys

I've left the original patch as 23.11 for backport, re-tested, works as intended. Although this is a small enhancement and not a bugfix, would be great to have this backported if possible as it'd be one less bug that we'd have to backport manually to our customers. 

Submitted new patch based on master on top of bug 33568.

(In reply to Katrin Fischer from comment #3)
> [comment not intended as a blocker]
> 
> Hi Pedro, 
> 
> I wonder if it would make sense to resolve the ID to the vendor's name.
> Could be a separate bug.
> 
> To explain:
> Libraries not using the acq module like to write a vendor name in the field
> in the cataloguing editor as there is no plugin or similar to search for a
> vendor to create a proper link (there is a bug for that somewhere...)
> For libraries using the acq module, Koha adds the booksellerid of the vendor
> automatically in the acquisition process. 
> Some libraries will have a mix of both (retro-cataloguing, migrated data,
> donations, etc.)
> 
> If we have the ID, we won't resolve to the vendor name with this patch and
> there is no easy way for the library to figure out the actual vendor. We
> neither allow searching by booksellerid, nor do we display the ID on the
> vendor's detail page. You can only see it in the URL.
> 
> I see that the items tab in the staff interface (moredetails.pl) uses this
> code:
> 
>     if ($item_info->{'basketno'}){
>         my $basket = GetBasket($item_info->{'basketno'});
>         my $bookseller = Koha::Acquisition::Booksellers->find(
> $basket->{booksellerid} );
>         $item_info->{'vendor'} = $bookseller->name;
>     }
> 
> So if an order for the item exists, it gets resolved to the name, otherwise
> it remains as is. 
> 
> Also something that could probably be improved on. But re-using the logic
> would give us a consistent display/behavior between items tab and holdings
> table.

Would it be okay if this is handled in a different bug as further enhancement with a detailed test plan? I'm still having a hard time reproducing this as I don't think I'm experienced enough in acquisitions to get this use-case going.
Thanks.
Comment 11 Lucas Gass (lukeg) 2024-04-22 17:08:08 UTC
Needs rebased now that we have Bug 36182.
Comment 12 Pedro Amorim 2024-04-22 18:21:37 UTC
(In reply to Lucas Gass from comment #11)
> Needs rebased now that we have Bug 36182.

Patch applies for me, double-checking: have you applied interactively and commented the [23.11] one?
Comment 13 Lucas Gass (lukeg) 2024-04-22 19:11:22 UTC
(In reply to Pedro Amorim from comment #12)
> (In reply to Lucas Gass from comment #11)
> > Needs rebased now that we have Bug 36182.
> 
> Patch applies for me, double-checking: have you applied interactively and
> commented the [23.11] one?

My mistake, I only noticed the 23.11 patch.
Comment 14 Lucas Gass (lukeg) 2024-04-24 17:26:51 UTC
Created attachment 165485 [details] [review]
Bug 36182: Add booksellerid columns to holdings table

1) Apply patch, reset_all
2) Configure holdings_table, visit:
<staff_url>/cgi-bin/koha/admin/columns_settings.pl?module=catalogue&page=detail&table=holdings_table
3) Confirm holdings_booksellerid is there and is hidden by default
4) Visit a record:
<staff_url>/cgi-bin/koha/catalogue/detail.pl?biblionumber=76
5) Edit one of the items and add a value to field 'e' Source of acquisition
5.5) You may need to click the 'show filters' link in order to have the 'Columns' table button show up
6) Go back to the record and click on the 'Columns' above the table
7) Click 'Source of acquisition'. Confirm it shows as expected

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 15 Katrin Fischer 2024-05-01 20:09:56 UTC
*** Bug 36747 has been marked as a duplicate of this bug. ***
Comment 16 Katrin Fischer 2024-05-06 08:23:41 UTC
This will still only display the vendor ID for all libraries using the acquisition module with item creation. I think as such it's not really useful right now and the change requested would not add much extra work.

See: bug 36750
(In reply to Keith Dembek from comment #17)
> +1 for me, in our system I'm probably the only current staff member who
> would know a vendor #, so having the name would be very helpful for other
> staff!
Comment 17 Pedro Amorim 2024-05-07 08:54:39 UTC
(In reply to Katrin Fischer from comment #16)
> This will still only display the vendor ID for all libraries using the
> acquisition module with item creation. I think as such it's not really
> useful right now and the change requested would not add much extra work.
> 
> See: bug 36750
> (In reply to Keith Dembek from comment #17)
> > +1 for me, in our system I'm probably the only current staff member who
> > would know a vendor #, so having the name would be very helpful for other
> > staff!

Is this referring to the below?
I wonder if it would make sense to resolve the ID to the vendor's name. Could be a separate bug.

Could I please have a test plan for this? I understand the requirement but don't know how to "link" the stuff that's needed here to come up with this.
Comment 18 Katrin Fischer 2024-05-07 09:15:05 UTC
I checked in our production systems with acq and the booksellerid is always set to the vendor id. So this should work:

1) Create a new basket, make sure you set item creation to "on order"
2) Create an order line with one or more items
3) Close the basket
4) Receive shipment for that vendor
5) Receive your order line with the item
6) Check the item - some fields should have been set by the acq module, like price and booksellerid.

I feel the feature as suggested is not useful and might be confusing to a lot of libraries even. I made a suggestion on how to resolve to vendor name in comment#3, it's the same code used on the items tab (moredetails.pl), so it would give us consistency to use the same logic.

I was hoping to spot the logic in a proper module, but... *sigh*

https://git.bsz-bw.de/koha/koha/-/blob/master/acqui/finishreceive.pl#L181

my $new_order_object = Koha::Acquisition::Orders->find( $new_ordernumber ); 

# FIXME we should not need to refetch it
my $items = $new_order_object->items;
while ( my $item = $items->next )  {
    $item->update({
        booksellerid => $booksellerid,
        dateaccessioned => $datereceived,
        datelastseen => $datereceived,
        price => $unitprice,
        replacementprice => $replacementprice,
        replacementpricedate => $datereceived,
    });
}
Comment 19 Pedro Amorim 2024-05-07 12:50:11 UTC
Created attachment 166276 [details] [review]
Bug 36182: Show vendor name if acquisition_source is a vendor_id

This will make it so if acquisition_source is of an existing vendor_id, it'll show the vendor name instead of the id.
If it's not of an existing vendor_id, show the raw value instead.

I'm not 100% happy with this patch as it adds an edge case to Item::strings_map but I believe the only alternative
is to make 952$e Source of acquisition an AV field in the default framework.
Not only that, but this would have to be an AV field of type 'vendors' that'd have to allow to pick from existing vendors (similar to current 'branches').
The above is a ton more work than initial suggestions would imply.
Happy to be proven wrong (in fact, hoping I am).

This is compatible with main Koha only, not backportable to 23.11
Comment 20 Pedro Amorim 2024-05-07 12:52:46 UTC
Created attachment 166277 [details]
Receive orderline with item

(In reply to Katrin Fischer from comment #18)
> I checked in our production systems with acq and the booksellerid is always
> set to the vendor id. So this should work:
> 
> 1) Create a new basket, make sure you set item creation to "on order"
> 2) Create an order line with one or more items
> 3) Close the basket
> 4) Receive shipment for that vendor
> 5) Receive your order line with the item
> 6) Check the item - some fields should have been set by the acq module, like
> price and booksellerid.

Couldn't go through step 5, the items table shows empty and the "Confirm" button disabled, but went ahead with the development anyway changing data manually to an existing vendor_id.
Comment 21 Katrin Fischer 2024-05-07 12:54:28 UTC
Comment on attachment 166277 [details]
Receive orderline with item

That doesn't look right. I hope we didn't break something :( You should see your items on the left side if you have created them "on order" within the table.
To unlock the button you'd then need to checkbox an item in the table OR to add something in "quantity received".
Comment 22 Pedro Amorim 2024-08-16 14:03:25 UTC
This still applies.
Note that when applying on main, skip the [23.11] patch.
Likewise, when applying on 23.11.x, apply only the [23.11] patch.
Comment 23 Katrin Fischer 2024-09-02 09:53:50 UTC
I don't want to make a mess here, could you please rebase?
Happy to have another look then!
Comment 24 Pedro Amorim 2024-09-02 15:04:14 UTC
(In reply to Katrin Fischer from comment #23)
> I don't want to make a mess here, could you please rebase?
> Happy to have another look then!

This still applies.
Note that when applying on main, skip the [23.11] patch.
Likewise, when applying on 23.11.x, apply only the [23.11] patch.
Comment 25 Katrin Fischer 2024-09-02 15:13:48 UTC
That's probably what I missed. Will have another go once we got Jenkins happy again.
Comment 26 Katrin Fischer 2024-11-11 16:52:02 UTC
(In reply to Katrin Fischer from comment #25)
> That's probably what I missed. Will have another go once we got Jenkins
> happy again.

Sorry, I had missed that one. Having a look now.
Comment 27 Katrin Fischer 2024-11-11 16:55:09 UTC
The patch no longer applies, I'll keep the rel_24_11_candidate as this is "mostly display" bug. 

Apply? [(y)es, (n)o, (i)nteractive] y
Applying: Bug 36182: Add booksellerid column to holdings table
Using index info to reconstruct a base tree...
M	admin/columns_settings.yml
M	koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
Falling back to patching base and 3-way merge...
Auto-merging koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
CONFLICT (content): Merge conflict in koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
Auto-merging admin/columns_settings.yml
CONFLICT (content): Merge conflict in admin/columns_settings.yml
error: Failed to merge in the changes.
Patch failed at 0001 Bug 36182: Add booksellerid column to holdings table
hint: Use 'git am --show-current-patch=diff' to see the failed patch
When you have resolved this problem run "git bz apply --continue".
If you would prefer to skip this patch, instead run "git bz apply --skip".
To restore the original branch and stop patching run "git bz apply --abort".
Patch left in /tmp/2311-Bug-36182-Add-booksellerid-column-to-holdings-ujf64c3n.patch
Comment 28 Pedro Amorim 2024-11-12 09:50:09 UTC
Created attachment 174399 [details] [review]
Bug 36182: Add booksellerid columns to holdings table

1) Apply patch, reset_all
2) Configure holdings_table, visit:
<staff_url>/cgi-bin/koha/admin/columns_settings.pl?module=catalogue&page=detail&table=holdings_table
3) Confirm holdings_booksellerid is there and is hidden by default
4) Visit a record:
<staff_url>/cgi-bin/koha/catalogue/detail.pl?biblionumber=76
5) Edit one of the items and add a value to field 'e' Source of acquisition
5.5) You may need to click the 'show filters' link in order to have the 'Columns' table button show up
6) Go back to the record and click on the 'Columns' above the table
7) Click 'Source of acquisition'. Confirm it shows as expected

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 29 Pedro Amorim 2024-11-12 09:50:12 UTC
Created attachment 174400 [details] [review]
Bug 36182: Show vendor name if acquisition_source is a vendor_id

This will make it so if acquisition_source is of an existing vendor_id, it'll show the vendor name instead of the id.
If it's not of an existing vendor_id, show the raw value instead.

I'm not 100% happy with this patch as it adds an edge case to Item::strings_map but I believe the only alternative
is to make 952$e Source of acquisition an AV field in the default framework.
Not only that, but this would have to be an AV field of type 'vendors' that'd have to allow to pick from existing vendors (similar to current 'branches').
The above is a ton more work than initial suggestions would imply.
Happy to be proven wrong (in fact, hoping I am).

This is compatible with main Koha only, not backportable to 23.11
Comment 30 Pedro Amorim 2024-11-12 09:51:14 UTC
Updated from "Doesnt apply" to PQA but it was never PQA, it was SO. Changing it back.
Comment 31 Katrin Fischer 2024-11-12 09:57:10 UTC
(In reply to Pedro Amorim from comment #30)
> Updated from "Doesnt apply" to PQA but it was never PQA, it was SO. Changing
> it back.

I had looked at this one last when taking things out of the QA queue as mine was empty... similar situation now. I will come back for this later :)
Comment 32 Katrin Fischer 2024-11-12 16:01:09 UTC
Tested and works, will push to main.
Comment 33 Katrin Fischer 2024-11-12 16:55:23 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 34 Jonathan Druart 2024-11-13 10:40:34 UTC
Is this really working? It's hidden if there is no data, but it's displayed if there is at least one item with a source of acq.

Looks broken for the other columns as well but I am wondering why this has not been caught here.
Comment 35 Katrin Fischer 2024-11-13 10:53:53 UTC
(In reply to Jonathan Druart from comment #34)
> Is this really working? It's hidden if there is no data, but it's displayed
> if there is at least one item with a source of acq.
> 
> Looks broken for the other columns as well but I am wondering why this has
> not been caught here.

Hm I thought that it was hidden by default was expected. I made it visible for testing and then tested with values linked to acq (booksellerid) and plain text entries. I'll need to take another look at what I missed there.