From 8b6d139b635c6272c0adde71e3f12e9db0710b5b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 1 Oct 2025 07:08:16 +0100 Subject: [PATCH] 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. --- Koha/EDI/Account.pm | 111 +++++++++++++++++++++++++ Koha/EDI/Accounts.pm | 60 +++++++++++++ Koha/Schema/Result/VendorEdiAccount.pm | 20 +++++ 3 files changed, 191 insertions(+) create mode 100644 Koha/EDI/Account.pm create mode 100644 Koha/EDI/Accounts.pm diff --git a/Koha/EDI/Account.pm b/Koha/EDI/Account.pm new file mode 100644 index 00000000000..302a2157e8d --- /dev/null +++ b/Koha/EDI/Account.pm @@ -0,0 +1,111 @@ +package Koha::EDI::Account; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Fund; +use Koha::Edifact::Files; +use Koha::File::Transport; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::EDI::Account - Koha EDI Account Object class + +=head1 API + +=head2 Class methods + +=head3 vendor + + my $vendor = $edi_account->vendor; + +Returns the Koha::Acquisition::Bookseller object for this EDI account + +=cut + +sub vendor { + my ($self) = @_; + my $vendor_rs = $self->_result->vendor; + return unless $vendor_rs; + return Koha::Acquisition::Bookseller->_new_from_dbic($vendor_rs); +} + +=head3 file_transport + + my $transport = $edi_account->file_transport; + +Returns the Koha::File::Transport object for this EDI account + +=cut + +sub file_transport { + my ($self) = @_; + my $transport_rs = $self->_result->file_transport; + return unless $transport_rs; + return Koha::File::Transport->_new_from_dbic($transport_rs); +} + +=head3 shipment_fund + + my $fund = $edi_account->shipment_fund; + +Returns the Koha::Acquisition::Fund object for the shipment fund + +=cut + +sub shipment_fund { + my ($self) = @_; + my $fund_rs = $self->_result->shipment_budget; + return unless $fund_rs; + return Koha::Acquisition::Fund->_new_from_dbic($fund_rs); +} + +=head3 files + + my $files = $edi_account->files; + +Returns a Koha::Edifact::Files object containing all EDIFACT interchange files +for this account + +=cut + +sub files { + my ($self) = @_; + my $files_rs = $self->_result->edifact_messages; + return Koha::Edifact::Files->_new_from_dbic($files_rs); +} + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'VendorEdiAccount'; +} + +=head1 AUTHOR + +Koha Development Team + +=cut + +1; diff --git a/Koha/EDI/Accounts.pm b/Koha/EDI/Accounts.pm new file mode 100644 index 00000000000..a3cb0bfc661 --- /dev/null +++ b/Koha/EDI/Accounts.pm @@ -0,0 +1,60 @@ +package Koha::EDI::Accounts; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Koha::EDI::Account; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::EDI::Accounts - Koha EDI Account Objects class + +=head1 API + +=head2 Internal methods + +=head3 _type + +Returns name of corresponding DBIC resultset + +=cut + +sub _type { + return 'VendorEdiAccount'; +} + +=head3 object_class + +Returns name of corresponding koha object class + +=cut + +sub object_class { + return 'Koha::EDI::Account'; +} + +=head1 AUTHOR + +Martin Renvoize + +Koha Development Team + +=cut + +1; diff --git a/Koha/Schema/Result/VendorEdiAccount.pm b/Koha/Schema/Result/VendorEdiAccount.pm index 0b260e04884..c28c92570da 100644 --- a/Koha/Schema/Result/VendorEdiAccount.pm +++ b/Koha/Schema/Result/VendorEdiAccount.pm @@ -251,4 +251,24 @@ __PACKAGE__->add_columns( '+responses_enabled' => { is_boolean => 1 }, ); +=head2 koha_object_class + +Helper for Koha::Object-based class name resolution. + +=cut + +sub koha_object_class { + return 'Koha::EDI::Account'; +} + +=head2 koha_objects_class + +Helper for Koha::Objects-based class name resolution. + +=cut + +sub koha_objects_class { + return 'Koha::EDI::Accounts'; +} + 1; -- 2.51.0