https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=41728

--- Comment #3 from Tomás Cohen Arazi (tcohen) <[email protected]> ---
Created attachment 192132
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=192132&action=edit
Bug 41728: Make AddReturn use Koha::Item::Checkin::Availability

This patch refactors AddReturn to use the new Koha::Item::Checkin::Availability
class for validation logic, eliminating code duplication and centralizing
check-in validation.

Changes:
- Add use statement for Koha::Item::Checkin::Availability
- Look up item first, return BadBarcode if not found
- Call $item->checkin_availability() for validation
- Use Result object methods (available(), blockers, context)
- Replace inline withdrawn/lost/branch validation with blocker handling
- Remove duplicate CanBookBeReturned() call (now in Availability class)
- Preserve all existing behavior and error messages
- Maintain backward compatibility

The refactoring extracts ~40 lines of validation logic while maintaining
identical functionality. All validation results are obtained from a single
availability check that returns a Result object.

Note: The withdrawn message is set in two places depending on context:
- When BlockReturnOfWithdrawnItems is ON: set in blocker handler before early
return
- When BlockReturnOfWithdrawnItems is OFF: set by existing check later in the
flow
This preserves the original behavior where withdrawn items always get the
message, but are only blocked when the syspref is enabled.

Test plan:
1. Apply patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/Koha/Item/Checkin/Availability.t
=> SUCCESS: Tests pass!
  k$ prove t/db_dependent/Circul*
=> SUCCESS: Tests pass!
3. Verify check-in operations work correctly:
   - Items not found return BadBarcode
   - Withdrawn items blocked when syspref enabled
   - Lost items blocked when syspref enabled
   - Wrong branch returns blocked per AllowReturnToBranch
   - Not issued items handled correctly
   - Normal check-ins complete successfully
4. Sign off :-D

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list
[email protected]
https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to