Bug 35073: Default to existing value if there is one

For values that dont exist in the batch edit submission, i.e. UI says 'No change', we default to existing value if there is one.

Test plan:
Preparation - Additional fields:
1) Add a new 'additional field', visit:
/cgi-bin/koha/admin/additional-fields.pl
2) Click 'subscription' and '+ New field'. Enter a 'name' and hit 'save'.

Serials:
1) Add a new serial, visit:
/cgi-bin/koha/serials/subscription-add.pl
2) Put a biblionumber in the 'record' field, i.e. '112'. Press 'next' and click 'ok' on the alert box
3) Fill all the required fields and click 'test prediction'
4) Input something in the additional field created previously.
5) Click 'save subscription'. Notice the additional field is as expected.
6) Repeat steps 1-5 to create a second serial.

Batch edit:
1) Visit serials and hit the 'Search' button:
/cgi-bin/koha/serials/serials-home.pl
2) Click the 2 checkboxes for the 2 serials we created previously and click the new link that pops up 'edit selected serials'.
3) Click 'Save' without changing anything.
4) Go back to either of the serials, notice the value for the additional field is unchanged. Visit:
/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=1

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Pedro Amorim 2023-10-17 09:20:59 +00:00 committed by Tomas Cohen Arazi
parent 05d131febf
commit 7294908de3
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
1 changed files with 8 additions and 0 deletions

View File

@ -84,6 +84,14 @@ if ($batchedit) {
id => $field->id,
value => $value,
};
}else{
my $existing = $subscription->additional_field_values->search( { field_id => $field->id } )->last;
if($existing && $existing->value){
push @additional_field_values, {
id => $field->id,
value => $existing->value,
};
}
}
}
$subscription->set_additional_fields(\@additional_field_values);