Bugzilla – Attachment 189612 Details for
Bug 40817
Holds charges should be accessible from Holds
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40817: Add Koha object methods for hold-account line linking
Bug-40817-Add-Koha-object-methods-for-hold-account.patch (text/plain), 7.00 KB, created by
Martin Renvoize (ashimema)
on 2025-11-14 14:36:29 UTC
(
hide
)
Description:
Bug 40817: Add Koha object methods for hold-account line linking
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-11-14 14:36:29 UTC
Size:
7.00 KB
patch
obsolete
>From ae9de83bad9f7d0c190d1ddc66780161ff076ed4 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Tue, 16 Sep 2025 13:47:45 +0100 >Subject: [PATCH] Bug 40817: Add Koha object methods for hold-account line > linking > >This patch implements the core object methods to support direct linking >between holds and their associated account lines: > >Koha::Account.pm: >- Enhance add_debit() to accept hold_id parameter for linking fees to holds >- Add automatic detection of current vs old holds for proper field assignment >- Add graceful handling of non-existent holds > >Koha::Account::Line.pm: >- Add hold() method to retrieve associated hold (current or old) >- Support bidirectional navigation between account lines and holds > >Koha::Hold.pm: >- Add debits() method to get all charges associated with the hold >- Update charge_hold_fee() to link created fees to the hold >- Enhance _move_to_old() to migrate account line relationships >- Add hold_id parameter to fee creation calls > >Koha::Old::Hold.pm: >- Add debits() method for accessing charges linked to old holds > >Signed-off-by: Jackie Usher <jackie.usher@westsussex.gov.uk> >--- > Koha/Account.pm | 28 ++++++++++++++++++++++++++++ > Koha/Account/Line.pm | 23 +++++++++++++++++++++++ > Koha/Hold.pm | 41 +++++++++++++++++++++++++++++++++++++++-- > Koha/Old/Hold.pm | 24 ++++++++++++++++++++++++ > 4 files changed, 114 insertions(+), 2 deletions(-) > >diff --git a/Koha/Account.pm b/Koha/Account.pm >index d78247409de..3bff0a75421 100644 >--- a/Koha/Account.pm >+++ b/Koha/Account.pm >@@ -492,6 +492,7 @@ sub add_debit { > my $transaction_type = $params->{transaction_type}; > my $item_id = $params->{item_id}; > my $issue_id = $params->{issue_id}; >+ my $hold_id = $params->{hold_id}; > > my $old_issue_id; > if ($issue_id) { >@@ -503,6 +504,23 @@ sub add_debit { > } > } > >+ my $old_hold_id; >+ if ($hold_id) { >+ my $hold = Koha::Holds->find($hold_id); >+ unless ($hold) { >+ my $old_hold = Koha::Old::Holds->find($hold_id); >+ if ($old_hold) { >+ $hold_id = undef; >+ $old_hold_id = $old_hold->id; >+ } else { >+ >+ # Neither current nor old hold exists, keep hold_id as is for now >+ # The caller will need to handle this case >+ $hold_id = undef; >+ } >+ } >+ } >+ > my $line; > my $schema = Koha::Database->new->schema; > try { >@@ -533,6 +551,16 @@ sub add_debit { > ? ( old_issue_id => $old_issue_id ) > : () > ), >+ ( >+ $hold_id >+ ? ( reserve_id => $hold_id ) >+ : () >+ ), >+ ( >+ $old_hold_id >+ ? ( old_reserve_id => $old_hold_id ) >+ : () >+ ), > branchcode => $library_id, > register_id => $cash_register, > ( >diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm >index f44761fcf48..73eeea89bc7 100644 >--- a/Koha/Account/Line.pm >+++ b/Koha/Account/Line.pm >@@ -104,6 +104,29 @@ sub checkout { > return $result; > } > >+=head3 hold >+ >+ my $hold = $account_line->hold; >+ >+Get the hold associated with this account line (if any) >+ >+=cut >+ >+sub hold { >+ my ($self) = @_; >+ >+ my $result; >+ if ( $self->reserve_id ) { >+ my $hold_rs = $self->_result->reserve; >+ $result = Koha::Hold->_new_from_dbic($hold_rs) if $hold_rs; >+ } elsif ( $self->old_reserve_id ) { >+ my $old_hold_rs = $self->_result->old_reserve; >+ $result = Koha::Old::Hold->_new_from_dbic($old_hold_rs) if $old_hold_rs; >+ } >+ >+ return $result; >+} >+ > =head3 library > > Returns a Koha::Library object representing where the accountline was recorded >diff --git a/Koha/Hold.pm b/Koha/Hold.pm >index 223a6be1790..c2014afc39f 100644 >--- a/Koha/Hold.pm >+++ b/Koha/Hold.pm >@@ -938,7 +938,8 @@ sub cancel { > interface => C4::Context->interface, > library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, > type => 'RESERVE_EXPIRED', >- item_id => $self->itemnumber >+ item_id => $self->itemnumber, >+ hold_id => $self->id, > } > ) if $charge; > } >@@ -1309,6 +1310,7 @@ sub charge_hold_fee { > description => $self->biblio->title, > type => 'RESERVE', > item_id => $self->itemnumber, >+ hold_id => $self->id, > user_id => C4::Context->userenv ? C4::Context->userenv->{number} : undef, > library_id => C4::Context->userenv ? C4::Context->userenv->{branch} : undef, > interface => C4::Context->interface, >@@ -1446,7 +1448,19 @@ sub _move_to_old { > my ($self) = @_; > my $hold_infos = $self->unblessed; > require Koha::Old::Hold; >- return Koha::Old::Hold->new($hold_infos)->store; >+ >+ # Create the old hold record >+ my $old_hold = Koha::Old::Hold->new($hold_infos)->store; >+ >+ # Update any linked accountlines to point to old_reserve_id instead of reserve_id >+ $self->_result->search_related('accountlines')->update( >+ { >+ old_reserve_id => $self->id, >+ reserve_id => undef, >+ } >+ ); >+ >+ return $old_hold; > } > > =head3 to_api_mapping >@@ -1538,6 +1552,29 @@ sub strings_map { > return $strings; > } > >+=head3 debits >+ >+ my $debits = $hold->debits; >+ >+Get all debit account lines (charges) associated with this hold >+ >+=cut >+ >+sub debits { >+ my ($self) = @_; >+ >+ my $accountlines_rs = $self->_result->search_related( >+ 'accountlines', >+ { >+ credit_type_code => undef, # Only debits (no credits) >+ }, >+ { >+ order_by => { -desc => 'timestamp' }, >+ } >+ ); >+ return Koha::Account::Debits->_new_from_dbic($accountlines_rs); >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/Koha/Old/Hold.pm b/Koha/Old/Hold.pm >index 95cce805adc..fcb2348655e 100644 >--- a/Koha/Old/Hold.pm >+++ b/Koha/Old/Hold.pm >@@ -105,6 +105,30 @@ sub anonymize { > return $self->update( { borrowernumber => $anonymous_id } ); > } > >+=head3 debits >+ >+ my $debits = $old_hold->debits; >+ >+Get all debit account lines (charges) associated with this old hold >+ >+=cut >+ >+sub debits { >+ my ($self) = @_; >+ >+ my $accountlines_rs = $self->_result->search_related( >+ 'accountlines', >+ { >+ credit_type_code => undef, # Only debits (no credits) >+ }, >+ { >+ # Optimize with proper ordering and potential prefetching >+ order_by => { -desc => 'timestamp' }, >+ } >+ ); >+ return Koha::Account::Debits->_new_from_dbic($accountlines_rs); >+} >+ > =head2 Internal methods > > =head3 _type >-- >2.51.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40817
:
186476
|
186477
|
186478
|
186479
|
186480
|
186481
|
189610
|
189611
| 189612 |
189613
|
189614
|
189615