Bug 38195 - EDI/Edifact classes should use Koha::Objects instead of plain DBIC
Summary: EDI/Edifact classes should use Koha::Objects instead of plain DBIC
Status: ASSIGNED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Martin Renvoize (ashimema)
QA Contact: Testopia
URL:
Keywords:
Depends on: 38489 40587
Blocks:
  Show dependency treegraph
 
Reported: 2024-10-17 14:01 UTC by Tomás Cohen Arazi (tcohen)
Modified: 2025-10-01 11:39 UTC (History)
1 user (show)

See Also:
GIT URL:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 38195: Add Koha::EDI::Account and Koha::EDI::Accounts object classes (6.17 KB, patch)
2025-10-01 10:31 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38195: Convert admin/edi_accounts.pl to use Koha::EDI::Account(s) (6.27 KB, patch)
2025-10-01 10:31 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38195: Modernise Koha::Edifact::Transport to use Koha::Objects (3.06 KB, patch)
2025-10-01 10:31 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38195: Convert Koha::EDI to use Koha object classes (7.67 KB, patch)
2025-10-01 10:31 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38195: Add Koha::EDI::Account and Koha::EDI::Accounts object classes (6.17 KB, patch)
2025-10-01 11:39 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38195: Convert admin/edi_accounts.pl to use Koha::EDI::Account(s) (6.27 KB, patch)
2025-10-01 11:39 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38195: Modernise Koha::Edifact::Transport to use Koha::Objects (3.06 KB, patch)
2025-10-01 11:39 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38195: Convert Koha::EDI to use Koha object classes (7.68 KB, patch)
2025-10-01 11:39 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi (tcohen) 2024-10-17 14:01:59 UTC

    
Comment 1 Martin Renvoize (ashimema) 2025-10-01 10:31:07 UTC
Created attachment 187161 [details] [review]
Bug 38195: Add Koha::EDI::Account and Koha::EDI::Accounts object classes

This patch introduces Koha::Object-based classes for managing vendor
EDI accounts, replacing direct DBIx::Class result access with proper
Koha object wrappers.

New classes:
- Koha::EDI::Account: Object class representing a single EDI account
- Koha::EDI::Accounts: Objects class for collections of EDI accounts

The Koha::EDI::Account class provides accessor methods for all related
objects following modern Koha naming conventions:
- vendor() - Returns the associated Koha::Acquisition::Bookseller
- file_transport() - Returns the associated Koha::File::Transport
- shipment_fund() - Returns the Koha::Acquisition::Fund for shipment fund
- files() - Returns Koha::Edifact::Files (EDIFACT interchange files)

The Schema Result class has been updated with koha_object_class() and
koha_objects_class() helper methods to enable automatic object
inflation.

This modernization enables cleaner code in controllers and provides
a consistent API for working with EDI accounts throughout the codebase.
Comment 2 Martin Renvoize (ashimema) 2025-10-01 10:31:09 UTC
Created attachment 187162 [details] [review]
Bug 38195: Convert admin/edi_accounts.pl to use Koha::EDI::Account(s)

This patch modernizes the EDI accounts administration controller to use
the new Koha::EDI::Account(s) object classes instead of raw DBIx::Class
result access.

Changes to admin/edi_accounts.pl:
- Replaced Aqbookseller searches with Koha::Acquisition::Booksellers
- Replaced FileTransport searches with Koha::File::Transports
- Updated account save operations to use Koha::EDI::Account->new/set/store
- Updated account delete to use Koha::EDI::Accounts->find->delete
- Simplified display logic using to_api with embed parameter for
  automatic relationship inflation and JSON status decoding
- Leverages Koha::File::Transport->to_api which handles JSON decoding
  of the status field automatically

Benefits:
- Much cleaner, more maintainable code following modern Koha patterns
- Automatic relationship inflation via to_api embed parameter
- Status decoding handled automatically by Koha::File::Transport->to_api
- Single line conversion using map and to_api
- Consistent API representation across the codebase
- No manual JSON decoding or data transformation in controller
Comment 3 Martin Renvoize (ashimema) 2025-10-01 10:31:13 UTC
Created attachment 187163 [details] [review]
Bug 38195: Modernise Koha::Edifact::Transport to use Koha::Objects

This patch updates Koha::Edifact::Transport to use the new
Koha::EDI::Accounts and Koha::Edifact::Files object classes
instead of raw DBIx::Class objects.

Changes:
- Replaced $schema->resultset('VendorEdiAccount')->find() with
  Koha::EDI::Accounts->find()
- Replaced resultset('EdifactMessage')->find( { filename => $f, } );
  with Koha::Edifact::Files->search( { filename => $f });
- Simplified file_transport retrieval by using the relationship
  method from Koha::EDI::Account->file_transport()
- Removed conditional logic as the relationship method handles
  undef cases automatically

Benefits:
- Cleaner code using Koha object patterns
- Automatic relationship handling via accessor methods
- More maintainable and consistent with rest of codebase
Comment 4 Martin Renvoize (ashimema) 2025-10-01 10:31:15 UTC
Created attachment 187164 [details] [review]
Bug 38195: Convert Koha::EDI to use Koha object classes

This patch updates Koha::EDI to use modern Koha object classes instead
of raw DBIx::Class access.

Changes to vendor_edi_accounts access:
- Added use Koha::EDI::Accounts;
- Replaced three instances of $schema->resultset('VendorEdiAccount')
  with Koha::EDI::Accounts in:
  1. create_edi_order() - Finding vendor account by vendor_id
  2. process_invoice() - Finding vendor account by SAN
  3. process_quote() - Finding vendor account for auto_orders check

Changes to aqorders access:
- Added use Koha::Acquisition::Orders;
- Converted five instances from raw DBIx::Class to Koha::Objects:
  1. create_edi_order() - Changed from ->all array to resultset with
     ->count, ->next, ->reset, and ->_resultset->all for iteration
  2. process_invoice() - Changed ->find to use Koha::Acquisition::Orders
  3-4. process_quote() - Changed two ->create calls to use
     Koha::Acquisition::Order->new()->store pattern
  5. process_quote() - Changed ->find to use Koha::Acquisition::Orders

Additional improvements:
- Used idiomatic Koha::Objects patterns (->count, ->next, ->reset)
- Maintained backward compatibility with existing code expectations
- Cleaner variable naming (e.g., $vendor -> $edi_account)

Benefits:
- Consistent use of Koha object patterns throughout EDI code
- Enables use of relationship methods from Koha objects
- More maintainable and testable code
- Better integration with Koha's ORM layer
Comment 5 Martin Renvoize (ashimema) 2025-10-01 11:39:11 UTC
Created attachment 187178 [details] [review]
Bug 38195: Add Koha::EDI::Account and Koha::EDI::Accounts object classes

This patch introduces Koha::Object-based classes for managing vendor
EDI accounts, replacing direct DBIx::Class result access with proper
Koha object wrappers.

New classes:
- Koha::EDI::Account: Object class representing a single EDI account
- Koha::EDI::Accounts: Objects class for collections of EDI accounts

The Koha::EDI::Account class provides accessor methods for all related
objects following modern Koha naming conventions:
- vendor() - Returns the associated Koha::Acquisition::Bookseller
- file_transport() - Returns the associated Koha::File::Transport
- shipment_fund() - Returns the Koha::Acquisition::Fund for shipment fund
- files() - Returns Koha::Edifact::Files (EDIFACT interchange files)

The Schema Result class has been updated with koha_object_class() and
koha_objects_class() helper methods to enable automatic object
inflation.

This modernization enables cleaner code in controllers and provides
a consistent API for working with EDI accounts throughout the codebase.
Comment 6 Martin Renvoize (ashimema) 2025-10-01 11:39:13 UTC
Created attachment 187179 [details] [review]
Bug 38195: Convert admin/edi_accounts.pl to use Koha::EDI::Account(s)

This patch modernizes the EDI accounts administration controller to use
the new Koha::EDI::Account(s) object classes instead of raw DBIx::Class
result access.

Changes to admin/edi_accounts.pl:
- Replaced Aqbookseller searches with Koha::Acquisition::Booksellers
- Replaced FileTransport searches with Koha::File::Transports
- Updated account save operations to use Koha::EDI::Account->new/set/store
- Updated account delete to use Koha::EDI::Accounts->find->delete
- Simplified display logic using to_api with embed parameter for
  automatic relationship inflation and JSON status decoding
- Leverages Koha::File::Transport->to_api which handles JSON decoding
  of the status field automatically

Benefits:
- Much cleaner, more maintainable code following modern Koha patterns
- Automatic relationship inflation via to_api embed parameter
- Status decoding handled automatically by Koha::File::Transport->to_api
- Single line conversion using map and to_api
- Consistent API representation across the codebase
- No manual JSON decoding or data transformation in controller
Comment 7 Martin Renvoize (ashimema) 2025-10-01 11:39:15 UTC
Created attachment 187180 [details] [review]
Bug 38195: Modernise Koha::Edifact::Transport to use Koha::Objects

This patch updates Koha::Edifact::Transport to use the new
Koha::EDI::Accounts and Koha::Edifact::Files object classes
instead of raw DBIx::Class objects.

Changes:
- Replaced $schema->resultset('VendorEdiAccount')->find() with
  Koha::EDI::Accounts->find()
- Replaced resultset('EdifactMessage')->find( { filename => $f, } );
  with Koha::Edifact::Files->search( { filename => $f });
- Simplified file_transport retrieval by using the relationship
  method from Koha::EDI::Account->file_transport()
- Removed conditional logic as the relationship method handles
  undef cases automatically

Benefits:
- Cleaner code using Koha object patterns
- Automatic relationship handling via accessor methods
- More maintainable and consistent with rest of codebase
Comment 8 Martin Renvoize (ashimema) 2025-10-01 11:39:17 UTC
Created attachment 187181 [details] [review]
Bug 38195: Convert Koha::EDI to use Koha object classes

This patch updates Koha::EDI to use modern Koha object classes instead
of raw DBIx::Class access.

Changes to vendor_edi_accounts access:
- Added use Koha::EDI::Accounts;
- Replaced three instances of $schema->resultset('VendorEdiAccount')
  with Koha::EDI::Accounts in:
  1. create_edi_order() - Finding vendor account by vendor_id
  2. process_invoice() - Finding vendor account by SAN
  3. process_quote() - Finding vendor account for auto_orders check

Changes to aqorders access:
- Added use Koha::Acquisition::Orders;
- Converted five instances from raw DBIx::Class to Koha::Objects:
  1. create_edi_order() - Changed from ->all array to resultset with
     ->count, ->next, ->reset, and ->_resultset->all for iteration
  2. process_invoice() - Changed ->find to use Koha::Acquisition::Orders
  3-4. process_quote() - Changed two ->create calls to use
     Koha::Acquisition::Order->new()->store pattern
  5. process_quote() - Changed ->find to use Koha::Acquisition::Orders

Additional improvements:
- Used idiomatic Koha::Objects patterns (->count, ->next, ->reset)
- Maintained backward compatibility with existing code expectations
- Cleaner variable naming (e.g., $vendor -> $edi_account)

Benefits:
- Consistent use of Koha object patterns throughout EDI code
- Enables use of relationship methods from Koha objects
- More maintainable and testable code
- Better integration with Koha's ORM layer