Bugzilla – Attachment 193802 Details for
Bug 39658
Allow definition of non-hierarchical linked patron accounts
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39658: Add linked account methods to Koha::Patron
Bug-39658-Add-linked-account-methods-to-KohaPatron.patch (text/plain), 4.01 KB, created by
Kellie Stephens
on 2026-02-24 21:13:32 UTC
(
hide
)
Description:
Bug 39658: Add linked account methods to Koha::Patron
Filename:
MIME Type:
Creator:
Kellie Stephens
Created:
2026-02-24 21:13:32 UTC
Size:
4.01 KB
patch
obsolete
>From 6138f68ab17036e707aa1f88f3876deef94f119f Mon Sep 17 00:00:00 2001 >From: Jacob O'Mara <Jacob.omara@openfifth.co.uk> >Date: Wed, 21 Jan 2026 15:36:16 +0000 >Subject: [PATCH] Bug 39658: Add linked account methods to Koha::Patron > >Methods: account_link, linked_accounts, all_linked_borrowernumbers, >linked_accounts_debt. Also adds charge limit checking. > >Signed-off-by: Trevor Diamond <trevor.diamond@mainlib.org> >Signed-off-by: Kellie Stephens <kellie.stephens@bywatersolutions.com> >--- > Koha/Patron.pm | 87 +++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 86 insertions(+), 1 deletion(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index c0ef6e292c..cbfd466c6e 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -62,6 +62,7 @@ use Koha::Patron::Images; > use Koha::Patron::Messages; > use Koha::Patron::Modifications; > use Koha::Patron::MessagePreferences; >+use Koha::Patron::AccountLinks; > use Koha::Patron::Relationships; > use Koha::Patron::Restrictions; > use Koha::Patrons; >@@ -639,6 +640,70 @@ sub relationships_debt { > return $non_issues_charges; > } > >+=head3 account_link >+ >+Returns the Koha::Patron::AccountLink for this patron, or undef if not linked >+ >+=cut >+ >+sub account_link { >+ my ($self) = @_; >+ return Koha::Patron::AccountLinks->find( { borrowernumber => $self->borrowernumber } ); >+} >+ >+=head3 linked_accounts >+ >+Returns Koha::Patrons of all linked accounts (excluding self) >+ >+=cut >+ >+sub linked_accounts { >+ my ($self) = @_; >+ >+ my $link = $self->account_link; >+ return Koha::Patrons->new->empty unless $link; >+ >+ return $link->linked_patrons; >+} >+ >+=head3 all_linked_borrowernumbers >+ >+Returns arrayref of all borrowernumbers in the link group (including self) >+ >+=cut >+ >+sub all_linked_borrowernumbers { >+ my ($self) = @_; >+ >+ my $link = $self->account_link; >+ return [ $self->borrowernumber ] unless $link; >+ >+ return $link->all_linked_borrowernumbers; >+} >+ >+=head3 linked_accounts_debt >+ >+Returns total non_issues_charges across all linked accounts >+ >+=cut >+ >+sub linked_accounts_debt { >+ my ($self) = @_; >+ >+ my $total = 0; >+ my $link = $self->account_link; >+ return $total unless $link; >+ >+ my $linked = Koha::Patron::AccountLinks->search( { link_group_id => $link->link_group_id } ); >+ >+ while ( my $l = $linked->next ) { >+ my $patron = Koha::Patrons->find( $l->borrowernumber ); >+ $total += $patron->account->non_issues_charges if $patron; >+ } >+ >+ return $total; >+} >+ > =head3 housebound_profile > > Returns the HouseboundProfile associated with this patron. >@@ -3509,7 +3574,8 @@ sub can_checkout { > $status->{can_checkout} = 0 > if $patron_charge_limits->{noissuescharge}->{overlimit} > || $patron_charge_limits->{NoIssuesChargeGuarantees}->{overlimit} >- || $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit}; >+ || $patron_charge_limits->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit} >+ || $patron_charge_limits->{NoIssuesChargeLinkedAccounts}->{overlimit}; > > return $status; > } >@@ -3576,6 +3642,25 @@ sub is_patron_inside_charge_limits { > if $no_issues_charge_guarantors_with_guarantees > && $guarantors_non_issues_charges > $no_issues_charge_guarantors_with_guarantees; > >+ my $no_issues_charge_linked = C4::Context->preference('NoIssuesChargeLinkedAccounts'); >+ my $linked_non_issues_charges = 0; >+ >+ if ( C4::Context->preference('EnablePatronAccountLinking') >+ && defined $no_issues_charge_linked >+ && looks_like_number($no_issues_charge_linked) ) >+ { >+ $linked_non_issues_charges = $patron->linked_accounts_debt(); >+ } >+ >+ $patron_charge_limits->{NoIssuesChargeLinkedAccounts} = { >+ limit => $no_issues_charge_linked, >+ charge => $linked_non_issues_charges, >+ overlimit => 0 >+ }; >+ $patron_charge_limits->{NoIssuesChargeLinkedAccounts}->{overlimit} = 1 >+ if $no_issues_charge_linked >+ && $linked_non_issues_charges > $no_issues_charge_linked; >+ > return $patron_charge_limits; > } > >-- >2.39.5
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 39658
:
193344
|
193345
|
193346
|
193347
|
193348
|
193349
|
193350
|
193351
|
193352
|
193353
|
193354
|
193355
|
193356
|
193357
|
193358
|
193359
|
193462
|
193463
|
193464
|
193465
|
193466
|
193467
|
193468
|
193469
|
193470
|
193471
|
193472
|
193473
|
193474
|
193475
|
193476
|
193477
|
193478
|
193479
|
193781
|
193782
|
193783
|
193784
|
193785
|
193786
|
193787
|
193788
|
193789
|
193790
|
193791
|
193792
|
193793
|
193794
|
193795
|
193796
|
193797
|
193798
|
193800
|
193801
| 193802 |
193803
|
193804
|
193805
|
193806
|
193807
|
193808
|
193809
|
193810
|
193811
|
193812
|
193813
|
193814
|
193815
|
193816
|
193817