Bug 27509: Prevent cn_sort value to be lost when editing items
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 21 Jan 2021 16:21:15 +0000 (17:21 +0100)
committerFridolin Somers <fridolin.somers@biblibre.com>
Fri, 22 Jan 2021 14:18:42 +0000 (15:18 +0100)
commit080a6f6aea0418fe234b73eedbffa0a6c8e71600
tree962d10a7b4b1c2dc2b4161e32f2673e1b04fb65c
parentf393408a05233723e8aaaa6207de74a83c4190dd
Bug 27509: Prevent cn_sort value to be lost when editing items

This is a bit dirty, cn_sort is not passed from the UI but built in
Koha::Item->store depending on the values of itemcallnumber and
cn_source.
It must be updated only if one of those 2 attributes are modified.
The problem is that, as it's not passed, $item->{cn_sort} does not exist,
and set_or_blank will set it to undef.
The trick here is to backup the value before set_or_blank and set it
back to the item object.
Another solution would be to force the processing of cn_sort each time
we call Koha::Item->store. I don't think that's a good idea.

Test plan:
- Create a new item with a cn_source value and an itemcallnumber value
- write a quick report to see the cn_sort value: SELECT cn_sort FROM items WHERE itemnumber=your itemnumber, see your item has a cn_sort value
- edit your item and save it without changing either the cn_source of the itemcallnumber
- run your report again, cn_sort is not modified
- edit your item, changing either the cn_source or itemcallnumber
- run report again, cn_sort is modified as expected

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit dcd4ab94cd0a7b0a599cdc507810f9a8eb819202)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
C4/Items.pm
t/db_dependent/Items.t