Bug 23463: Use new method Koha::Object->set_or_blank
This patch fixes an issue when editing items.
* The issue
Cannot blank a subfield when editing an item.
If you have an item with itemcallnumber=42, then edit it, blank it and
save. The itemcallnumber is still 42
* Why? (line numbers from https://gitlab.com/joubu/Koha/-/tree/bug_23463)
additem (and other item's edition forms) receives a list of tags,
subfields and values, generates a MARC::Record::XML then calls
ModItemFromMarc:
717 my $itemtosave=MARC::Record::new_from_xml($xml, 'UTF-8');
727 my $newitem = ModItemFromMarc($itemtosave, $biblionumber,
$itemnumber);
And ModItemFromMarc:
282 my $item = TransformMarcToKoha( $localitemmarc,
$frameworkcode, 'items' );
283 $item->{cn_source} = delete $item->{'items.cn_source'}; #
Because of C4::Biblio::_disambiguate
284 $item_object->set($item);
ModItemFromMarc never knows that the field has been blank.
Prior to bug 23463 we had a map of default values, and ModItemFromMarc
was doing:
426 my $item = TransformMarcToKoha( $localitemmarc,
$frameworkcode, 'items' );
427 my $default_values = _build_default_values_for_mod_marc();
428 foreach my $item_field ( keys %$default_values ) {
429 $item->{$item_field} = $default_values->{$item_field}
430 unless exists $item->{$item_field};
431 }
I do not want to reinsert that list of default values.
Here I wrote a generic method in Koha::Object to set the value passed in parameter,
or "blank" if not passed.
It's nulled if can be set to null in DB, or the default value is retrieved from
the schema info.
Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>