Bug 37710

Summary: Remove the marc link when removing an item from a bundle
Product: Koha Reporter: Baptiste Wojtkowski (bwoj) <baptiste.wojtkowski>
Component: CatalogingAssignee: Baptiste Wojtkowski (bwoj) <baptiste.wojtkowski>
Status: BLOCKED --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: jonathan.druart, lucas, m.de.rooy, thibault.keromnes
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: Small patch Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 37996    
Bug Blocks: 38093    
Attachments: Bug 37710: Remove the marc link when removing an item from a bundle
Bug 37710: Add unit tests
Bug 37710: Remove the marc link when removing an item from a bundle
Bug 37710: Add unit tests
Bug 37710: Remove the marc link when removing an item from a bundle

Description Baptiste Wojtkowski (bwoj) 2024-08-22 14:09:25 UTC
A new functionality to automatically add a new MARC link has been added in Bug 29560 (Add option to create MARC links when adding items to bundles). There should also be a way to remove this link when removing the item from the bundle.

Moreover I don't know if this should be a second bug but since the link is not removed, there can be multiple links if the item is added to a new bundle.
Comment 1 Baptiste Wojtkowski (bwoj) 2024-09-20 15:06:55 UTC
Created attachment 171832 [details] [review]
Bug 37710: Remove the marc link when removing an item from a bundle

A new functionality to automatically add a new MARC link has been added in Bug 29560 (Add option to create MARC links when adding items to bundles). There should also be a way to remove this link when removing the item from the bundle.

Moreover I don't know if this should be a second bug but since the link is not removed, there can be multiple links if the item is added to a new bundle.

TEST PLAN:
1 - Create a bundle on an item by changing the 7th character of the
  leader to c (go to the marc, click on the button at the right of the
          field 000 and change the bibliographical level to collection).
2 - Add an item to the bundle (on the biblio, exemplars will have a
  button "manage bundle"->add_to_bundle, fill in a barcode and check "add MARC link")
3 - Check on the MARC that field 461 (UNIMARC) or 773 (MARC21) is
  propperly filled
4 - Remove the item from the bundle
5 - Check that the marc field is still there and remove it manually
6 - APPLY PATCH
7 - Repeat 2-5 -> the field should have been automatically removed
Comment 2 Lucas Gass (lukeg) 2024-09-21 15:21:53 UTC
Can we get some unit tests to cover unlink_marc_host?
Comment 3 Baptiste Wojtkowski (bwoj) 2024-09-24 13:45:35 UTC
Created attachment 171933 [details] [review]
Bug 37710: Add unit tests
Comment 4 Baptiste Wojtkowski (bwoj) 2024-09-24 13:45:37 UTC
Created attachment 171934 [details] [review]
Bug 37710: Remove the marc link when removing an item from a bundle

A new functionality to automatically add a new MARC link has been added in Bug 29560 (Add option to create MARC links when adding items to bundles). There should also be a way to remove this link when removing the item from the bundle.

Moreover I don't know if this should be a second bug but since the link is not removed, there can be multiple links if the item is added to a new bundle.

TEST PLAN:
1 - Apply tests and prove t/db_dependent/Koha/Biblio.t -> should fail
2 - Create a bundle on an item by changing the 7th character of the
  leader to c (go to the marc, click on the button at the right of the
          field 000 and change the bibliographical level to collection).
3 - Add an item to the bundle (on the biblio, exemplars will have a
  button "manage bundle"->add_to_bundle, fill in a barcode and check "add MARC link")
4 - Check on the MARC that field 461 (UNIMARC) or 773 (MARC21) is
  propperly filled
5 - Remove the item from the bundle
6 - Check that the marc field is still there and remove it manually
7 - APPLY PATCH
8 - Repeat 2-5 -> the field should have been automatically removed
9 - Run tests -> should pass

Note: as for link_marc_host, tests assume you are using MARC21
Comment 5 Baptiste Wojtkowski (bwoj) 2024-09-24 13:47:21 UTC
Note : 
In order to prove the behavior properly, I had to create Bug 37996
Comment 6 Thibault Keromnès 2025-01-13 10:24:54 UTC
Created attachment 176427 [details] [review]
Bug 37710: Add unit tests

Signed-off-by: Thibault Keromnes  <thibault.keromnes@univ-paris8.fr>
Comment 7 Thibault Keromnès 2025-01-13 10:24:57 UTC
Created attachment 176428 [details] [review]
Bug 37710: Remove the marc link when removing an item from a bundle

A new functionality to automatically add a new MARC link has been added in Bug 29560 (Add option to create MARC links when adding items to bundles). There should also be a way to remove this link when removing the item from the bundle.

Moreover I don't know if this should be a second bug but since the link is not removed, there can be multiple links if the item is added to a new bundle.

TEST PLAN:
1 - Apply tests and prove t/db_dependent/Koha/Biblio.t -> should fail
2 - Create a bundle on an item by changing the 7th character of the
  leader to c (go to the marc, click on the button at the right of the
          field 000 and change the bibliographical level to collection).
3 - Add an item to the bundle (on the biblio, exemplars will have a
  button "manage bundle"->add_to_bundle, fill in a barcode and check "add MARC link")
4 - Check on the MARC that field 461 (UNIMARC) or 773 (MARC21) is
  propperly filled
5 - Remove the item from the bundle
6 - Check that the marc field is still there and remove it manually
7 - APPLY PATCH
8 - Repeat 2-5 -> the field should have been automatically removed
9 - Run tests -> should pass

Note: as for link_marc_host, tests assume you are using MARC21
Signed-off-by: Thibault Keromnes  <thibault.keromnes@univ-paris8.fr>
Comment 8 Jonathan Druart 2025-01-16 12:57:30 UTC Comment hidden (obsolete)
Comment 9 Jonathan Druart 2025-01-16 12:57:58 UTC
Should not we unlink from Koha::Item->remove_from_bundle?
Comment 10 Baptiste Wojtkowski (bwoj) 2025-01-16 13:17:20 UTC
(In reply to Jonathan Druart from comment #9)
> Should not we unlink from Koha::Item->remove_from_bundle?


In my opinion, here we want that add_to_bundle and remove_from_bundle work the same way. Since add_to_bundle requires calling link_marc_host aside, I would say that we want to build remove_from_bundle the same way, don't you think ?

Hereafter a call to add_to_bundle in Koha/REST/V1/Items.pm

327         my $link = $item->add_to_bundle( $bundle_item, $options );
328         if ($add_link) {
329             $bundle_item->biblio->link_marc_host( { host => $item->biblio } );
330         }
Comment 11 Jonathan Druart 2025-01-16 13:27:51 UTC
I will ask the question differently.

We have other remove_from_bundle calls:
circ/returns.pl:                $verify_item->remove_from_bundle;

Do we want to unlink there?
Comment 12 Lucas Gass (lukeg) 2025-02-25 14:50:02 UTC
Since the dependency is FQA I will set this one to BLOCKED for now.