Description
Martin Renvoize (ashimema)
2025-09-15 10:15:49 UTC
Created attachment 186436 [details] [review] Bug 40808: Add accountline_links table for polymorphic hold-fee linking This patch introduces a new polymorphic linking system to replace the growing number of nullable foreign key fields in the accountlines table. Database changes: - New accountline_links table with optimized indexes - Supports linking account lines to holds, checkouts, article requests, etc. - Uses clean link_type naming (hold, checkout, article_request) - Migrates existing issue_id and old_issue_id links during upgrade - Includes database triggers for referential integrity Benefits: - Eliminates nullable FK field bloat in accountlines - Infinitely extensible for new entity types - Enables one-to-many relationships (one fee can link to multiple entities) - Better performance with covering indexes Created attachment 186437 [details] [review] Bug 40808: Add DBIx::Class schema for accountline_links polymorphic relationships This patch adds the DBIx::Class schema definitions for the new accountline_links table and updates the existing accountlines schema. Changes: - New Koha::Schema::Result::AccountlineLink with polymorphic relationships - Updated Koha::Schema::Result::Accountline to include has_many relationship - Supports modern link types: hold, checkout, article_request - Includes validation methods for link integrity - Optimized for common query patterns with covering indexes The polymorphic design allows linking account lines to any entity type without adding nullable foreign key columns to the accountlines table. Created attachment 186438 [details] [review] Bug 40808: Add Koha::Object classes for accountline_links and update existing objects This patch implements the Koha::Object layer for the new polymorphic account line linking system. New classes: - Koha::Account::Link - Individual link object with validation - Koha::Account::Links - Collection class with filtering methods Enhanced existing classes: - Koha::Account::Line gains methods: add_link, links, holds, checkouts, article_requests - Koha::Hold gains method: account_lines Features: - Clean API using modern class names (holds, checkouts vs reserves, issues) - Built-in validation for link integrity - Optimized queries with proper joins and prefetch - Seamless integration with existing Koha::Object patterns Usage examples: my $fees = $hold->debits; my $holds = $account_line->holds; $account_line->add_link('hold', $hold_id); Created attachment 186439 [details] [review] Bug 40808: Add schema relationships for polymorphic account line linking Adds the necessary DBIx::Class relationships to support polymorphic linking between account lines and various entities: 1. Koha::Schema::Result::Reserve - Adds accountline_links relationship to enable holds to find their linked account lines 2. Koha::Schema::Result::AccountlineLink - Enhanced polymorphic methods for accessing linked objects and validation These relationships enable proper traversal from holds to account lines and support the polymorphic linking system. Created attachment 186440 [details] [review] Bug 40808: Add comprehensive test coverage for account line linking Adds comprehensive test coverage for the polymorphic account line linking system with proper transaction isolation: 1. t/db_dependent/Koha/Account/Link.t - Tests individual Link objects - Object creation and validation - Link integrity validation - Exception handling for invalid link types and targets - Integration with account lines and holds - Unique constraint enforcement 2. t/db_dependent/Koha/Account/Links.t - Tests Links collection - Collection filtering by link_type and linked_id - Polymorphic access to linked objects (holds, checkouts) - Proper transaction isolation between subtests 3. Updates to t/db_dependent/Koha/Account/Line.t - New subtest for Account::Line linking methods - Tests add_link(), links(), holds(), checkouts() methods - Proper integration testing with transaction isolation All tests pass with comprehensive coverage of the linking functionality. Created attachment 186441 [details] [review] Bug 40808: Add REST API embedding support for hold account_lines Adds support for embedding account lines in holds via the REST API: 1. api/v1/swagger/definitions/hold.yaml - Adds account_lines property to hold definition for API output when embedded 2. api/v1/swagger/paths/holds.yaml - Adds account_lines to the x-koha-embed enum for the GET /holds endpoint 3. api/v1/swagger/paths/patrons_holds.yaml - Adds account_lines to the x-koha-embed enum for GET /patrons/{patron_id}/holds endpoint Usage: GET /api/v1/holds?x-koha-embed=account_lines GET /api/v1/patrons/123/holds?x-koha-embed=account_lines This allows API consumers to retrieve holds with their associated charges/fees in a single request, enabling efficient access to hold-related financial information. Created attachment 186442 [details] [review] Bug 40808: Add account_lines embedding support to POST /holds endpoint Adds x-koha-embed parameter to the POST /holds endpoint to allow embedding account_lines in the response when creating a hold. This enables API consumers to immediately see any charges/fees that are created as part of the hold placement process in a single API call. Usage: POST /api/v1/holds x-koha-embed: account_lines The response will include any account lines (fees) automatically created during hold placement, such as hold placement fees. Created attachment 186443 [details] [review] Bug 40808: Add REST API unit tests for holds debits embedding Adds comprehensive API unit tests for the debits embedding functionality in the holds REST API endpoints. The tests verify: 1. GET /holds without embedding - should not include debits field 2. GET /holds with debits embedding - should include linked charges 3. GET /holds with empty debits - should return empty array when no fees linked Note: Currently the API embedding tests fail with 500 errors due to issues in the REST API framework's automatic embedding mechanism, though the underlying Hold.debits() method and to_api() functionality works correctly when tested directly. Also improves the Hold.debits() method to properly filter for debit-only account lines (excluding credits). Created attachment 186458 [details] [review] Bug 40808: Add accountline_links table for polymorphic hold-fee linking This patch introduces a new polymorphic linking system to replace the growing number of nullable foreign key fields in the accountlines table. Database changes: - New accountline_links table with optimized indexes - Supports linking account lines to holds, checkouts, article requests, etc. - Uses clean link_type naming (hold, checkout, article_request) - Migrates existing issue_id and old_issue_id links during upgrade - Includes database triggers for referential integrity Benefits: - Eliminates nullable FK field bloat in accountlines - Infinitely extensible for new entity types - Enables one-to-many relationships (one fee can link to multiple entities) - Better performance with covering indexes Created attachment 186459 [details] [review] Bug 40808: Add DBIx::Class schema for accountline_links polymorphic relationships This patch adds the DBIx::Class schema definitions for the new accountline_links table and updates the existing accountlines schema. Changes: - New Koha::Schema::Result::AccountlineLink with polymorphic relationships - Updated Koha::Schema::Result::Accountline to include has_many relationship - Supports modern link types: hold, checkout, article_request - Includes validation methods for link integrity - Optimized for common query patterns with covering indexes The polymorphic design allows linking account lines to any entity type without adding nullable foreign key columns to the accountlines table. Created attachment 186460 [details] [review] Bug 40808: Add Koha::Object classes for accountline_links and update existing objects This patch implements the Koha::Object layer for the new polymorphic account line linking system. New classes: - Koha::Account::Link - Individual link object with validation - Koha::Account::Links - Collection class with filtering methods Enhanced existing classes: - Koha::Account::Line gains methods: add_link, links, holds - Koha::Hold gains method: account_lines Features: - Clean API using modern class names (holds) - Built-in validation for link integrity - Optimized queries with proper joins and prefetch - Seamless integration with existing Koha::Object patterns Usage examples: my $fees = $hold->debits; my $holds = $account_line->holds; $account_line->add_link('hold', $hold_id); Created attachment 186461 [details] [review] Bug 40808: Add schema relationships for polymorphic account line linking Adds the necessary DBIx::Class relationships to support polymorphic linking between account lines and various entities: 1. Koha::Schema::Result::Reserve - Adds accountline_links relationship to enable holds to find their linked account lines 2. Koha::Schema::Result::AccountlineLink - Enhanced polymorphic methods for accessing linked objects and validation These relationships enable proper traversal from holds to account lines and support the polymorphic linking system. Created attachment 186462 [details] [review] Bug 40808: Add comprehensive test coverage for account line linking Adds comprehensive test coverage for the polymorphic account line linking system with proper transaction isolation: 1. t/db_dependent/Koha/Account/Link.t - Tests individual Link objects - Object creation and validation - Link integrity validation - Exception handling for invalid link types and targets - Integration with account lines and holds - Unique constraint enforcement 2. t/db_dependent/Koha/Account/Links.t - Tests Links collection - Collection filtering by link_type and linked_id - Polymorphic access to linked objects (holds, checkouts) - Proper transaction isolation between subtests 3. Updates to t/db_dependent/Koha/Account/Line.t - New subtest for Account::Line linking methods - Tests add_link(), links(), holds(), checkouts() methods - Proper integration testing with transaction isolation All tests pass with comprehensive coverage of the linking functionality. Created attachment 186463 [details] [review] Bug 40808: Add REST API embedding support for hold account_lines Adds support for embedding account lines in holds via the REST API: 1. api/v1/swagger/definitions/hold.yaml - Adds account_lines property to hold definition for API output when embedded 2. api/v1/swagger/paths/holds.yaml - Adds account_lines to the x-koha-embed enum for the GET /holds endpoint 3. api/v1/swagger/paths/patrons_holds.yaml - Adds account_lines to the x-koha-embed enum for GET /patrons/{patron_id}/holds endpoint Usage: GET /api/v1/holds?x-koha-embed=account_lines GET /api/v1/patrons/123/holds?x-koha-embed=account_lines This allows API consumers to retrieve holds with their associated charges/fees in a single request, enabling efficient access to hold-related financial information. Created attachment 186464 [details] [review] Bug 40808: Add account_lines embedding support to POST /holds endpoint Adds x-koha-embed parameter to the POST /holds endpoint to allow embedding account_lines in the response when creating a hold. This enables API consumers to immediately see any charges/fees that are created as part of the hold placement process in a single API call. Usage: POST /api/v1/holds x-koha-embed: account_lines The response will include any account lines (fees) automatically created during hold placement, such as hold placement fees. Created attachment 186465 [details] [review] Bug 40808: Add REST API unit tests for holds debits embedding Adds comprehensive API unit tests for the debits embedding functionality in the holds REST API endpoints. The tests verify: 1. GET /holds without embedding - should not include debits field 2. GET /holds with debits embedding - should include linked charges 3. GET /holds with empty debits - should return empty array when no fees linked Note: Currently the API embedding tests fail with 500 errors due to issues in the REST API framework's automatic embedding mechanism, though the underlying Hold.debits() method and to_api() functionality works correctly when tested directly. Also improves the Hold.debits() method to properly filter for debit-only account lines (excluding credits). |