Bug 29139: Add exceptions to relation accessors

We already had exceptions on the many-to-many links, but we didn't have
them for the middle table. The underlying dbic relations make it clear
which id's are being used for linking.  A 'credit' has 'credit_offsets',
a 'debit' has 'debit_offsets'.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2021-09-30 09:28:29 +01:00 committed by Kyle Hall
parent 229ea7a312
commit e124d1283c

View file

@ -132,8 +132,15 @@ Return the credit_offsets linked to this account line if some exist
=cut
sub credit_offsets {
my ( $self ) = @_;
my $rs = $self->_result->account_offsets_credits;
my ( $self, $cond, $attr ) = @_;
unless ( $self->is_credit ) {
Koha::Exceptions::Account::IsNotCredit->throw(
error => 'Account line ' . $self->id . ' is not a credit'
);
}
my $rs = $self->_result->search_related( 'account_offsets_credits', $cond, $attr);
return unless $rs;
return Koha::Account::Offsets->_new_from_dbic($rs);
}
@ -145,13 +152,19 @@ Return the debit_offsets linked to this account line if some exist
=cut
sub debit_offsets {
my ( $self ) = @_;
my $rs = $self->_result->account_offsets_debits;
my ( $self, $cond, $attr ) = @_;
unless ( $self->is_debit ) {
Koha::Exceptions::Account::IsNotDebit->throw(
error => 'Account line ' . $self->id . ' is not a debit'
);
}
my $rs = $self->_result->search_related( 'account_offsets_debits', $cond, $attr);
return unless $rs;
return Koha::Account::Offsets->_new_from_dbic($rs);
}
=head3 credits
my $credits = $accountline->credits;