Commit Graph

62478 Commits

Author SHA1 Message Date
Martin Renvoize 9371504d98
Bug 30144: (QA follow-up) Only show servicing instructions when EDIFACT is available
The new servicing instructions UI on the "add order" form was showing
unconditionally, even when the EDIFACT system preference is disabled
or the vendor has no EDI account configured. Elsewhere in acquisitions
(e.g. acqui/basket.tt) EDI-only UI is gated on
Koha.Preference('EDIFACT') && ediaccount, so apply the same check here.

Test plan:
1. With EDIFACT disabled, or EDIFACT enabled but the vendor has no
   entry in vendor_edi_accounts, open Acquisitions > a basket > Add
   order (neworderempty.pl)
   => No "Servicing instructions" field is shown
2. Enable EDIFACT and add a vendor_edi_accounts row for the vendor
   => The "Servicing instructions" field appears and behaves as before

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-09 12:07:23 +00:00
Martin Renvoize b210605ef7
Bug 30144: (QA follow-up) Fix t/Ediorder.t for JSON servicing_instruction format
Bug 30144 changed Koha::Edifact::Order::gir_segments() to expect
servicing_instruction as a JSON-encoded array of instruction groups
(added by Bug 41709 while working with the older plain-string format
that predated Bug 30144's change was never adapted to match).

As a plain string no longer decodes as JSON, gir_segments() silently
skipped the servicing instruction elements, leaving the GIR split and
special-character tests comparing against undef.

Test plan:
1. prove t/Ediorder.t
   => 4 tests failed before this patch, all pass after
2. prove t/db_dependent/Koha/Edifact/Order.t
   => still passes

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-09 12:07:21 +00:00
Jonathan Druart 58cda28f6a
Bug 41996: Fix kohastructure.sql
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-07 10:46:28 +00:00
Jonathan Druart 3594c6f60c
Bug 16631: Fix kohastructure.sql
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-07 10:46:27 +00:00
Jonathan Druart f612fda1e9
Bug 41995: Add nonce
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:24:14 +00:00
Jonathan Druart 76504e598a
Bug 41995: Remove extra JS code
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:24:12 +00:00
Jonathan Druart dd536cae2e
Bug 41995: Fix conflict with bug 37762
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:24:11 +00:00
Jonathan Druart 061cc915ad
Bug 41995: Add autocomplete on the admin home page
Signed-off-by: Anneli Österman <anneli.osterman@koha-suomi.fi>
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:24:10 +00:00
Jonathan Druart c9cfa985b6
Bug 41995: Autocomplete for syspref search
This patch adds autocompletion to the syspref search in the header.

Test plan:
1. Go to the admin home page - /cgi-bin/koha/admin/admin-home.pl
2. In the header start typing the name of a syspref and notice that
   there is now autocompletion (you need at least 3 chars)
3. Select an entry and confirm that you are correctly redirected to the
   correct search result

Signed-off-by: Anneli Österman <anneli.osterman@koha-suomi.fi>
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:24:09 +00:00
Pedro Amorim 52e6e3ad53
Bug 41728: (RM follow-up): Add AddReturn marks ISO18626 request as LoanCompleted
Regression test from the RM's QA review (attachment 204865, comment
104/105 on the bug): drives a real ISO18626 request through AddReturn
and confirms it gets marked LoanCompleted and receives a
supplyingAgencyMessage, rather than only checking that the $messages
hashref no longer contains a stray NotIssued key. This closes the gap
the "Remove leftover duplicate data-consistency block" follow-up left
- that fix restored the $iso18626_request assignment, but nothing
previously exercised the ISO18626 progress-reporting path end to end.

Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>

Test plan:
1. prove t/db_dependent/Circulation.t
=> SUCCESS: 91 tests pass.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:24:07 +00:00
Martin Renvoize e0d32e073a
Bug 41728: (QA follow-up) Add coverage for the Wrongbranch blocker
No test in the suite asserted on $messages->{Wrongbranch} content
despite this being one of the blockers AddReturn's rewired
availability check produces (AllowReturnToBranch enforcement, moved
into Koha::Item->can_be_returned_at / Koha::Item::Availability::Checkin
by this bug). Add coverage for it.

Test plan:
1. prove t/db_dependent/Circulation.t
=> SUCCESS: 88 tests pass.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:24:06 +00:00
Martin Renvoize 8bcd634fb9
Bug 41728: (QA follow-up) Remove leftover duplicate data-consistency block
d43945e7279 moved the issued/patron data-consistency check earlier in
AddReturn (before blocker handling), as its commit message describes,
but only copied the block instead of deleting the original. The
leftover block ran unconditionally afterwards: since $patron is
already guaranteed set whenever $issue is true by that point, its
"else" branch fired on every normal checkin of an already-issued item,
incorrectly setting $messages->{NotIssued} and clearing item.onloan.
This corrupted the not_issued message surfaced to circ/returns.pl, SIP,
and the checkin audit record on every ordinary return.

The same leftover block also buried $iso18626_request's assignment
after a die (making it dead code), so ISO18626 progress-reporting on
checkin was never triggered. Restore the assignment at the point
$issue/$patron are extracted from the availability context, where it
belongs.

Test plan:
1. Return an item that is currently checked out.
2. Confirm the returned $messages hashref no longer contains a
   NotIssued key, and that item.onloan is only cleared for items that
   were genuinely not checked out.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:24:05 +00:00
Tomás Cohen Arazi ce9ffcca52
Bug 41728: (follow-up) Replace require with use for Availability::Checkin
There is no circular dependency, so the runtime require can be
replaced with a compile-time use statement.

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:24:03 +00:00
Martin Renvoize fbe7c7a60f
Bug 41728: (QA follow-up) Move Item::Checkin::Availability to Item::Availability::Checkin
Introduce a dedicated Koha::Item::Availability::* namespace for checkers
that return a Koha::Result::Availability. Keeping these under the Item
subject prefix keeps them co-located with the Item they describe, while
the Availability sub-namespace gives future parallel checkers
(Checkout, Hold, Book, ...) an obvious home rather than scattering them
as single-file directories alongside Koha/Item/Transfer/ etc.

The $item->checkin_availability convenience method on Koha::Item is
preserved; only its internal delegation target changes.

Renames:
  Koha::Item::Checkin::Availability -> Koha::Item::Availability::Checkin
  Koha/Item/Checkin/Availability.pm -> Koha/Item/Availability/Checkin.pm
  t/db_dependent/Koha/Item/Checkin/Availability.t
    -> t/db_dependent/Koha/Item/Availability/Checkin.t

Test plan:
  prove t/db_dependent/Koha/Item/Availability/Checkin.t
  prove t/db_dependent/Circulation/Returns.t

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:24:02 +00:00
Martin Renvoize be74523028
Bug 41728: (QA follow-up) Move Availability::Result to Result::Availability
Consolidate result base classes under the Koha::Result::* namespace
alongside the existing Koha::Result::Boolean. This keeps return-value
wrappers discoverable in one place and avoids a lone Koha::Availability::
namespace that would otherwise host a single base class.

Renames:
  Koha::Availability::Result -> Koha::Result::Availability
  Koha/Availability/Result.pm -> Koha/Result/Availability.pm
  t/Koha/Availability/Result.t -> t/Koha/Result/Availability.t

Call sites in Koha::Item, Koha::Item::Checkin::Availability, and the
test files are updated accordingly.

Test plan:
  prove t/Koha/Result/Availability.t
  prove t/db_dependent/Koha/Item/Checkin/Availability.t

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:24:01 +00:00
Tomás Cohen Arazi dece71cb3e
Bug 41728: (follow-up) Add no_short_circuit option to checkin availability
This follow-up replaces the unconditional removal of short-circuit logic
with a caller-controlled no_short_circuit parameter, following the same
pattern established by Koha::Patron->can_place_holds.

By default, check() short-circuits on the first blocker. This is the
correct behavior for AddReturn, which processes blockers sequentially
and only acts on the first one it finds (BlockedWithdrawn => early return,
Wrongbranch => early return, BlockedLost => sets doreturn=0). Running all
policy checks only to discard the results is wasteful, specially when
some of them (e.g. can_be_returned_at) hit the database.

When no_short_circuit => 1 is passed, all checks run and all blockers
are collected. This is the behavior API consumers will need: present the
full set of issues in a single response instead of requiring
fix-one-recheck cycles.

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. Sign off :-D

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:59 +00:00
Martin Renvoize 84bcca727a
Bug 41728: (QA follow-up) Collect all blockers instead of short-circuiting
Remove early returns from Koha::Item::Checkin::Availability::check() so
that all blockers, confirmations, and warnings are collected in a single
pass. Previously, the first blocker triggered an early return, meaning
callers could only discover one problem at a time.

This is particularly useful for API consumers who want to present the
full set of issues to the user in a single response rather than
requiring fix-one-recheck cycles.

The change is safe for AddReturn because it already handles blocker
priority through its sequential if/return structure:
  1. BlockedWithdrawn → early return before status updates
  2. Wrongbranch → early return after status updates
  3. BlockedLost → sets doreturn=0

Even when multiple blockers are present, AddReturn processes them in
the correct priority order.

Also makes existing tests deterministic by explicitly setting withdrawn
and itemlost values on test items, preventing random TestBuilder values
from triggering unrelated blockers now that all checks always run.

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:58 +00:00
Martin Renvoize 8391917bab
Bug 41728: (QA follow-up) Restore withdrawn warning and use from availability
Restore the withdrawn warning in Koha::Item::Checkin::Availability that
was incorrectly removed. This warning is set when an item is withdrawn
but BlockReturnOfWithdrawnItems is off, making it useful for API
consumers in subsequent work.

Update AddReturn to read the withdrawn state from the availability
result's warnings rather than re-checking $item->withdrawn directly,
avoiding duplication of logic.

Add test for the withdrawn warning (non-blocked) path.

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:57 +00:00
Martin Renvoize 24854abf30
Bug 41728: (QA follow-up) Move return policy logic to Koha::Item
Move the AllowReturnToBranch and branch transfer limit checks from both
C4::Circulation::CanBookBeReturned and
Koha::Item::Checkin::Availability::_check_return_policy into a single
authoritative method on Koha::Item: can_be_returned_at().

This eliminates the duplicate implementations and follows the Koha
convention of placing item-related logic on the Koha::Item object.

Changes:
- Add Koha::Item->can_be_returned_at() with AllowReturnToBranch policy
  and transfer limit checks
- Make CanBookBeReturned a thin wrapper delegating to the new method
- Update Checkin::Availability to call $item->can_be_returned_at()
- Remove _check_return_policy and unused withdrawn warning from
  the Availability class

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:56 +00:00
Martin Renvoize b689dd07cc
Bug 41728: (QA follow-up) Restore original execution order for Wrongbranch
The refactoring changed the relative order of the Wrongbranch early
return and several status-update operations. In the original AddReturn,
the execution order was:

  1. checkout/patron lookup
  2. not-issued handling + RecordLocalUseOnReturn
  3. withdrawn check (early return)
  4. location_update_trigger
  5. UpdateNotForLoanStatusOnCheckin
  6. CanBookBeReturned / Wrongbranch check (early return)
  7. BlockReturnOfLostItems

After the refactoring, the Wrongbranch blocker returned early before
steps 2, 4 and 5, causing three regressions:

  - RecordLocalUseOnReturn was not recorded for non-issued items
    scanned at the wrong branch
  - location_update_trigger was skipped for Wrongbranch returns
  - UpdateNotForLoanStatusOnCheckin was skipped for Wrongbranch returns

Fix by splitting blocker handling into two phases:

  1. BlockedWithdrawn: earliest early return, before status updates
     (matches original withdrawn check position)
  2. Wrongbranch and BlockedLost: after RecordLocalUseOnReturn,
     location_update_trigger, and UpdateNotForLoanStatusOnCheckin
     (matches original CanBookBeReturned position)

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:54 +00:00
Martin Renvoize d46b0c1106
Bug 41728: (QA follow-up) Move data consistency check before blocker handling
The data inconsistency die (checkout exists but patron does not) was
placed after the blocker handling block. This meant that if an item had
corrupt data AND triggered a blocker (e.g. withdrawn+blocked), the
blocker handler would return early with patron as undef instead of dying
on the inconsistency, silently masking database corruption.

Move the check to immediately after extracting context from the
availability result, before any blocker handling, matching the original
AddReturn behavior where the die fired during checkout lookup.

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:53 +00:00
Kyle M Hall 2e4459ea69
Bug 41728: (QA follow-up) Declare issue and patron variables together
There seems to be no reason to declare $patron near the start of the sub
while $issue is declared where they are both populated.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:52 +00:00
Kyle M Hall dad9fd4a30
Bug 41728: (QA follow-up) Fix test accessing wrong key for checkout
The test was checking $result->{issue} which doesn't exist on the
Result object. The correct accessor is $result->context->{checkout},
so the assertion was always trivially true.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:51 +00:00
Kyle M Hall 402b6559f8
Bug 41728: (QA follow-up) Match original blocker priority order
Reorder blocker checks to match the original AddReturn priority:
Withdrawn > Wrongbranch > Lost. Previously Lost was checked before
Wrongbranch, which changed behavior for items that were both lost
and at the wrong branch.

QA note: There are other checks in-between these, but I don't think
their order betwixt these blockers matters for retaining existing
behavior.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:49 +00:00
Kyle M Hall e822660311
Bug 41728: (QA follow-up) Populate checkout context before blocker checks
The availability check is returning early on blockers (BlockedWithdrawn,
BlockedLost, Wrongbranch) before checking if the item had an active
checkout. This causes AddReturn to lose checkout/patron context for
checked-out items that hit a blocker, resulting in incorrect NotIssued
messages, unintended onloan clearing, and incorrect local use recording.

Move the checkout check to run first so context is always populated
regardless of blockers.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:48 +00:00
Tomás Cohen Arazi cb3deeadcc
Bug 41728: (follow-up) Add transfer limit check and clean param names
- Rename params: branch => library, add to_library for destination
- Move $returnbranch computation before the availability check in
  AddReturn so it can be passed as to_library
- Add transfer limit check (bug 7376) to the Availability class
- Rename internal _can_book_be_returned to _check_return_policy
- Remove duplicate $returnbranch block and standalone transfer
  limit check from AddReturn
- Update tests for new param names

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:47 +00:00
Tomás Cohen Arazi 4b277a6e4a
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

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:45 +00:00
Tomás Cohen Arazi 9b8328c3f5
Bug 41728: Add Koha::Item::Checkin::Availability class
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:44 +00:00
Tomás Cohen Arazi b5041ae361
Bug 41728: Add Koha::Availability::Result base class
This patch introduces a standardized result class for availability checks,
providing a clean API with proper methods instead of raw hashrefs.

The Koha::Availability::Result class provides:
- add_blocker() - Add conditions that prevent the action
- add_confirmation() - Add conditions requiring user confirmation
- add_warning() - Add informational messages
- set_context() - Store related objects (item, checkout, patron, etc.)
- available() - Check if action can proceed (no blockers)
- needs_confirmation() - Check if confirmations are required
- Accessor methods for all categories
- to_hashref() for backward compatibility

This design:
- Provides a consistent interface across all availability checks
- Makes the API more discoverable and self-documenting
- Enables future enhancements without breaking changes
- Follows OO principles with proper encapsulation
- Can be used as base for checkout, hold, renewal availability

Test plan:
1. Apply patch
2. Run:
   $ ktd --shell
  k$ prove t/Koha/Availability/Result.t
=> SUCCESS: Tests pass!
3. Verify all methods work correctly
4. Sign off :-D

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:43 +00:00
Tomás Cohen Arazi 78906e00da
Bug 42443: (QA follow-up) Use POST /transfers/{transfer_id}/cancellation
Cancelling a transfer is a state change on the resource, not a deletion of
it, so it should be modelled as an action sub-resource rather than a DELETE
on the transfer itself. This aligns the endpoint with the API coding
guidelines (REST2: non-CRUD actions use action sub-resources; REST3.2:
conflicts return 409) and with the design used in bug 43454.

Changes:
- Replace DELETE /transfers/{transfer_id} with
  POST /transfers/{transfer_id}/cancellation
- Rename the controller method delete() to cancel(), look the transfer up
  with objects->find_rs, and return 200 with the updated resource
  representation instead of 204 with an empty body
- Make cancellation_reason optional, defaulting to 'Manual', matching the
  legacy returns.pl behaviour
- Return 409 with a structured error_code ('already_arrived',
  'already_cancelled') when the transfer cannot be cancelled, instead of a
  bare 400
- Update the transfers to receive page to POST to the new endpoint and to
  treat 404/409 as "already gone, refresh the table"
- Adapt the tests accordingly, including coverage for the default reason
- The *_date API attribute names introduced by this bug are kept, as they
  are the guideline-compliant form (REST1.3.4.1: *_date, not date_*)

Test plan:
1. Apply patch
2. Run the tests:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/transfers.t
=> SUCCESS: Tests pass!
3. Rebuild and validate the API spec:
  k$ yarn api:bundle
  k$ prove xt/api.t
=> SUCCESS: Tests pass!
4. In the staff interface, go to Circulation -> Transfers to receive,
   click "Cancel transfer" on a row
=> SUCCESS: The transfer is cancelled and the row drops off the table
5. Cancel the same transfer again from a second tab
=> SUCCESS: The API returns 409 (already_cancelled) and the row is
   treated as already gone
6. Sign off :-D

Assisted-by: Sonnet 4.6 (Anthropic)
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:41 +00:00
Martin Renvoize d7a87e2cbd
Bug 42443: (QA follow-up) Use library selects for Sent from and Home library filters
Replace the free-text filter inputs for the "Sent from" and "Home library"
columns with select dropdowns populated from the full library list, consistent
with other DataTables pages such as the pending bookings page.

The "Sent from" column is made visible again (it was previously hidden since
rowGroup provides the visual grouping); showing it also allows its filter cell
to render.

The "On hold for" column intentionally has no filter: it is computed from two
different embedded sub-objects (item.first_hold.patron or item.recall.patron)
and has no single API field to filter against server-side.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:40 +00:00
Martin Renvoize dcb423b766
Bug 42443: (QA follow-up) Add DBIC relationship aliases on Branchtransfer
The REST framework resolves _order_by parameters and embed prefetches by
walking prefetch_whitelist, which is built from DBIC relationship names.
The auto-generated relationships use the FK column names (itemnumber,
frombranch, tobranch), but the API exposes them as item, from_library,
and to_library. Sorting by item.biblio.title etc. threw a 500 because
those names were not in the whitelist.

Adding belongs_to aliases below the DO NOT MODIFY line bridges the API
names to the DBIC names, matching the convention used by other Koha
schema result classes (e.g. Koha::Schema::Result::Item).

Also updates the relation methods in Koha::Item::Transfer to use the new
aliases consistently, so the accessor names line up across both layers.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:39 +00:00
Martin Renvoize ebb77c8fa9
Bug 42443: (QA follow-up) Group transfers by sending library using rowGroup
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:38 +00:00
Martin Renvoize e5a07ccd25
Bug 42443: (QA follow-up) Test from_library_id query filter
The OpenAPI spec documents from_library_id as a supported filter
parameter but the test suite only exercised to_library_id. Add a test
to verify filtering by source library returns the correct transfer.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:36 +00:00
Martin Renvoize 02a02c7209
Bug 42443: (QA follow-up) Test UseRecalls integration in transfer cancel
The delete() controller reverts any in-transit recall tied to the item
when UseRecalls is enabled. Add a subtest to verify the recall status
is set back to 'requested' after the transfer is cancelled.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:35 +00:00
Martin Renvoize 19d1db91d2
Bug 42443: (QA follow-up) Fix escaping of branchcode in JS context
Using | html to embed a TT value inside a JS string literal is
incorrect: it produces HTML entities rather than JS-safe characters.
Store the branchcode in a data attribute (where | html is correct)
and read it from there in JavaScript.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:34 +00:00
Martin Renvoize 16b2ac663e
Bug 42443: (QA follow-up) Guard nullable embed access in JS renderers
from_library and home_library can be null if a transfer references an
orphaned branch row. Accessing .name on null throws a TypeError and
crashes the DataTable renderer; guard both accesses.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:33 +00:00
Martin Renvoize f80b599332
Bug 42443: (QA follow-up) Add to_library to embed enum
Koha::Item::Transfer exposes a to_library() method and the definition
already listed to_library as a valid property, but the x-koha-embed
enum was missing the entry. Add it so consumers can embed it.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:31 +00:00
Martin Renvoize f8d59a7b50
Bug 42443: (QA follow-up) Prevent cancelling completed transfers
The delete endpoint was passing force => 1 to cancel() with no state
guards, allowing already-received and already-cancelled transfers to
be re-cancelled, corrupting datearrived/datecancelled audit fields.

Add explicit 400 responses for both cases and tests to cover them.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:30 +00:00
Kyle M Hall c813fb2574
Bug 42443: Add ability to cancel a transfer via the REST API
This patch adds a DELETE /transfers/{transfer_id} route that cancels the
given transfer by id and reverts an in transit recall for the item the same
way as returns.pl does. The cancellation reason is passed in the request body
so this api endpoint could be used in other places we can cancel transfers.

Signed-off-by: Alex Carver [Acerock7] <alex@rcls.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:29 +00:00
Kyle M Hall 560d7b7ff7
Bug 42443: Convert transfers to receive page to ajax datatable
Updates circ/transferstoreceive.pl to use the new REST API with
an ajax DataTable to display transfer to receive.

Test Plan:
1) Apply this patch
2) Restart all the things!
3) Set an item in transit to your logged in library ( check it in at another
   branch so it is sent home, or place a hold to trigger a transfer )
4) Place a hold on a second transferred item, and a recall on a third
5) Browse to /cgi-bin/koha/circ/transferstoreceive.pl
6) Note the "On hold for" column shows the hold patron, the recall patron or
   "None"
7) Set TransfersMaxDaysWarning low and note the "days late" badge appears
8) Click "Cancel transfer" and note the transfer is cancelled
9) A library with no incoming transfers will get "No transfers to receive"

Signed-off-by: Alex Carver [Acerock7] <alex@rcls.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:28 +00:00
Kyle M Hall 4fc5617615
Bug 42443: Add unit tests
Signed-off-by: Alex Carver [Acerock7] <alex@rcls.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:26 +00:00
Kyle M Hall 9dac6290d7
Bug 42443: Add REST API for item transfers
Signed-off-by: Alex Carver [Acerock7] <alex@rcls.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:25 +00:00
Lisette Scheer 2aa2cc0e7f
Bug 42330: (QA follow-up) Fix file permissions on new test and tidy
This patch
- Fixes the file permissions on the new test
- Removes a variable declaration from the new test that's unused
- Removes a new line from the end of staff-global.scss

Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:24 +00:00
Jonathan Druart 6cb0f5161c
Bug 42330: Auto-tidy
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:23 +00:00
Jonathan Druart fc32990f49
Bug 42330: Add new template tools/restore-records.tt
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:21 +00:00
Jonathan Druart 210aa964f0
Bug 42330: Add an xt test to prevent new occurrences of <main> in staff templates
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:20 +00:00
Owen Leonard 248c0fe224
Bug 42330: (follow-up) Some corrections to sidebars
- The structure of the search facets, advanced MARC editor, and
  HTML customiztions sidebars need to be corrected in order for
  the collapse button to work correctly.
- The "toggle_sidebar" click handler should be inside a
  "$(document).ready()" in order to work correctly on pages where the JS
  is in the header.

Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:19 +00:00
Jonathan Druart ad694a3411
Bug 42330: Tidy
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:17 +00:00
Jonathan Druart b02ca1270d
Bug 42330: Use main-container from all our templates
This goal here is to uniformize the structure of our templates.
Using main-container.inc will also introduce the sidebar collapse (from
bug 42322) where it was missing

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-09-04 11:23:13 +00:00